portals-portalapps-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From woon...@apache.org
Subject svn commit: r832821 - in /portals/applications/webcontent/trunk/webcontent-jar/src: main/java/org/apache/portals/applications/webcontent/proxy/impl/ main/java/org/apache/portals/applications/webcontent/rewriter/ test/java/org/apache/portals/application...
Date Wed, 04 Nov 2009 18:00:10 GMT
Author: woonsan
Date: Wed Nov  4 18:00:10 2009
New Revision: 832821

URL: http://svn.apache.org/viewvc?rev=832821&view=rev
Log:
APA-20: Adding custom replacing properties.

Modified:
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/impl/DefaultHttpReverseProxyServlet.java
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/impl/DefaultReverseProxyLinkRewritingParserAaptor.java
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/MappingRewriterController.java
    portals/applications/webcontent/trunk/webcontent-jar/src/test/java/org/apache/portals/applications/webcontent/proxy/TestReverseProxyLinkRewritingParserAaptor.java

Modified: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/impl/DefaultHttpReverseProxyServlet.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/impl/DefaultHttpReverseProxyServlet.java?rev=832821&r1=832820&r2=832821&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/impl/DefaultHttpReverseProxyServlet.java
(original)
+++ portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/impl/DefaultHttpReverseProxyServlet.java
Wed Nov  4 18:00:10 2009
@@ -399,9 +399,9 @@
         Class basicRewriterClass = null;
         Class ruleBasedRewriterClass = null;
         Map<String, Class> adaptorMimeTypeClassMap = new HashMap<String, Class>();
-        Map<String, Object> basicRewriterProps = null;
-        Map<String, Object> rulesetRewriterProps = null;
-        Map<String, Map<String, Object>> parserAdaptorMimeTypeMap = null;
+        Map<String, String []> basicRewriterProps = null;
+        Map<String, String []> rulesetRewriterProps = null;
+        Map<String, Map<String, String []>> parserAdaptorMimeTypeMap = null;
         
         try
         {
@@ -429,11 +429,11 @@
                 Configuration propsConf = basicRewriterConf.subset("property");
                 if (!propsConf.isEmpty())
                 {
-                    basicRewriterProps = new HashMap<String, Object>();
+                    basicRewriterProps = new HashMap<String, String []>();
                     for (Iterator it = propsConf.getKeys(); it.hasNext(); )
                     {
                         String propName = (String) it.next();
-                        basicRewriterProps.put(propName, propsConf.getString(propName));
+                        basicRewriterProps.put(propName, propsConf.getStringArray(propName));
                     }
                 }
             }
@@ -447,11 +447,11 @@
                 Configuration propsConf = ruleBasedRewriterConf.subset("property");
                 if (!propsConf.isEmpty())
                 {
-                    rulesetRewriterProps = new HashMap<String, Object>();
+                    rulesetRewriterProps = new HashMap<String, String []>();
                     for (Iterator it = propsConf.getKeys(); it.hasNext(); )
                     {
                         String propName = (String) it.next();
-                        rulesetRewriterProps.put(propName, propsConf.getString(propName));
+                        rulesetRewriterProps.put(propName, propsConf.getStringArray(propName));
                     }
                 }
             }
@@ -473,15 +473,15 @@
                         Configuration propsConf = parserAdaptorConf.subset("property");
                         if (!propsConf.isEmpty())
                         {
-                            Map<String, Object> parserAdaptorProps = new HashMap<String,
Object>();
+                            Map<String, String []> parserAdaptorProps = new HashMap<String,
String []>();
                             for (Iterator it = propsConf.getKeys(); it.hasNext(); )
                             {
                                 String propName = (String) it.next();
-                                parserAdaptorProps.put(propName, propsConf.getString(propName));
+                                parserAdaptorProps.put(propName, propsConf.getStringArray(propName));
                             }
                             if (parserAdaptorMimeTypeMap == null)
                             {
-                                parserAdaptorMimeTypeMap = new HashMap<String, Map<String,
Object>>();
+                                parserAdaptorMimeTypeMap = new HashMap<String, Map<String,
String []>>();
                             }
                             parserAdaptorMimeTypeMap.put(mimeType, parserAdaptorProps);
                         }
