Author: cziegeler
Date: Mon Feb 16 08:52:10 2015
New Revision: 1660050

URL: http://svn.apache.org/r1660050
Log:
SLING-4421 : Remove duplicate API method bodys

Modified:
    
sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/RequestUtil.java
    
sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/ResponseUtil.java

Modified: 
sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/RequestUtil.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/RequestUtil.java?rev=1660050&r1=1660049&r2=1660050&view=diff
==============================================================================
--- 
sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/RequestUtil.java
 (original)
+++ 
sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/RequestUtil.java
 Mon Feb 16 08:52:10 2015
@@ -18,8 +18,6 @@
  */
 package org.apache.sling.engine;
 
-import java.util.Collections;
-import java.util.HashMap;
 import java.util.Map;
 
 import javax.servlet.Servlet;
@@ -46,29 +44,8 @@ public class RequestUtil {
      * @return A Map indexed by the Token names where the values are Map
      *         instances indexed by parameter name
      */
-    public static Map<String, Map<String, String>> parserHeader(String value) {
-        Map<String, Map<String, String>> result = new HashMap<String, 
Map<String, String>>();
-        String[] tokens = value.split(",");
-        for (int i = 0; i < tokens.length; i++) {
-            String[] parameters = tokens[i].split(";");
-            String name = parameters[0].trim();
-            Map<String, String> parMap;
-            if (parameters.length > 0) {
-                parMap = new HashMap<String, String>();
-                for (int j = 1; j < parameters.length; j++) {
-                    String[] content = parameters[j].split("=", 2);
-                    if (content.length > 1) {
-                        parMap.put(content[0].trim(), content[1].trim());
-                    } else {
-                        parMap.put(content[0].trim(), content[0].trim());
-                    }
-                }
-            } else {
-                parMap = Collections.emptyMap();
-            }
-            result.put(name, parMap);
-        }
-        return result;
+    public static Map<String, Map<String, String>> parserHeader(final String 
value) {
+        return org.apache.sling.api.request.RequestUtil.parserHeader(value);
     }
 
     /**
@@ -87,30 +64,8 @@ public class RequestUtil {
      *         <code>Double</code> instances providing the value of the
      *         <code>q</code> parameter.
      */
-    public static Map<String, Double> parserAcceptHeader(String value) {
-        Map<String, Double> result = new HashMap<String, Double>();
-        String[] tokens = value.split(",");
-        for (int i = 0; i < tokens.length; i++) {
-            String[] parameters = tokens[i].split(";");
-            String name = parameters[0];
-            Double qVal = new Double(1.0);
-            if (parameters.length > 1) {
-                for (int j = 1; j < parameters.length; j++) {
-                    String[] content = parameters[j].split("=", 2);
-                    if (content.length > 1 && "q".equals(content[0])) {
-                        try {
-                            qVal = Double.valueOf(content[1]);
-                        } catch (NumberFormatException nfe) {
-                            // don't care
-                        }
-                    }
-                }
-            }
-            if (qVal != null) {
-                result.put(name, qVal);
-            }
-        }
-        return result;
+    public static Map<String, Double> parserAcceptHeader(final String value) {
+        return 
org.apache.sling.api.request.RequestUtil.parserAcceptHeader(value);
     }
 
     /**
@@ -124,20 +79,8 @@ public class RequestUtil {
      * <li>Otherwise use the fully qualified name of the servlet class
      * </ol>
      */
-    public static String getServletName(Servlet servlet) {
-        String name = null;
-
-        if (servlet.getServletConfig() != null) {
-            name = servlet.getServletConfig().getServletName();
-        }
-        if (name == null || name.length() == 0) {
-            name = servlet.getServletInfo();
-        }
-        if (name == null || name.length() == 0) {
-            name = servlet.getClass().getName();
-        }
-
-        return name;
+    public static String getServletName(final Servlet servlet) {
+        return 
org.apache.sling.api.request.RequestUtil.getServletName(servlet);
     }
 
     /**
@@ -147,18 +90,12 @@ public class RequestUtil {
      * @param request The request object whose attribute is to be set.
      * @param name The name of the attribute to be set.
      * @param value The new value of the attribute. If this is 
<code>null</code>
-     *            the attribte is actually removed from the request.
+     *            the attribute is actually removed from the request.
      * @return The previous value of the named request attribute or
      *         <code>null</code> if it was not set.
      */
-    public static Object setRequestAttribute(HttpServletRequest request,
-            String name, Object value) {
-        Object oldValue = request.getAttribute(name);
-        if (value == null) {
-            request.removeAttribute(name);
-        } else {
-            request.setAttribute(name, value);
-        }
-        return oldValue;
+    public static Object setRequestAttribute(final HttpServletRequest request,
+            final String name, final Object value) {
+        return 
org.apache.sling.api.request.RequestUtil.setRequestAttribute(request, name, 
value);
     }
 }

Modified: 
sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/ResponseUtil.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/ResponseUtil.java?rev=1660050&r1=1660049&r2=1660050&view=diff
==============================================================================
--- 
sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/ResponseUtil.java
 (original)
+++ 
sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/ResponseUtil.java
 Mon Feb 16 08:52:10 2015
@@ -18,7 +18,6 @@
  */
 package org.apache.sling.engine;
 
-import java.io.IOException;
 import java.io.Writer;
 
 /**
@@ -28,92 +27,14 @@ import java.io.Writer;
 @Deprecated
 public class ResponseUtil {
 
-    private static class XmlEscapingWriter extends Writer {
-        private final Writer target;
-
-        XmlEscapingWriter(Writer target) {
-            this.target = target;
-        }
-
-        @Override
-        public void close() throws IOException {
-            target.close();
-        }
-
-        @Override
-        public void flush() throws IOException {
-            target.flush();
-        }
-
-        @Override
-        public void write(char[] buffer, int offset, int length) throws 
IOException {
-            for(int i = offset; i < offset + length; i++) {
-                write(buffer[i]);
-            }
-        }
-
-        @Override
-        public void write(char[] cbuf) throws IOException {
-            write(cbuf, 0, cbuf.length);
-        }
-
-        @Override
-        public void write(int c) throws IOException {
-            if(c == '&') {
-                target.write("&amp;");
-            } else if(c == '<') {
-                target.write("&lt;");
-            } else if(c == '>') {
-                target.write("&gt;");
-            } else if(c == '"') {
-                target.write("&quot;");
-            } else if(c == '\'') {
-                target.write("&apos;");
-            } else {
-                target.write(c);
-            }
-        }
-
-        @Override
-        public void write(String str, int off, int len) throws IOException {
-            write(str.toCharArray(), off, len);
-        }
-
-        @Override
-        public void write(String str) throws IOException {
-            write(str.toCharArray());
-        }
-    }
-
     /** Escape xml text */
     public static String escapeXml(final String input) {
-        if (input == null) {
-            return null;
-        }
-
-        final StringBuilder b = new StringBuilder(input.length());
-        for(int i = 0;i  < input.length(); i++) {
-            final char c = input.charAt(i);
-            if(c == '&') {
-                b.append("&amp;");
-            } else if(c == '<') {
-                b.append("&lt;");
-            } else if(c == '>') {
-                b.append("&gt;");
-            } else if(c == '"') {
-                b.append("&quot;");
-            } else if(c == '\'') {
-                b.append("&apos;");
-            } else {
-                b.append(c);
-            }
-        }
-        return b.toString();
+        return org.apache.sling.api.request.ResponseUtil.escapeXml(input);
     }
 
     /** Return a Writer that writes escaped XML text to target
      */
-    public static Writer getXmlEscapingWriter(Writer target) {
-        return new XmlEscapingWriter(target);
+    public static Writer getXmlEscapingWriter(final Writer target) {
+        return 
org.apache.sling.api.request.ResponseUtil.getXmlEscapingWriter(target);
     }
 }


Reply via email to