Author: woonsan
Date: Tue Dec 23 14:34:03 2014
New Revision: 1647583

URL: http://svn.apache.org/r1647583
Log:
APA-67: javadocs in reverse-proxy portlets module

Added:
    
portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/util/RewriterUtils.java
Modified:
    
portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/proxy/DefaultPortletProxyTagNodeVisitor.java
    
portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/proxy/GenericReverseProxyPortlet.java
    
portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/proxy/MimeResponseSink.java
    
portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/proxy/PortletAnyProxyMapping.java
    
portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/proxy/PortletRequestContext.java
    
portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/proxy/SimpleReverseProxyPortlet.java
    
portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/rewriter/DefaultReverseProxyTextLineContentRewriter.java

Modified: 
portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/proxy/DefaultPortletProxyTagNodeVisitor.java
URL: 
http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/proxy/DefaultPortletProxyTagNodeVisitor.java?rev=1647583&r1=1647582&r2=1647583&view=diff
==============================================================================
--- 
portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/proxy/DefaultPortletProxyTagNodeVisitor.java
 (original)
+++ 
portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/proxy/DefaultPortletProxyTagNodeVisitor.java
 Tue Dec 23 14:34:03 2014
@@ -24,9 +24,9 @@ import javax.portlet.MimeResponse;
 import javax.portlet.PortletResponse;
 import javax.portlet.PortletURL;
 
-import org.apache.commons.lang.StringUtils;
 import org.apache.http.client.utils.URIUtils;
 import org.apache.portals.applications.webcontent2.proxy.ProxyContext;
+import org.apache.portals.applications.webcontent2.proxy.util.RewriterUtils;
 import 
org.apache.portals.applications.webcontent2.rewriter.htmlcleaner.AbstractProxyTagNodeVisitor;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -103,17 +103,6 @@ public class DefaultPortletProxyTagNodeV
 
     protected boolean isRewritableURI(String uri)
     {
-        // mailto: URIs often contain invalid characters in web pages to avoid 
spams
-        // and #, javascript: and data: URIs do not need to be parsed at all.
-        // These should be avoided in URI rewriting.
-        if (StringUtils.startsWith(uri, "#") 
-                        || StringUtils.startsWith(uri, "javascript:")
-                        || StringUtils.startsWith(uri, "mailto:";)
-                        || StringUtils.startsWith(uri, "data:"))
-        {
-            return false;
-        }
-
-        return true;
+        return RewriterUtils.isRewritableURI(uri);
     }
 }

Modified: 
portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/proxy/GenericReverseProxyPortlet.java
URL: 
http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/proxy/GenericReverseProxyPortlet.java?rev=1647583&r1=1647582&r2=1647583&view=diff
==============================================================================
--- 
portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/proxy/GenericReverseProxyPortlet.java
 (original)
+++ 
portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/proxy/GenericReverseProxyPortlet.java
 Tue Dec 23 14:34:03 2014