@@ -743,11 +743,11 @@
             
             if (!StringUtils.isBlank(propName))
             {
-                String propValue = conf.getString(propName);
+                String [] propValues = conf.getStringArray(propName);
                 
                 try
                 {
-                    BeanUtils.setProperty(bean, propName, propValue);
+                    setBeanProperty(bean, propName, propValues);
                 }
                 catch (Exception e)
                 {
@@ -795,4 +795,16 @@
         return ruleset;
     }
     
+    private void setBeanProperty(Object bean, String propName, String [] propValues)
+    {
+        try
+        {
+            BeanUtils.setProperty(bean, propName, propValues);
+        }
+        catch (Exception e)
+        {
+            throw new RuntimeException(e);
+        }
+    }
+    
 }

Modified: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/impl/DefaultReverseProxyLinkRewritingParserAaptor.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/impl/DefaultReverseProxyLinkRewritingParserAaptor.java?rev=832821&r1=832820&r2=832821&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/impl/DefaultReverseProxyLinkRewritingParserAaptor.java
(original)
+++ portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/impl/DefaultReverseProxyLinkRewritingParserAaptor.java
Wed Nov  4 18:00:10 2009
@@ -62,6 +62,9 @@
     private Map<HttpReverseProxyPathMapper, Pattern> remoteURLMatchingPatternMap;
     private Map<HttpReverseProxyPathMapper, String> localPathMatchingReplacesMap;
     
+    private Pattern [] customPatterns;
+    private String [] customReplaces;
+    
     public DefaultReverseProxyLinkRewritingParserAaptor()
     {
         this(true, null);
@@ -78,11 +81,31 @@
         this.lookUpAllMappings = lookUpAllMappings;
     }
     
+    public boolean getLookUpAllMappings()
+    {
+        return lookUpAllMappings;
+    }
+    
     public void setBlacklist(Set<String> blacklist)
     {
         this.blacklist = blacklist;
     }
     
+    public void setCustomPatterns(String [] patterns)
+    {
+        customPatterns = new Pattern[patterns.length];
+        
+        for (int i = 0; i < patterns.length; i++)
+        {
+            customPatterns[i] = Pattern.compile(patterns[i], Pattern.CASE_INSENSITIVE);
+        }
+    }
+    
+    public void setCustomReplaces(String [] customReplaces)
+    {
+        this.customReplaces = customReplaces;
+    }
+    
     @Override
     protected String rewriteLine(String line) throws Exception
     {
@@ -175,6 +198,15 @@
             line = matcher.replaceAll("$1$2=$3" + defaultRemoteURLReplaces + "$6$3");
         }
         
+        if (customPatterns != null)
+        {
+            for (int i = 0; i < customPatterns.length; i++)
+            {
+                Matcher matcher = customPatterns[i].matcher(line);
+                line = matcher.replaceAll(customReplaces[i]);
+            }
+        }
+        
         return line;
     }
     

Modified: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/MappingRewriterController.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/MappingRewriterController.java?rev=832821&r1=832820&r2=832821&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/MappingRewriterController.java
(original)
+++ portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/MappingRewriterController.java
Wed Nov  4 18:00:10 2009
@@ -19,7 +19,6 @@
 import java.io.File;
 import java.io.InputStream;
 import java.io.Reader;
-import java.lang.reflect.InvocationTargetException;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
@@ -75,13 +74,13 @@
     protected Map<String, Class> parserAdaptorMimeTypeClassMap;
     
     /** Basic rewriter instance properties */
-    protected Map<String, Object> basicRewriterProps;
+    protected Map<String, String []> basicRewriterProps;
     
     /** Ruleset rewriter instance properties */
-    protected Map<String, Object> rulesetRewriterProps;
+    protected Map<String, String []> rulesetRewriterProps;
     
     /** Parser adaptor rewriter instance properties map */
