sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1636564 - /sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/console/WebConsolePlugin.java
Date Tue, 04 Nov 2014 12:44:40 GMT
Author: cziegeler
Date: Tue Nov  4 12:44:40 2014
New Revision: 1636564

URL: http://svn.apache.org/r1636564
Log:
SLING-4129 : Remove obsolete functionality from web console

Modified:
    sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/console/WebConsolePlugin.java

Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/console/WebConsolePlugin.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/console/WebConsolePlugin.java?rev=1636564&r1=1636563&r2=1636564&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/console/WebConsolePlugin.java
(original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/console/WebConsolePlugin.java
Tue Nov  4 12:44:40 2014
@@ -20,6 +20,7 @@ package org.apache.sling.event.impl.jobs
 
 import java.io.IOException;
 import java.io.PrintWriter;
+import java.net.URLEncoder;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
 import java.util.Collection;
@@ -37,6 +38,7 @@ import org.apache.felix.scr.annotations.
 import org.apache.felix.scr.annotations.Property;
 import org.apache.felix.scr.annotations.Reference;
 import org.apache.felix.scr.annotations.Service;
+import org.apache.sling.api.request.ResponseUtil;
 import org.apache.sling.discovery.InstanceDescription;
 import org.apache.sling.event.impl.jobs.JobConsumerManager;
 import org.apache.sling.event.impl.jobs.config.InternalQueueConfiguration;
@@ -84,14 +86,6 @@ public class WebConsolePlugin extends Ht
     @Reference
     private JobConsumerManager jobConsumerManager;
 
-    /** Escape the output for HTML. */
-    private String escape(final String text) {
-        if ( text == null ) {
-            return "";
-        }
-        return text.replace("&", "&amp;").replace("<", "&lt;").replace(">",
"&gt;");
-    }
-
     private static final String PAR_QUEUE = "queue";
 
     private Queue getQueue(final HttpServletRequest req) {
@@ -133,13 +127,6 @@ public class WebConsolePlugin extends Ht
             } else {
                 msg = this.getQueueErrorMessage(req, "resume");
             }
-        } else if ( "clear".equals(cmd) ) {
-            final Queue q = this.getQueue(req);
-            if ( q != null ) {
-                q.clear();
-            } else {
-                msg = this.getQueueErrorMessage(req, "clear");
-            }
         } else if ( "reset".equals(cmd) ) {
             if ( req.getParameter(PAR_QUEUE) == null || req.getParameter(PAR_QUEUE).length()
== 0 ) {
                 this.jobManager.getStatistics().reset();
@@ -168,13 +155,13 @@ public class WebConsolePlugin extends Ht
         if ( msg == null ) {
             redirectTo = path;
         } else {
-            redirectTo = path + "?message=" + msg;
+            redirectTo = path + "?message=" + URLEncoder.encode(msg, "UTF-8");
         }
-        resp.sendRedirect(redirectTo);
+        resp.sendRedirect(resp.encodeRedirectURL(redirectTo));
     }
 
     private void startTestJob() {
-        logger.info("Adding test job.");
+        logger.info("Adding test job: {}", SLING_WEBCONSOLE_TEST_JOB_TOPIC);
         this.jobManager.addJob(SLING_WEBCONSOLE_TEST_JOB_TOPIC, null);
     }
 
@@ -196,7 +183,7 @@ public class WebConsolePlugin extends Ht
                    "} </script>");
 
         pw.printf("<p class='statline ui-state-highlight'>Apache Sling Job Handling%s%n</p>",
-                msg != null ? " : " + msg : "");
+                msg != null ? " : " + ResponseUtil.escapeXml(msg) : "");
         pw.println("<div class='ui-widget-header ui-corner-top buttonGroup'>");
         pw.println("<span style='float: left; margin-left: 1em'>Apache Sling Job Handling:
Overall Statistics</span>");
         this.printForm(pw, null, "Reset Stats", "reset");
@@ -216,7 +203,7 @@ public class WebConsolePlugin extends Ht
                 } else {
                     sb.append("<br/>");
                 }
-                sb.append(t);
+                sb.append(ResponseUtil.escapeXml(t));
             }
             topics = sb.toString();
         }
@@ -253,10 +240,10 @@ public class WebConsolePlugin extends Ht
                     if ( id.isLocal() ) {
                         sb.append("<b>local</b>");
                     } else {
-                        sb.append(id.getSlingId());
+                        sb.append(ResponseUtil.escapeXml(id.getSlingId()));
                     }
                 }
-                pw.printf("<tr><td>%s</td><td>%s</td></tr>",
entry.getKey(), sb.toString());
+                pw.printf("<tr><td>%s</td><td>%s</td></tr>",
ResponseUtil.escapeXml(entry.getKey()), sb.toString());
             }
         }
         pw.println("</tbody></table>");