@@ -40,25 +40,45 @@ import org.apache.portals.bridges.veloci
 public class GenericReverseProxyPortlet extends GenericVelocityPortlet
 {
 
+    /**
+     * Name of the portlet request parameter pointing at the target remote URI.
+     */
     public static final String REMOTE_URI_PARAM_NAME = "remote.uri";
 
+    /**
+     * Internal {@link ReverseProxyService} to invoke while processing reverse 
proxy requests.
+     */
     private ReverseProxyService proxyService;
 
+    /**
+     * Zero-argument default constructor.
+     */
     public GenericReverseProxyPortlet()
     {
         super();
     }
 
+    /**
+     * Returns the internal {@link ReverseProxyService} instance.
+     * @return
+     */
     public ReverseProxyService getProxyService()
     {
         return proxyService;
     }
 
+    /**
+     * Sets the internal {@link ReverseProxyService} instance.
+     * @param proxyService
+     */
     public void setProxyService(ReverseProxyService proxyService)
     {
         this.proxyService = proxyService;
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public void doView(RenderRequest request, RenderResponse response) throws 
PortletException, IOException
     {
@@ -66,12 +86,18 @@ public class GenericReverseProxyPortlet
         invokeProxyService(request, response);
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public void serveResource(ResourceRequest request, ResourceResponse 
response) throws PortletException, IOException
     {
         invokeProxyService(request, response);
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public void processAction(ActionRequest request, ActionResponse response) 
throws PortletException, IOException
     {
@@ -83,6 +109,9 @@ public class GenericReverseProxyPortlet
         }
     }
 
+    /**
+     * Invokes the internal {@link ReverseProxyService} on portlet requests.
+     */
     protected void invokeProxyService(PortletRequest request, PortletResponse 
response) throws PortletException, IOException
     {
         try

Modified: 
portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/proxy/MimeResponseSink.java
URL: 
http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/proxy/MimeResponseSink.java?rev=1647583&r1=1647582&r2=1647583&view=diff
==============================================================================
--- 
portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/proxy/MimeResponseSink.java
 (original)
+++ 
portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/proxy/MimeResponseSink.java
 Tue Dec 23 14:34:03 2014
@@ -24,21 +24,39 @@ import javax.portlet.MimeResponse;
 
 import org.apache.portals.applications.webcontent2.rewriter.Sink;
 
+/**
+ * Acts as an holder for a content rewriting {@link Sink}
+ * in the form of byte or character stream of {@link MimeResponse}.
+ */
 public class MimeResponseSink implements Sink
 {
 
+    /**
+     * Underlying {@link MimeResponse} of this sink.
+     */
     private final MimeResponse response;
 
+    /**
+     * Constructs a <code>MimeResponseSink</code> for the given
+     * <code>response</code>.
+     * @param response
+     */
     public MimeResponseSink(final MimeResponse response)
     {
         this.response = response;
     }
 
+    /**
+     * Returns the {@link java.io.OutputStream} of the underlying {@link 
MimeResponse}.
+     */
     public OutputStream getOutputStream() throws IOException
     {
         return response.getPortletOutputStream();
     }
 
+    /**
+     * Returns the {@link java.io.Writer} of the underlying {@link 
MimeResponse}.
+     */
     public Writer getWriter() throws IOException
     {
         return response.getWriter();

Modified: 
portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/proxy/PortletAnyProxyMapping.java
URL: 
http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/proxy/PortletAnyProxyMapping.java?rev=1647583&r1=1647582&r2=1647583&view=diff
==============================================================================
--- 
portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/proxy/PortletAnyProxyMapping.java
 (original)
+++ 
portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/proxy/PortletAnyProxyMapping.java
 Tue Dec 23 14:34:03 2014
@@ -23,43 +23,97 @@ import javax.portlet.PortletRequest;
 
 import org.apache.commons.lang.StringUtils;
 import org.apache.portals.applications.webcontent2.proxy.ProxyContext;
+import org.apache.portals.applications.webcontent2.proxy.ProxyMapping;
 import 
org.apache.portals.applications.webcontent2.proxy.impl.AbstractProxyMapping;
 
+/**
+ * Default {@link ProxyMapping} implementation for a generic reverse proxy 
portlet.
+ * <p>
+ * Because a generic reverse proxy portlet may serve any remote content,
+ * this allows matching from any local path info and any remote content URI.
+ * And this resolves the remote target URI by reading {@link 
GenericReverseProxyPortlet.REMOTE_URI_PARAM_NAME}
+ * request parameter value.
+ * </p>
+ */
 public class PortletAnyProxyMapping extends AbstractProxyMapping
 {
 
+    /**
+     * Underlying {@link PortletConfig}.
+     */
     private PortletConfig portletConfig;
 
+    /**
+     * Constructs a {@link PortletAnyProxyMapping} with the given 
<code>portletConfig</code>.
+     * @param portletConfig
+     */
     public PortletAnyProxyMapping(PortletConfig portletConfig)
     {
         this.portletConfig = portletConfig;
     }
 
+    /**
+     * {@inheritDoc}
+     * <p>
+     * Always returns true.
+     * </p>
+     */
     public boolean matchesLocal(String localPath)
     {
         return true;
     }
 
+    /**
+     * {@inheritDoc}
+     * <p>
+     * Returns a resolved remote URI by reading {@link 
GenericReverseProxyPortlet.REMOTE_URI_PARAM_NAME} request parameter value.
+     * </p>
+     */
     public String resolveRemoteFromLocal(String localPath)
     {
         return getCurrentRemoteURI();
     }
 
+    /**
+     * {@inheritDoc}
+     * <p>
+     * Always returns true.
+     * </p>
+     */
     public boolean matchesRemote(URI remoteURI)
     {
         return true;
     }
 
+    /**
+     * {@inheritDoc}
+     * <p>
+     * Always returns <code>/</code> because no local path info can be 
resolved in portlet environment.
+     * </p>
+     */
     public String resolveLocalFromRemote(URI remoteURI)
     {
         return "/";
     }
 
+    /**
+     * Returns the underlying {@link PortletConfig}.
+     * @return
+     */
     protected PortletConfig getPortletConfig()
     {
         return portletConfig;
     }
 
+    /**
+     * Returns the current remote target URI by reading {@link 
GenericReverseProxyPortlet.REMOTE_URI_PARAM_NAME}
+     * request parameter value.
+     * <p>
+     * It reads the request parameter first. If not found, then it reads the 
portlet preferences.
+     * If nothing found, then it reads the portlet init parameter finally.
+     * </p>
+     * @return
+     */
     protected String getCurrentRemoteURI()
     {
         ProxyContext proxyContext = ProxyContext.getCurrentProxyContext();

Modified: 
portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/proxy/PortletRequestContext.java
URL: 
http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/proxy/PortletRequestContext.java?rev=1647583&r1=1647582&r2=1647583&view=diff
==============================================================================
--- 
portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/proxy/PortletRequestContext.java
 (original)
+++ 
portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/proxy/PortletRequestContext.java
 Tue Dec 23 14:34:03 2014
@@ -40,23 +40,55 @@ import org.apache.portals.applications.w
 public class PortletRequestContext implements RequestContext
 {
 
+    /**
+     * Internal portlet request.
+     */
     private final PortletRequest request;
+
+    /**
+     * Internal portlet response.
+     */
     private final PortletResponse response;
+
+    /**
+     * Response status holder.
+     */
     private int responseStatus;
+
+    /**
+     * Response cookies holder.
+     */
     private List<Cookie> responseCookies;
+
+    /**
+     * Portlet response based {@link Sink}.
+     */
     private Sink sink;
 
+    /**
+     * Constructs a {@link PortletRequestContext} with given portlet request 
and portlet response.
+     * @param request
+     * @param response
+     */
     public PortletRequestContext(final PortletRequest request, final 
PortletResponse response)
     {
         this.request = request;
         this.response = response;
     }
 
+    /**
+     * Returns the underlying portlet request.
+     * @return
+     */
     public PortletRequest getPortletRequest()
     {
         return request;
     }
 
+    /**
+     * Returns the underlying portlet response.
+     * @return
+     */
     public PortletResponse getPortletResponse()
     {
         return response;

Modified: 
portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/proxy/SimpleReverseProxyPortlet.java
URL: 
http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/proxy/SimpleReverseProxyPortlet.java?rev=1647583&r1=1647582&r2=1647583&view=diff
==============================================================================
--- 
portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/proxy/SimpleReverseProxyPortlet.java
 (original)
+++ 
portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/proxy/SimpleReverseProxyPortlet.java
 Tue Dec 23 14:34:03 2014
@@ -25,6 +25,7 @@ import javax.portlet.PortletConfig;
 import javax.portlet.PortletException;
 
 import org.apache.commons.lang.ArrayUtils;
+import org.apache.commons.lang.BooleanUtils;
 import org.apache.commons.lang.StringUtils;
 import org.apache.http.impl.client.HttpClientBuilder;
 import org.apache.http.impl.client.HttpClients;
@@ -42,22 +43,73 @@ import org.apache.portals.applications.w
 import org.htmlcleaner.SimpleHtmlSerializer;
 import org.htmlcleaner.TagNodeVisitor;
 
+/**
+ * Simple reverse proxy portlet implementation with using {@link 
HtmlCleanerContentRewriter}
+ * as the default {@link ContentRewriter}.
+ * And this is given as an example and a base class to be overriden.
+ * <p>
+ * This portlet reads {@link #XPATH_EXPRESSION_PARAM_NAME} parameter value 
(<code>//body</code> by default)
+ * to select only the specified DOM element and its descendants.
+ * Also, this portlet can transform the content by using 
<code>HtmlCleaner</code> transformation rules.
+ * Finally, this portlet can use {@link TagNodeVisitor}s to give custom {@link 
TagNodeVisitor}s a chance
+ * to transform the selected content.
+ * </p>
+ */
 public class SimpleReverseProxyPortlet extends GenericReverseProxyPortlet
 {
 
+    /**
+     * Parameter name for the XPath expression to select only the specified 
DOM element
+     * after retrieving the remote content.
+     */
     private static final String XPATH_EXPRESSION_PARAM_NAME = 
"xpath.expression";
+
+    /**
+     * Parameter name for the flag whether or not the inner elements should be 
selected by the XPath expression.
+     */
+    private static final String INNER_ELEMENTS_ONLY_PARAM_NAME = 
"inner.elements.only";
+
+    /**
+     * Default value of the flag whether or not the inner elements should be 
selected by the XPath expression.
+     */
+    private static final boolean DEFAULT_INNER_ELEMENTS_ONLY_VALUE = true;
+
+    /**
+     * Parameter name for the <code>HtmlCleander</code> transformation rule.
+     */
     private static final String HTML_CLEANER_TRANSFORMATION_PARAM_NAME = 
"html.cleaner.transformation";
 
+    /**
+     * Internal reverse proxy mapping registry.
+     */
     private ProxyMappingRegistry proxyMappingRegistry;
+
+    /**
+     * Internal {@link HttpClientBuilder} instance.
+     */
     private HttpClientBuilder httpClientBuilder;
+
+    /**
+     * Internal {@link HttpClientContextBuilder} instance.
+     */
     private HttpClientContextBuilder httpClientContextBuilder;
+
+    /**
+     * Internal root reverse proxy processing chain instance.
+     */
     private ProxyProcessingChain proxyServiceCommand;
 
+    /**
+     * Zero-argument default constructor.
+     */
     public SimpleReverseProxyPortlet()
     {
         super();
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public void init(PortletConfig portletConfig) throws PortletException
     {
@@ -70,6 +122,10 @@ public class SimpleReverseProxyPortlet e
         setProxyService(proxyService);
     }
 
+    /**
+     * Returns the internal {@link ProxyMappingRegistry} instance.
+     * @return
+     */
     public ProxyMappingRegistry getProxyMappingRegistry()
     {
         if (proxyMappingRegistry == null)
@@ -81,11 +137,19 @@ public class SimpleReverseProxyPortlet e
         return proxyMappingRegistry;
     }
 
+    /**
+     * Sets the internal {@link ProxyMappingRegistry} instance.
+     * @param proxyMappingRegistry
+     */
     public void setProxyMappingRegistry(ProxyMappingRegistry 
proxyMappingRegistry)
     {
         this.proxyMappingRegistry = proxyMappingRegistry;
     }
 
+    /**
+     * Returns the internal {@link HttpClientBuilder} instance.
+     * @return
+     */
     public HttpClientBuilder getHttpClientBuilder()
     {
         if (httpClientBuilder == null)
@@ -96,21 +160,36 @@ public class SimpleReverseProxyPortlet e
         return httpClientBuilder;
     }
 
+    /**
+     * Sets the internal {@link HttpClientBuilder} instance.
+     * @param httpClientBuilder
+     */
     public void setHttpClientBuilder(HttpClientBuilder httpClientBuilder)
     {
         this.httpClientBuilder = httpClientBuilder;
     }
 
+    /**
+     * Returns the internal {@link HttpClientContextBuilder} instance.
+     * @return
+     */
     public HttpClientContextBuilder getHttpClientContextBuilder()
     {
         return httpClientContextBuilder;
     }
 
+    /**
+     * Sets the internal {@link HttpClientContextBuilder} instance.
+     * @param httpClientContextBuilder
+     */
     public void setHttpClientContextBuilder(HttpClientContextBuilder 
httpClientContextBuilder)
     {
         this.httpClientContextBuilder = httpClientContextBuilder;
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public void destroy()
     {
@@ -118,10 +197,19 @@ public class SimpleReverseProxyPortlet e
         super.destroy();
     }
 
+    /**
+     * {@link #init(PortletConfig) method invokes this method to
+     * create the root reverse proxy processing chain ({@link 
ProxyProcessingChain}).
+     * @return
+     */
     protected ProxyProcessingChain createProxyServiceCommand() {
         return ProxyServices.createDefault().build(getProxyMappingRegistry(), 
getHttpClientBuilder(), getHttpClientContextBuilder());
     }
 
+    /**
+     * Returns a {@link ProxyMapping} instance ({@link PortletAnyProxyMapping} 
by default).
+     * @return
+     */
     protected ProxyMapping getProxyMapping()
     {
         PortletAnyProxyMapping portletAnyProxyMapping = new 
PortletAnyProxyMapping(getPortletConfig());
@@ -129,6 +217,12 @@ public class SimpleReverseProxyPortlet e
         return portletAnyProxyMapping;
     }
 
+    /**
+     * Returns a map containing only a {@link ContentRewriter} for 
<code>text/html</code> content
+     * by default. The {@link ContentRewriter} for HTML content is {@link 
HtmlCleanerContentRewriter}, by default,
+     * which is implemented with <code>HtmlCleander</code> library.
+     * @return
+     */
     protected Map<String, ContentRewriter> getContentRewriters()
     {
         Map<String, ContentRewriter> contentRewriters = new HashMap<String, 
ContentRewriter>();
@@ -139,7 +233,7 @@ public class SimpleReverseProxyPortlet e
         HtmlCleanerContentRewriter contentRewriter = new 
HtmlCleanerContentRewriter();
         contentRewriter.setSerializerFactory(serializerFactory);
         contentRewriter.setXpathExpression(getXpathExpression());
-        contentRewriter.setInnerHtmlOnly(true);
+        contentRewriter.setInnerHtmlOnly(isInnerElementsOnly());
 
         String [] cleanerTransformations = 
getCleanerTransformationStringArray();
 
@@ -158,11 +252,16 @@ public class SimpleReverseProxyPortlet e
             }
         }
 
-        contentRewriters.put("text/html",contentRewriter);
+        contentRewriters.put("text/html", contentRewriter);
 
         return contentRewriters;
     }
 
+    /**
+     * Returns the XPath expression to select only the specific DOM element 
and its descendants from the remote content document.
+     * If not set, it returns <code>//body</code> by default.
+     * @return
+     */
     protected String getXpathExpression()
     {
         String expression = 
getPortletConfig().getInitParameter(XPATH_EXPRESSION_PARAM_NAME);
@@ -175,6 +274,24 @@ public class SimpleReverseProxyPortlet e
         return expression;
     }
 
+    /**
+     * Returns the flag whether or not only the inner elements should be 
selected by the XPath expression.
+     * @return
+     */
+    protected boolean isInnerElementsOnly() {
+        String param = 
getPortletConfig().getInitParameter(INNER_ELEMENTS_ONLY_PARAM_NAME);
+
+        if (StringUtils.isBlank(param)) {
+            return DEFAULT_INNER_ELEMENTS_ONLY_VALUE;
+        } else {
+            return BooleanUtils.toBoolean(param);
+        }
+    }
+
+    /**
+     * Returns <code>HtmlCleaner</code> transformation string array.
+     * @return
+     */
     protected String [] getCleanerTransformationStringArray()
     {
         String param = 
getPortletConfig().getInitParameter(HTML_CLEANER_TRANSFORMATION_PARAM_NAME);
@@ -194,6 +311,11 @@ public class SimpleReverseProxyPortlet e
         return tokens;
     }
 
+    /**
+     * Returns a list of {@link TagNodeVisitor}s which are given a chance to 
visit all the tag nodes.
+     * Custom {@TagNodeVisitor}s can be used to translate the selected content 
from the remote content.
+     * @return
+     */
     protected List<TagNodeVisitor> getTagNodeVisitors()
     {
         List<TagNodeVisitor> visitors = new ArrayList<TagNodeVisitor>();

Modified: 
portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/rewriter/DefaultReverseProxyTextLineContentRewriter.java
URL: 
http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/rewriter/DefaultReverseProxyTextLineContentRewriter.java?rev=1647583&r1=1647582&r2=1647583&view=diff
==============================================================================
--- 
portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/rewriter/DefaultReverseProxyTextLineContentRewriter.java
 (original)
+++ 
portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/rewriter/DefaultReverseProxyTextLineContentRewriter.java
 Tue Dec 23 14:34:03 2014
@@ -28,6 +28,7 @@ import org.apache.portals.applications.w
 import org.apache.portals.applications.webcontent2.proxy.ProxyMappingRegistry;
 import org.apache.portals.applications.webcontent2.proxy.RequestContext;
 import org.apache.portals.applications.webcontent2.proxy.util.CharArraySegment;
+import org.apache.portals.applications.webcontent2.proxy.util.RewriterUtils;
 import 
org.apache.portals.applications.webcontent2.rewriter.ContentRewritingContext;
 import 
org.apache.portals.applications.webcontent2.rewriter.ContentRewritingException;
 import 
org.apache.portals.applications.webcontent2.rewriter.impl.AbstractTextLineContentRewriter;
@@ -55,11 +56,6 @@ public class DefaultReverseProxyTextLine
                     
Pattern.compile("(\\s|^)(href\\s*=\\s*|src\\s*=\\s*|action\\s*=\\s*|url\\s*\\(\\s*)((\"([^\"]*)\")|('([^']*)'))",
 Pattern.CASE_INSENSITIVE);
 
     /**
-     * External URL resources which are not generated from the repository 
resources.
-     */
-    private static final String[] DEFAULT_NONREWRITABLE_URL_PREFIX = { "#", 
"javascript:", "mailto:";, "data:", "webdav:", "ftp:", "callto:", "tel:", "sms:" 
};
-
-    /**
      * Zero-argument default constructor.
      */
     public DefaultReverseProxyTextLineContentRewriter()
@@ -215,19 +211,6 @@ public class DefaultReverseProxyTextLine
      */
     protected boolean isRewritableURI(String uri)
     {
-        if (StringUtils.isBlank(uri))
-        {
-            return false;
-        }
-
-        for (String prefix : DEFAULT_NONREWRITABLE_URL_PREFIX)
-        {
-            if (uri.startsWith(prefix))
-            {
-                return false;
-            }
-        }
-
-        return true;
+        return RewriterUtils.isRewritableURI(uri);
     }
 }

Added: 
portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/util/RewriterUtils.java
URL: 
http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/util/RewriterUtils.java?rev=1647583&view=auto
==============================================================================
--- 
portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/util/RewriterUtils.java
 (added)
+++ 
portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/util/RewriterUtils.java
 Tue Dec 23 14:34:03 2014
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.portals.applications.webcontent2.proxy.util;
+
+import org.apache.commons.lang.StringUtils;
+
+/**
+ * Utilities for content rewriting.
+ */
+public class RewriterUtils
+{
+
+    /**
+     * External URL resources which are not generated from the repository 
resources.
+     */
+    private static final String[] DEFAULT_NONREWRITABLE_URL_PREFIX = { "#", 
"javascript:", "mailto:";, "data:", "webdav:", "ftp:", "callto:", "tel:", "sms:" 
};
+
+    /**
+     * Returns true if the given <code>uri</code> can be rewritten by this. 
Otherwise it returns false.
+     * @param uri
+     * @return
+     */
+    public static boolean isRewritableURI(String uri)
+    {
+        if (StringUtils.isBlank(uri))
+        {
+            return false;
+        }
+
+        for (String prefix : DEFAULT_NONREWRITABLE_URL_PREFIX)
+        {
+            if (uri.startsWith(prefix))
+            {
+                return false;
+            }
+        }
+
+        return true;
+    }
+
+    private RewriterUtils() {
+    }
+
+}


Reply via email to