incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1127023 - in /sling/trunk/bundles: api/src/main/java/org/apache/sling/api/servlets/HtmlResponse.java servlets/post/pom.xml servlets/post/src/main/java/org/apache/sling/servlets/post/HtmlResponse.java
Date Tue, 24 May 2011 13:10:59 GMT
Author: bdelacretaz
Date: Tue May 24 13:10:58 2011
New Revision: 1127023

URL: http://svn.apache.org/viewvc?rev=1127023&view=rev
Log:
SLING-2082 - use ResponseUtil for escaping

Modified:
    sling/trunk/bundles/api/src/main/java/org/apache/sling/api/servlets/HtmlResponse.java
    sling/trunk/bundles/servlets/post/pom.xml
    sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/HtmlResponse.java

Modified: sling/trunk/bundles/api/src/main/java/org/apache/sling/api/servlets/HtmlResponse.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/api/src/main/java/org/apache/sling/api/servlets/HtmlResponse.java?rev=1127023&r1=1127022&r2=1127023&view=diff
==============================================================================
--- sling/trunk/bundles/api/src/main/java/org/apache/sling/api/servlets/HtmlResponse.java
(original)
+++ sling/trunk/bundles/api/src/main/java/org/apache/sling/api/servlets/HtmlResponse.java
Tue May 24 13:10:58 2011
@@ -27,6 +27,8 @@ import java.util.Map;
 
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.sling.api.request.ResponseUtil;
+
 /**
  * Generator for a HTML status response that displays the changes made in a post
  * request. see <a href="HtmlResponse.html">HtmlResponse.html</a> for the
@@ -476,7 +478,7 @@ public class HtmlResponse {
                         state = 0;
                         Object prop = properties.get(varBuffer.toString());
                         if (prop != null) {
-                            out.write(escapeHtmlText(prop.toString()));
+                            out.write(ResponseUtil.escapeXml(prop.toString()));
                         }
                         varBuffer.setLength(0);
                     } else {
@@ -487,25 +489,5 @@ public class HtmlResponse {
         in.close();
         out.flush();
     }
-    
-    public static String escapeHtmlText(String str) {
-        if(str == null) {
-            return null;
-        }
-        final StringBuilder out = new StringBuilder();
-        for(int i=0; i < str.length(); i++) {
-            final char c = str.charAt(i);
-            if(c == '<') {
-                out.append("&lt;");
-            } else if (c == '>') {
-                out.append("&gt;");
-            } else if(c == '&') {
-                out.append("&amp;");
-            } else {
-                out.append(c);
-            }
-        }
-        return out.toString();
-    }
 
 }
\ No newline at end of file

Modified: sling/trunk/bundles/servlets/post/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/post/pom.xml?rev=1127023&r1=1127022&r2=1127023&view=diff
==============================================================================
--- sling/trunk/bundles/servlets/post/pom.xml (original)
+++ sling/trunk/bundles/servlets/post/pom.xml Tue May 24 13:10:58 2011
@@ -115,7 +115,7 @@
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.api</artifactId>
-            <version>2.0.8</version>
+            <version>2.1.0</version>
             <scope>provided</scope>
         </dependency>
         <dependency>

Modified: sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/HtmlResponse.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/HtmlResponse.java?rev=1127023&r1=1127022&r2=1127023&view=diff
==============================================================================
--- sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/HtmlResponse.java
(original)
+++ sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/HtmlResponse.java
Tue May 24 13:10:58 2011
@@ -22,8 +22,11 @@ import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.Reader;
 import java.io.Writer;
+
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.sling.api.request.ResponseUtil;
+
 /**
  * The <code>HtmlResponse</code> is an {@link AbstractPostResponse} preparing
  * the response in HTML (actually XHTML) such that it can be interpreted
@@ -140,7 +143,7 @@ public class HtmlResponse extends Abstra
                         state = 0;
                         Object prop = getProperty(varBuffer.toString());
                         if (prop != null) {
-                            out.write(htmlEscape(prop.toString()));
+                            out.write(ResponseUtil.escapeXml(prop.toString()));
                         }
                         varBuffer.setLength(0);
                     } else {
@@ -152,24 +155,4 @@ public class HtmlResponse extends Abstra
         out.flush();
     }
 
-    /** HTML escaping */
-    static String htmlEscape(String str) {
-        if(str == null) {
-            return null;
-        }
-        final StringBuilder out = new StringBuilder();
-        for(int i=0; i < str.length(); i++) {
-            final char c = str.charAt(i);
-            if(c == '<') {
-                out.append("&lt;");
-            } else if (c == '>') {
-                out.append("&gt;");
-            } else if(c == '&') {
-                out.append("&amp;");
-            } else {
-                out.append(c);
-            }
-        }
-        return out.toString();
-    }
 }
\ No newline at end of file



Mime
View raw message