incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r906456 - /sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/request/RequestHistoryConsolePlugin.java
Date Thu, 04 Feb 2010 11:32:44 GMT
Author: cziegeler
Date: Thu Feb  4 11:32:43 2010
New Revision: 906456

URL: http://svn.apache.org/viewvc?rev=906456&view=rev
Log:
Just code formatting, no functional changes except StringBuffer -> StringBuilder

Modified:
    sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/request/RequestHistoryConsolePlugin.java

Modified: sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/request/RequestHistoryConsolePlugin.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/request/RequestHistoryConsolePlugin.java?rev=906456&r1=906455&r2=906456&view=diff
==============================================================================
--- sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/request/RequestHistoryConsolePlugin.java
(original)
+++ sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/request/RequestHistoryConsolePlugin.java
Thu Feb  4 11:32:43 2010
@@ -45,107 +45,108 @@
 @SuppressWarnings("serial")
 public class RequestHistoryConsolePlugin extends AbstractWebConsolePlugin {
 
-  public static final String LABEL = "requests";
-  public static final String INDEX = "index";
-  public static final String CLEAR = "clear";
-  private static RequestHistoryConsolePlugin instance;
-  private ServiceRegistration serviceRegistration;
-
-  public static final int STORED_REQUESTS_COUNT = 20;
-  private final SlingHttpServletRequest[] requests = new SlingHttpServletRequest[STORED_REQUESTS_COUNT];
-  
-  /** Need to store methods separately, apparently requests clear this data when done processing
*/
-  private final String [] methods = new String[STORED_REQUESTS_COUNT];
-  
-  private int lastRequestIndex = -1;
-
-  private RequestHistoryConsolePlugin() {
-  }
-
-  public static void recordRequest(SlingHttpServletRequest r) {
-    if (instance == null) {
-      return;
-    }
-    instance.addRequest(r);
-  }
-
-  private synchronized void addRequest(SlingHttpServletRequest r) {
-    int index = lastRequestIndex + 1;
-    if (index >= requests.length) {
-      index = 0;
-    }
-    requests[index] = r;
-    methods[index] = r.getMethod();
-    lastRequestIndex = index;
-  }
-  
-  private synchronized void clear() {
-    for(int i=0; i < requests.length; i++) {
-      requests[i] = null;
-    }
-    lastRequestIndex = -1;
-  }
-
-  public static void initPlugin(BundleContext context) {
-    if (instance == null) {
-      RequestHistoryConsolePlugin tmp = new RequestHistoryConsolePlugin();
-      tmp.activate(context);
-      instance = tmp;
-    }
-  }
-
-  public static void destroyPlugin() {
-    if (instance != null) {
-      try {
-        instance.deactivate();
-      } finally {
-        instance = null;
-      }
-    }
-  }
-
-  public void activate(BundleContext context) {
-    super.activate(context);
-
-    Dictionary<String, Object> props = new Hashtable<String, Object>();
-    props
-        .put(Constants.SERVICE_DESCRIPTION,
+    public static final String LABEL = "requests";
+    public static final String INDEX = "index";
+    public static final String CLEAR = "clear";
+
+    private static RequestHistoryConsolePlugin instance;
+
+    private ServiceRegistration serviceRegistration;
+
+    public static final int STORED_REQUESTS_COUNT = 20;
+
+    private final SlingHttpServletRequest[] requests = new SlingHttpServletRequest[STORED_REQUESTS_COUNT];
+
+    /** Need to store methods separately, apparently requests clear this data when done processing
*/
+    private final String [] methods = new String[STORED_REQUESTS_COUNT];
+
+    private int lastRequestIndex = -1;
+
+    private RequestHistoryConsolePlugin() {
+    }
+
+    public static void recordRequest(SlingHttpServletRequest r) {
+        if (instance != null) {
+            instance.addRequest(r);
+        }
+    }
+
+    private synchronized void addRequest(SlingHttpServletRequest r) {
+        int index = lastRequestIndex + 1;
+        if (index >= requests.length) {
+            index = 0;
+        }
+        requests[index] = r;
+        methods[index] = r.getMethod();
+        lastRequestIndex = index;
+    }
+
+    private synchronized void clear() {
+        for(int i=0; i < requests.length; i++) {
+            requests[i] = null;
+        }
+        lastRequestIndex = -1;
+    }
+
+    public static void initPlugin(BundleContext context) {
+        if (instance == null) {
+            RequestHistoryConsolePlugin tmp = new RequestHistoryConsolePlugin();
+            tmp.activate(context);
+            instance = tmp;
+        }
+    }
+
+    public static void destroyPlugin() {
+        if (instance != null) {
+            try {
+                instance.deactivate();
+            } finally {
+                instance = null;
+            }
+        }
+    }
+
+    public void activate(BundleContext context) {
+        super.activate(context);
+
+        Dictionary<String, Object> props = new Hashtable<String, Object>();
+        props.put(Constants.SERVICE_DESCRIPTION,
             "Web Console Plugin to display information about recent Sling requests");
-    props.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation");
-    props.put(Constants.SERVICE_PID, getClass().getName());
-    props.put(WebConsoleConstants.PLUGIN_LABEL, LABEL);
-
-    serviceRegistration = context.registerService(
-        WebConsoleConstants.SERVICE_NAME, this, props);
-  }
-
-  public void deactivate() {
-    if (serviceRegistration != null) {
-      serviceRegistration.unregister();
-      serviceRegistration = null;
-    }
-    super.deactivate();
-  }
-
-  @Override
-  public String getLabel() {
-    return LABEL;
-  }
-
-  @Override
-  public String getTitle() {
-    return "Recent requests";
-  }
-
-  private int getArrayIndex(int displayIndex) {
-      int result = lastRequestIndex - displayIndex;
-      if (result < 0) {
-        result += requests.length;
-      }
-      return result;
-  }
-  
-  private String getLinksTable(int currentRequestIndex) {
+        props.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation");
+        props.put(Constants.SERVICE_PID, getClass().getName());
+        props.put(WebConsoleConstants.PLUGIN_LABEL, LABEL);
+
+        serviceRegistration = context.registerService(
+            WebConsoleConstants.SERVICE_NAME, this, props);
+    }
+
+    public void deactivate() {
+        if (serviceRegistration != null) {
+            serviceRegistration.unregister();
+            serviceRegistration = null;
+        }
+        super.deactivate();
+    }
+
+    @Override
+    public String getLabel() {
+        return LABEL;
+    }
+
+    @Override
+    public String getTitle() {
+        return "Recent requests";
+    }
+
+    private int getArrayIndex(int displayIndex) {
+        int result = lastRequestIndex - displayIndex;
+        if (result < 0) {
+            result += requests.length;
+        }
+        return result;
+    }
+
+    private String getLinksTable(int currentRequestIndex) {
         final List<String> links = new ArrayList<String>();
         for (int i = 0; i < requests.length; i++) {
             final StringBuilder sb = new StringBuilder();
@@ -162,14 +163,14 @@
                 links.add(sb.toString());
             }
         }
-        
+
         final int nCols = 5;
         while((links.size() % nCols) != 0) {
             links.add("&nbsp;");
         }
 
         final StringBuilder tbl = new StringBuilder();
-        
+
         tbl.append("<table>\n<tr>\n");
         int i=0;
         for(String str : links) {
@@ -184,106 +185,106 @@
 
         tbl.append("</table>\n");
         return tbl.toString();
-  }
-  
-  @Override
-  protected void renderContent(HttpServletRequest req, HttpServletResponse res)
+    }
+
+    @Override
+    protected void renderContent(HttpServletRequest req, HttpServletResponse res)
       throws ServletException, IOException {
 
-    // If so requested, clear our data
-    if(req.getParameter(CLEAR) != null) {
-      clear();
-      res.sendRedirect(LABEL);
-      return;
-    }
-    
-    // Select request to display
-    int index = 0;
-    final String tmp = req.getParameter(INDEX);
-    if (tmp != null) {
-      try {
-        index = Integer.parseInt(tmp);
-      } catch (NumberFormatException ignore) {
-        // ignore
-      }
-    }
-
-    // index is relative to lastRequestIndex
-    final int arrayIndex = getArrayIndex(index); 
-
-    SlingHttpServletRequest r = null;
-    try {
-      r = requests[arrayIndex];
-    } catch (ArrayIndexOutOfBoundsException ignore) {
-      // ignore
-    }
-
-    final PrintWriter pw = res.getWriter();
-
-    pw.println("<table class='content' cellpadding='0' cellspacing='0' width='100%'>");
-
-    // Links to other requests
-    pw.println("<thead>");
-    pw.println("<tr class='content'>");
-    pw.println("<th colspan='2'class='content container'>Recent Requests");
-    pw.println(" (<a href='" + LABEL + "?clear=clear'>Clear</a>)");
-    pw.println("</th>");
-    pw.println("</thead>");
-    pw.println("<tbody>");
-    pw.println("<tr class='content'><td>");
-    pw.println(getLinksTable(index));
-    pw.println("</td></tr>");
-
-    if (r != null) {
-      // Request Progress Tracker Info
-      pw.println("<tr class='content'>");
-      pw.println("<th colspan='2'class='content container'>");
-      pw.print("Request " + index + " (" + getRequestLabel(index) + ") - RequestProgressTracker
Info");
-      pw.println("</th></tr>");
-      pw.println("<tr><td colspan='2'>");
-      final Iterator<String> it = r.getRequestProgressTracker().getMessages();
-      pw.print("<pre>");
-      while (it.hasNext()) {
-        pw.print(escape(it.next()));
-      }
-      pw.println("</pre></td></tr>");
-    }
-    pw.println("</tbody></table>");
-  }
-  
-  private static String escape(String str) {
-      final StringBuffer sb = new StringBuffer();
-      for(int i=0; i < str.length(); i++) {
-          final char c = str.charAt(i);
-          if(c == '<') {
-              sb.append("&lt;");
-          } else if (c == '>') {
-              sb.append("&gt;");
-          } else if (c == '&') {
-              sb.append("&amp;");
-          } else {
-              sb.append(c);
-          }
-      }
-      return sb.toString();
-  }
-  
-  private String getRequestLabel(int index) {
-      final StringBuilder sb = new StringBuilder();
-      String path = requests[index].getPathInfo();
-      if(path == null) {
-          path = "";
-      }
-      
-      sb.append(methods[index]);
-      sb.append(' ');
-      
-      final int pos = requests[index].getPathInfo().lastIndexOf('/');
-      if(pos < 0) {
-          sb.append(requests[index].getPathInfo());
-      } else {
-          sb.append(requests[index].getPathInfo().substring(pos+1));
-      }
-      return sb.toString();
-  }
+        // If so requested, clear our data
+        if(req.getParameter(CLEAR) != null) {
+            clear();
+            res.sendRedirect(LABEL);
+            return;
+        }
+
+        // Select request to display
+        int index = 0;
+        final String tmp = req.getParameter(INDEX);
+        if (tmp != null) {
+            try {
+                index = Integer.parseInt(tmp);
+            } catch (NumberFormatException ignore) {
+                // ignore
+            }
+        }
+
+        // index is relative to lastRequestIndex
+        final int arrayIndex = getArrayIndex(index);
+
+        SlingHttpServletRequest r = null;
+        try {
+            r = requests[arrayIndex];
+        } catch (ArrayIndexOutOfBoundsException ignore) {
+            // ignore
+        }
+
+        final PrintWriter pw = res.getWriter();
+
+        pw.println("<table class='content' cellpadding='0' cellspacing='0' width='100%'>");
+
+        // Links to other requests
+        pw.println("<thead>");
+        pw.println("<tr class='content'>");
+        pw.println("<th colspan='2'class='content container'>Recent Requests");
+        pw.println(" (<a href='" + LABEL + "?clear=clear'>Clear</a>)");
+        pw.println("</th>");
+        pw.println("</thead>");
+        pw.println("<tbody>");
+        pw.println("<tr class='content'><td>");
+        pw.println(getLinksTable(index));
+        pw.println("</td></tr>");
+
+        if (r != null) {
+            // Request Progress Tracker Info
+            pw.println("<tr class='content'>");
+            pw.println("<th colspan='2'class='content container'>");
+            pw.print("Request " + index + " (" + getRequestLabel(index) + ") - RequestProgressTracker
Info");
+            pw.println("</th></tr>");
+            pw.println("<tr><td colspan='2'>");
+            final Iterator<String> it = r.getRequestProgressTracker().getMessages();
+            pw.print("<pre>");
+            while (it.hasNext()) {
+                pw.print(escape(it.next()));
+            }
+            pw.println("</pre></td></tr>");
+        }
+        pw.println("</tbody></table>");
+    }
+
+    private static String escape(String str) {
+        final StringBuilder sb = new StringBuilder();
+        for(int i=0; i < str.length(); i++) {
+            final char c = str.charAt(i);
+            if(c == '<') {
+                sb.append("&lt;");
+            } else if (c == '>') {
+                sb.append("&gt;");
+            } else if (c == '&') {
+                sb.append("&amp;");
+            } else {
+                sb.append(c);
+            }
+        }
+        return sb.toString();
+    }
+
+    private String getRequestLabel(int index) {
+        final StringBuilder sb = new StringBuilder();
+        String path = requests[index].getPathInfo();
+        if (path == null) {
+            path = "";
+        }
+
+        sb.append(methods[index]);
+        sb.append(' ');
+
+        final int pos = requests[index].getPathInfo().lastIndexOf('/');
+        if(pos < 0) {
+            sb.append(requests[index].getPathInfo());
+        } else {
+            sb.append(requests[index].getPathInfo().substring(pos+1));
+        }
+        return sb.toString();
+    }
 }
\ No newline at end of file



Mime
View raw message