-    protected Map<String, Map<String, Object>> parserAdaptorMimeTypePropsMap;
+    protected Map<String, Map<String, String []>> parserAdaptorMimeTypePropsMap;
     
     public MappingRewriterController( String mappingFile ) throws RewriterException
     {
@@ -194,20 +193,13 @@
     {
         Rewriter rewriter = (Rewriter) basicRewriterClass.newInstance();
         
-        try
+        if (basicRewriterProps != null)
         {
-            if (basicRewriterProps != null)
+            for (Map.Entry<String, String []> entry : basicRewriterProps.entrySet())
             {
-                for (Map.Entry<String, Object> entry : basicRewriterProps.entrySet())
-                {
-                    BeanUtils.setProperty(rewriter, entry.getKey(), entry.getValue());
-                }
+                setBeanProperty(rewriter, entry.getKey(), entry.getValue());
             }
         }
-        catch (InvocationTargetException e)
-        {
-            throw new RuntimeException(e);
-        }
         
         return rewriter;
     }
@@ -219,20 +211,13 @@
             RulesetRewriter rewriter = (RulesetRewriter) rulesetRewriterClass.newInstance();
             rewriter.setRuleset(ruleset);
             
-            try
+            if (rulesetRewriterProps != null)
             {
-                if (rulesetRewriterProps != null)
+                for (Map.Entry<String, String []> entry : rulesetRewriterProps.entrySet())
                 {
-                    for (Map.Entry<String, Object> entry : rulesetRewriterProps.entrySet())
-                    {
-                        BeanUtils.setProperty(rewriter, entry.getKey(), entry.getValue());
-                    }
+                    setBeanProperty(rewriter, entry.getKey(), entry.getValue());
                 }
             }
-            catch (InvocationTargetException e)
-            {
-                throw new RuntimeException(e);
-            }
             
             return rewriter;
         }
@@ -240,6 +225,7 @@
         {
             log.error("Error creating rewriter class", e);
         }
+        
         return null;
     }
 
@@ -254,25 +240,18 @@
             {
                 parserAdaptor = (ParserAdaptor) parserAdaptorClass.newInstance();
             
-                try
+                if (parserAdaptorMimeTypePropsMap != null)
                 {
-                    if (parserAdaptorMimeTypePropsMap != null)
+                    Map<String, String []> parserAdaptorProps = parserAdaptorMimeTypePropsMap.get(mimeType);
+                    
+                    if (parserAdaptorProps != null)
                     {
-                        Map<String, Object> parserAdaptorProps = parserAdaptorMimeTypePropsMap.get(mimeType);
-                        
-                        if (parserAdaptorProps != null)
+                        for (Map.Entry<String, String []> entry : parserAdaptorProps.entrySet())
                         {
-                            for (Map.Entry<String, Object> entry : parserAdaptorProps.entrySet())
-                            {
-                                BeanUtils.setProperty(parserAdaptor, entry.getKey(), entry.getValue());
-                            }
+                            setBeanProperty(parserAdaptor, entry.getKey(), entry.getValue());
                         }
                     }
                 }
-                catch (InvocationTargetException e)
-                {
-                    throw new RuntimeException(e);
-                }
             }
             
             return parserAdaptor;
@@ -386,32 +365,32 @@
         return ruleset;
     }
     
-    public Map<String, Object> getBasicRewriterProps()
+    public Map<String, String []> getBasicRewriterProps()
     {
         return basicRewriterProps;
     }
     
-    public void setBasicRewriterProps(Map<String, Object> props)
+    public void setBasicRewriterProps(Map<String, String []> props)
     {
         basicRewriterProps = props;
     }
     
-    public Map<String, Object> getRulesetRewriterProps()
+    public Map<String, String []> getRulesetRewriterProps()
     {
         return rulesetRewriterProps;
     }
     
-    public void setRulesetRewriterProps(Map<String, Object> props)
+    public void setRulesetRewriterProps(Map<String, String []> props)
     {
         rulesetRewriterProps = props;
     }
     
-    public Map<String, Map<String, Object>> getParserAdaptorMimeTypePropsMap()
+    public Map<String, Map<String, String []>> getParserAdaptorMimeTypePropsMap()
     {
         return parserAdaptorMimeTypePropsMap;
     }
     
