cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From stevend...@apache.org
Subject svn commit: r1159765 - /cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/ServletProfiler.java
Date Fri, 19 Aug 2011 19:58:48 GMT
Author: stevendolg
Date: Fri Aug 19 19:58:47 2011
New Revision: 1159765

URL: http://svn.apache.org/viewvc?rev=1159765&view=rev
Log:
Reworked class to fix warnings.

Modified:
    cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/ServletProfiler.java

Modified: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/ServletProfiler.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/ServletProfiler.java?rev=1159765&r1=1159764&r2=1159765&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/ServletProfiler.java
(original)
+++ cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/ServletProfiler.java
Fri Aug 19 19:58:47 2011
@@ -30,9 +30,10 @@ import org.apache.cocoon.profiling.data.
  */
 public class ServletProfiler extends Profiler<Servlet> {
 
-    private final static String PROFILING_CONTROLLER_PATH = "cocoon-profiling/";
-    private final static String PROFILING_ID_HEADER = "X-Cocoon-Profiling-ID";
-    private final static String PROFILING_URL_HEADER = "X-Cocoon-Profiling-URL";
+    private static final String PROFILING_CONTROLLER_PATH = "cocoon-profiling/";
+    private static final String PROFILING_ID_HEADER = "X-Cocoon-Profiling-ID";
+    private static final String PROFILING_URL_HEADER = "X-Cocoon-Profiling-URL";
+
     private String mountPath;
 
     public ServletProfiler() {
@@ -46,62 +47,68 @@ public class ServletProfiler extends Pro
 
     @ProfileMethod(name = "service", type = ProfileMethodType.BEFORE_INVOCATION)
     public final void beforeService(ProfilingData data, Servlet component, Object[] args)
{
+        HttpServletRequest request = (HttpServletRequest) args[0];
+
         if (data.isRoot()) {
-            HttpServletRequest request = (HttpServletRequest) args[0];
             HttpServletResponse response = (HttpServletResponse) args[1];
+
             String profilingId = data.getProfilingId();
-            String requestUrl = request.getRequestURL().toString();
             response.addHeader(PROFILING_ID_HEADER, profilingId);
+            
+            String requestUrl = request.getRequestURL().toString();
             response.addHeader(PROFILING_URL_HEADER, this.createRelativeUrl(requestUrl, profilingId));
         }
 
-        HttpServletRequest request = (HttpServletRequest) args[0];
         String requestURI = request.getRequestURI();
         String className = component.getClass().getSimpleName();
-
         data.setDisplayName(String.format("%s (request=%s)", className, requestURI));
     }
 
     public String createRelativeUrl(String inputUrl, String profilingId) {
-        String mountPath = this.getMountPath();
-
-        int questionMarkIndex = inputUrl.indexOf('?');
-        if (questionMarkIndex != -1) {
-            // ignore parameters (could contain slashes)
-            inputUrl = inputUrl.substring(0, questionMarkIndex);
-        }
+        String url = stripQueryPart(inputUrl);
 
         // Don't count the slashes of http://
-        int inputUrlSlashes = countOccurenceOfCharacter('/', inputUrl) - 2;
-        int mountPathSlashes = countOccurenceOfCharacter('/', mountPath);
-
-        StringBuilder sb = new StringBuilder();
+        int inputUrlSlashes = countOccurenceOfCharacter('/', url) - 2;
+        int mountPathSlashes = countOccurenceOfCharacter('/', this.getMountPath());
 
+        StringBuilder stringBuilder = new StringBuilder();
         for (int i = mountPathSlashes; i < inputUrlSlashes; i++) {
-            sb.append("../");
+            stringBuilder.append("../");
         }
 
-        sb.append(PROFILING_CONTROLLER_PATH);
-        sb.append(profilingId);
+        stringBuilder.append(PROFILING_CONTROLLER_PATH);
+        stringBuilder.append(profilingId);
 
-        return sb.toString();
+        return stringBuilder.toString();
     }
 
-    public String getMountPath() {
+    public final String getMountPath() {
         return this.mountPath;
     }
 
-    public void setMountPath(String mountPath) {
+    public final void setMountPath(String mountPath) {
         this.mountPath = mountPath;
     }
 
-    private static int countOccurenceOfCharacter(char c, String s) {
+    private static int countOccurenceOfCharacter(char character, String string) {
         int count = 0;
-        for (int i = 0; i < s.length(); i++) {
-            if (s.charAt(i) == c) {
+
+        for (int i = 0; i < string.length(); i++) {
+            if (string.charAt(i) == character) {
                 count++;
             }
         }
+
         return count;
     }
+
+    private static String stripQueryPart(String inputUrl) {
+        int questionMarkIndex = inputUrl.indexOf('?');
+        if (questionMarkIndex == -1) {
+            return inputUrl;
+        }
+
+        // ignore parameters (could contain slashes)
+        return inputUrl.substring(0, questionMarkIndex);
+    }
 }



Mime
View raw message