@@ -272,7 +259,7 @@ public class WebConsolePlugin extends Ht
             int index = 1;
             for(final ScheduledJobInfo info : infos) {
                 pw.printf("<tr><td><b>%s</b></td><td>%s</td><td>",
-                        String.valueOf(index), info.getJobTopic());
+                        String.valueOf(index), ResponseUtil.escapeXml(info.getJobTopic()));
                 boolean first = true;
                 for(final ScheduleInfo si : info.getSchedules() ) {
                     if ( !first ) {
@@ -290,7 +277,7 @@ public class WebConsolePlugin extends Ht
                                  break;
                     case HOURLY : pw.printf("HOURLY %s", si.getMinuteOfHour());
                                  break;
-                    case CRON : pw.printf("CRON %s", si.getExpression());
+                    case CRON : pw.printf("CRON %s", ResponseUtil.escapeXml(si.getExpression()));
                                   break;
                     default : pw.printf("AT %s", si.getAt());
                     }
@@ -305,9 +292,9 @@ public class WebConsolePlugin extends Ht
         boolean isEmpty = true;
         for(final Queue q : this.jobManager.getQueues()) {
             isEmpty = false;
-            String queueName = q.getName();
+            final String queueName = q.getName();
             pw.println("<div class='ui-widget-header ui-corner-top buttonGroup'>");
-            pw.printf("<span style='float: left; margin-left: 1em'>Active JobQueue:
%s %s</span>", escape(q.getName()),
+            pw.printf("<span style='float: left; margin-left: 1em'>Active JobQueue:
%s %s</span>", ResponseUtil.escapeXml(queueName),
                     q.isSuspended() ? "(SUSPENDED)" : "");
             this.printForm(pw, queueName, "Reset Stats", "reset");
             if ( q.isSuspended() ) {
@@ -316,7 +303,6 @@ public class WebConsolePlugin extends Ht
                 this.printForm(pw, queueName, "Suspend", "suspend");
             }
             this.printForm(pw, queueName, "Test", "test");
-            this.printForm(pw, queueName, "Clear Queue", "clear");
             this.printForm(pw, queueName, "Drop All", "dropall");
             pw.println("</div>");
             pw.println("<table class='nicetable'><tbody>");
@@ -336,7 +322,7 @@ public class WebConsolePlugin extends Ht
             pw.printf("<tr><td>Processed Jobs</td><td>%s</td><td
colspan='2'>&nbsp</td></tr>", s.getNumberOfProcessedJobs());
             pw.printf("<tr><td>Average Processing Time</td><td>%s</td><td
colspan='2'>&nbsp</td></tr>", formatTime(s.getAverageProcessingTime()));
             pw.printf("<tr><td>Average Waiting Time</td><td>%s</td><td
colspan='2'>&nbsp</td></tr>", formatTime(s.getAverageWaitingTime()));
-            pw.printf("<tr><td>Status Info</td><td colspan='3'>%s</td></tr>",
escape(q.getStateInfo()));
+            pw.printf("<tr><td>Status Info</td><td colspan='3'>%s</td></tr>",
ResponseUtil.escapeXml(q.getStateInfo()));
             pw.println("</tbody></table>");
             pw.println("<br/>");
         }
@@ -347,7 +333,7 @@ public class WebConsolePlugin extends Ht
 
         for(final TopicStatistics ts : this.jobManager.getTopicStatistics()) {
             pw.println("<table class='nicetable'><tbody>");
-            pw.printf("<tr><th colspan='2'>Topic Statistics: %s</th></tr>",
escape(ts.getTopic()));
+            pw.printf("<tr><th colspan='2'>Topic Statistics: %s</th></tr>",
ResponseUtil.escapeXml(ts.getTopic()));
 
             pw.printf("<tr><td>Last Activated</td><td>%s</td></tr>",
formatDate(ts.getLastActivatedJobTime()));
             pw.printf("<tr><td>Last Finished</td><td>%s</td></tr>",
formatDate(ts.getLastFinishedJobTime()));
@@ -372,7 +358,7 @@ public class WebConsolePlugin extends Ht
     private void printQueueConfiguration(final HttpServletRequest req, final PrintWriter
pw, final InternalQueueConfiguration c) {
         pw.println("<div class='ui-widget-header ui-corner-top buttonGroup'>");
         pw.printf("<span style='float: left; margin-left: 1em'>Job Queue Configuration:
%s</span>%n",
-                escape(c.getName()));
+                ResponseUtil.escapeXml(c.getName()));
         pw.printf("<button id='edit' class='ui-state-default ui-corner-all' onclick='javascript:window.location=\"%s%s/configMgr/%s\";'>Edit</button>",
                 req.getContextPath(), req.getServletPath(), c.getPid());
         this.printForm(pw, c.getName(), "Test", "test");
@@ -409,7 +395,7 @@ public class WebConsolePlugin extends Ht
             first = false;
             sb.append(s);
         }
-        return escape(sb.toString());
+        return ResponseUtil.escapeXml(sb.toString());
     }
 
     private String formatType(final QueueConfiguration.Type type) {
@@ -458,12 +444,12 @@ public class WebConsolePlugin extends Ht
             final String buttonLabel,
             final String cmd) {
         pw.printf("<button class='ui-state-default ui-corner-all' onclick='javascript:eventingsubmit(\"%s\",
\"%s\");'>" +
-                "%s</button>", cmd, (qeueName != null ? qeueName : ""), buttonLabel);
+                "%s</button>", ResponseUtil.escapeXml(cmd), (qeueName != null ? ResponseUtil.escapeXml(qeueName)
: ""), ResponseUtil.escapeXml(buttonLabel));
     }
 
     @Override
     public JobResult process(final Job job) {
-        logger.info("Received test event.");
+        logger.info("Received test job {}", job.getTopic());
         return JobResult.OK;
     }
 }



Mime
View raw message