-    public void setParserAdaptorMimeTypePropsMap(Map<String, Map<String, Object>>
propsMap)
+    public void setParserAdaptorMimeTypePropsMap(Map<String, Map<String, String []>>
propsMap)
     {
         parserAdaptorMimeTypePropsMap = propsMap;
     }
@@ -420,5 +399,17 @@
     {
         return null;
     }
+    
+    private void setBeanProperty(Object bean, String propName, String [] propValues)
+    {
+        try
+        {
+            BeanUtils.setProperty(bean, propName, propValues);
+        }
+        catch (Exception e)
+        {
+            throw new RuntimeException(e);
+        }
+    }
 
 }
\ No newline at end of file

Modified: portals/applications/webcontent/trunk/webcontent-jar/src/test/java/org/apache/portals/applications/webcontent/proxy/TestReverseProxyLinkRewritingParserAaptor.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/webcontent-jar/src/test/java/org/apache/portals/applications/webcontent/proxy/TestReverseProxyLinkRewritingParserAaptor.java?rev=832821&r1=832820&r2=832821&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/webcontent-jar/src/test/java/org/apache/portals/applications/webcontent/proxy/TestReverseProxyLinkRewritingParserAaptor.java
(original)
+++ portals/applications/webcontent/trunk/webcontent-jar/src/test/java/org/apache/portals/applications/webcontent/proxy/TestReverseProxyLinkRewritingParserAaptor.java
Wed Nov  4 18:00:10 2009
@@ -25,6 +25,7 @@
 
 import junit.framework.TestCase;
 
+import org.apache.commons.beanutils.BeanUtils;
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang.StringUtils;
 import org.apache.portals.applications.webcontent.proxy.impl.DefaultHttpReverseProxyPathMapperImpl;
@@ -59,6 +60,7 @@
         "href=\"http://www.localhost.com/manager/list\">Application Management</a></p>\n"
+
         "<p><a href=\"https://blogs.apache.org/index.html\">Apache Blogs</a></p>\n"
+
         "<p><a href=\"http://apache.org/index.html\">Apache Software Foundation</a></p>\n"
+
+        "<script>new AjaxUpdate('/lazyLoader');</script>\n" +
         "</html>";
     
     private HttpReverseProxyPathMapperProvider proxyPathMapperProvider;
@@ -96,6 +98,12 @@
         DefaultReverseProxyLinkRewritingParserAaptor parserAdaptor = new DefaultReverseProxyLinkRewritingParserAaptor();
         parserAdaptor.setReverseProxyRewritingContext(rewritingContext);
         
+        parserAdaptor.setLookUpAllMappings(false);
+        BeanUtils.setProperty(parserAdaptor, "lookUpAllMappings", new String [] { "true"
});
+        assertTrue(parserAdaptor.getLookUpAllMappings());
+        BeanUtils.setProperty(parserAdaptor, "customPatterns", new String [] { "\\/lazyLoader"
});
+        BeanUtils.setProperty(parserAdaptor, "customReplaces", new String [] { "/busyLoader"
});
+        
         StringReader reader = new StringReader(html);
         StringWriter writer = new StringWriter();
         parserAdaptor.rewrite(null, reader, writer);
@@ -119,6 +127,7 @@
         assertTrue("Wrong rewriting: " + lines.get(9), StringUtils.contains(lines.get(9),
"href=\"/webcontent/rproxy/localhost/manager/list\""));
         assertTrue("Wrong rewriting: " + lines.get(10), StringUtils.contains(lines.get(10),
"href=\"/webcontent/rproxy/secure/blogs_apache/index.html\""));
         assertTrue("Wrong rewriting: " + lines.get(11), StringUtils.contains(lines.get(11),
"href=\"/webcontent/rproxy/apache/index.html\""));
+        assertTrue("Wrong rewriting: " + lines.get(12), StringUtils.contains(lines.get(12),
"new AjaxUpdate('/busyLoader');"));
     }
     
 }



Mime
View raw message