incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1067909 - /sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverWebConsolePlugin.java
Date Mon, 07 Feb 2011 10:53:59 GMT
Author: cziegeler
Date: Mon Feb  7 10:53:59 2011
New Revision: 1067909

URL: http://svn.apache.org/viewvc?rev=1067909&view=rev
Log:
SLING-1968 : Web console plugin is missing HTML header after submitting a value

Modified:
    sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverWebConsolePlugin.java

Modified: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverWebConsolePlugin.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverWebConsolePlugin.java?rev=1067909&r1=1067908&r2=1067909&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverWebConsolePlugin.java
(original)
+++ sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverWebConsolePlugin.java
Mon Feb  7 10:53:59 2011
@@ -20,6 +20,8 @@ package org.apache.sling.jcr.resource.in
 
 import java.io.IOException;
 import java.io.PrintWriter;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Dictionary;
@@ -51,7 +53,8 @@ public class JcrResourceResolverWebConso
 
     private static final String ATTR_SUBMIT = "plugin.submit";
 
-    private static final String ATTR_RESULT = "plugin.result";
+    private static final String PAR_MSG = "msg";
+    private static final String PAR_TEST = "test";
 
     private final transient JcrResourceResolverFactoryImpl resolverFactory;
 
@@ -67,7 +70,7 @@ public class JcrResourceResolverWebConso
         props.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation");
         props.put(Constants.SERVICE_PID, getClass().getName());
         props.put("felix.webconsole.label", "jcrresolver");
-        props.put("felix.webconsole.title", "JCR ResourceResolver");
+        props.put("felix.webconsole.title", "Sling Resource Resolver");
         props.put("felix.webconsole.configprinter.modes", "always");
 
         service = context.registerService(new String[] {
@@ -85,15 +88,19 @@ public class JcrResourceResolverWebConso
     @Override
     protected void doGet(final HttpServletRequest request, final HttpServletResponse response)
     throws ServletException, IOException {
-        String test = (String) request.getAttribute(ATTR_TEST);
-        if (test == null) test = "";
-        String result = (String) request.getAttribute(ATTR_RESULT);
+        final String msg = request.getParameter(PAR_MSG);
+        final String test;
+        if ( msg != null ) {
+            test = request.getParameter(PAR_TEST);
+        } else {
+            test = null;
+        }
 
-        PrintWriter pw = response.getWriter();
+        final PrintWriter pw = response.getWriter();
 
         pw.println("<table class='content' cellpadding='0' cellspacing='0' width='100%'>");
 
-        MapEntries mapEntries = resolverFactory.getMapEntries();
+        final MapEntries mapEntries = resolverFactory.getMapEntries();
 
         titleHtml(pw, "Configuration", null);
         pw.println("<tr class='content'>");
@@ -132,7 +139,7 @@ public class JcrResourceResolverWebConso
         pw.println("<td class='content'>Test</td>");
         pw.print("<td class='content' colspan='2'>");
         pw.print("<form method='post'>");
-        pw.println("<input type='text' name='" + ATTR_TEST + "' value='" + test
+        pw.println("<input type='text' name='" + ATTR_TEST + "' value='" + (test != null
? test : "")
             + "' class='input' size='50'>");
         pw.println("&nbsp;&nbsp;<input type='submit' name='" + ATTR_SUBMIT
             + "' value='Resolve' class='submit'>");
@@ -142,10 +149,10 @@ public class JcrResourceResolverWebConso
         pw.print("</td>");
         pw.println("</tr>");
 
-        if (result != null) {
+        if (msg != null) {
             pw.println("<tr class='content'>");
             pw.println("<td class='content'>&nbsp;</td>");
-            pw.println("<td class='content' colspan='2'>" + result + "</td>");
+            pw.println("<td class='content' colspan='2'>" + msg + "</td>");
             pw.println("</tr>");
         }
 
@@ -173,12 +180,10 @@ public class JcrResourceResolverWebConso
     protected void doPost(HttpServletRequest request,
             HttpServletResponse response) throws ServletException, IOException {
 
-        String test = request.getParameter(ATTR_TEST);
+        final String test = request.getParameter(ATTR_TEST);
+        String msg = null;
         if (test != null && test.length() > 0) {
 
-            // set test value for the re-rendering of the form
-            request.setAttribute(ATTR_TEST, test);
-
             Session session = null;
             try {
                 // prepare the request for the resource resolver
@@ -202,12 +207,12 @@ public class JcrResourceResolverWebConso
                 }
 
                 // set the result to render the result
-                request.setAttribute(ATTR_RESULT, result.toString());
+                msg = result.toString();
 
             } catch (Throwable t) {
 
                 // some error occurred, report it as a result
-                request.setAttribute(ATTR_RESULT, "Test Failure: " + t);
+                msg = "Test Failure: " + t;
 
             } finally {
                 if (session != null) {
@@ -217,8 +222,24 @@ public class JcrResourceResolverWebConso
 
         }
 
-        // finally render the result
-        doGet(request, response);
+        // finally redirect
+        final String path = request.getContextPath() + request.getServletPath() + request.getPathInfo();
+        final String redirectTo;
+        if ( msg == null ) {
+            redirectTo = path;
+        } else {
+            redirectTo = path + '?' + PAR_MSG + '=' + encodeParam(msg) + '&' + PAR_TEST
+ '=' + encodeParam(test);
+        }
+        response.sendRedirect(redirectTo);
+    }
+
+    private String encodeParam(final String value) {
+        try {
+            return URLEncoder.encode(value, "UTF-8");
+        } catch (UnsupportedEncodingException e) {
+            // should never happen
+            return value;
+        }
     }
 
     // ---------- ConfigurationPrinter



Mime
View raw message