myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From we...@apache.org
Subject svn commit: r916346 - in /myfaces/extensions/scripting/trunk: core/core/src/main/java/org/apache/myfaces/scripting/core/dependencyScan/ core/core/src/main/resources/META-INF/ core/core/src/test/java/org/apache/myfaces/extensions/scripting/dependencySca...
Date Thu, 25 Feb 2010 16:55:32 GMT
Author: werpu
Date: Thu Feb 25 16:55:32 2010
New Revision: 916346

URL: http://svn.apache.org/viewvc?rev=916346&view=rev
Log:
changing the current whitelist system to speed optimized filters

Added:
    myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/dependencyScan/ClassFilter.java
  (with props)
    myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/dependencyScan/DependencyRegistry.java
  (with props)
    myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/dependencyScan/StandardNamespaceFilter.java
  (with props)
    myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/dependencyScan/WhitelistFilter.java
  (with props)
    myfaces/extensions/scripting/trunk/core/core/src/test/java/org/apache/myfaces/extensions/scripting/dependencyScan/FilterTest.java
  (with props)
Modified:
    myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/dependencyScan/ClassDependencies.java
    myfaces/extensions/scripting/trunk/core/core/src/main/resources/META-INF/faces-config.xml
    myfaces/extensions/scripting/trunk/examples/myfaces20-example/src/main/webapp/WEB-INF/java/org/apache/myfaces/javaloader/blog/BlogService.java
    myfaces/extensions/scripting/trunk/examples/myfaces20-example/src/main/webapp/WEB-INF/java/org/apache/myfaces/javaloader/componentTest/JavaTestRenderer1.java
    myfaces/extensions/scripting/trunk/examples/myfaces20-example/src/main/webapp/WEB-INF/java/org/apache/myfaces/javaloader/componentTest/JavaTestRenderer2.java
    myfaces/extensions/scripting/trunk/examples/myfaces20-example/src/main/webapp/WEB-INF/web.xml

Modified: myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/dependencyScan/ClassDependencies.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/dependencyScan/ClassDependencies.java?rev=916346&r1=916345&r2=916346&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/dependencyScan/ClassDependencies.java
(original)
+++ myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/dependencyScan/ClassDependencies.java
Thu Feb 25 16:55:32 2010
@@ -33,7 +33,7 @@
      * classname
      * <p/>
      * <p/>
-     * the key is a dependency a class has the value is a set of classes which depend on
the current class
+     * the key is a dependency a class has the _value is a set of classes which depend on
the current class
      */
     private Map<String, Set<String>> reverseIndex = new ConcurrentHashMap<String,
Set<String>>();
 

Added: myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/dependencyScan/ClassFilter.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/dependencyScan/ClassFilter.java?rev=916346&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/dependencyScan/ClassFilter.java
(added)
+++ myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/dependencyScan/ClassFilter.java
Thu Feb 25 16:55:32 2010
@@ -0,0 +1,10 @@
+package org.apache.myfaces.scripting.core.dependencyScan;
+
+/**
+ * Generic filter pattern interface
+ * used by our dependency registry to prefilter the classes
+ */
+public interface ClassFilter {
+
+    public boolean isAllowed(String clazz);
+}

Propchange: myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/dependencyScan/ClassFilter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/dependencyScan/ClassFilter.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/dependencyScan/DependencyRegistry.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/dependencyScan/DependencyRegistry.java?rev=916346&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/dependencyScan/DependencyRegistry.java
(added)
+++ myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/dependencyScan/DependencyRegistry.java
Thu Feb 25 16:55:32 2010
@@ -0,0 +1,52 @@
+package org.apache.myfaces.scripting.core.dependencyScan;
+
+import org.objectweb.asm.*;
+
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * Registry facade which is used to track our dependencies
+ */
+public class DependencyRegistry {
+    List<ClassFilter> _filters = new LinkedList<ClassFilter>();
+    List<String> _dependencies = new LinkedList<String>();
+
+    public DependencyRegistry() {
+        _filters.add(new StandardNamespaceFilter());
+    }
+
+    public void clearFilters() {
+        _filters.clear();
+        _filters.add(new StandardNamespaceFilter());
+    }
+
+    public void addFilter(ClassFilter filter) {
+        _filters.add(filter);
+    }
+
+    public void addDependency(String source, String dependency) {
+        if (source.equals(dependency)) {
+            return;
+        }
+
+        if (dependency == null || dependency.trim().equals("")) {
+            return;
+        }
+
+        for (ClassFilter filter : _filters) {
+            if (!filter.isAllowed(dependency)) {
+                return;
+            }
+        }
+        //for now we code it into a list like we used to do before
+        //but in the long run we have to directly register
+        //to save one step
+
+    }
+
+    public List<String> getDependencies() {
+        return _dependencies;
+    }
+
+}

Propchange: myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/dependencyScan/DependencyRegistry.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/dependencyScan/DependencyRegistry.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/dependencyScan/StandardNamespaceFilter.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/dependencyScan/StandardNamespaceFilter.java?rev=916346&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/dependencyScan/StandardNamespaceFilter.java
(added)
+++ myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/dependencyScan/StandardNamespaceFilter.java
Thu Feb 25 16:55:32 2010
@@ -0,0 +1,11 @@
+package org.apache.myfaces.scripting.core.dependencyScan;
+
+/**
+ * Filter facade for our standard namespace check
+ */
+public class StandardNamespaceFilter implements ClassFilter {
+
+    public boolean isAllowed(String clazz) {
+        return !ClassScanUtils.isStandardNamespace(clazz);
+    }
+}

Propchange: myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/dependencyScan/StandardNamespaceFilter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/dependencyScan/StandardNamespaceFilter.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/dependencyScan/WhitelistFilter.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/dependencyScan/WhitelistFilter.java?rev=916346&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/dependencyScan/WhitelistFilter.java
(added)
+++ myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/dependencyScan/WhitelistFilter.java
Thu Feb 25 16:55:32 2010
@@ -0,0 +1,64 @@
+package org.apache.myfaces.scripting.core.dependencyScan;
+
+import java.util.*;
+
+/**
+ * Filter class which depends upon a list of whitelisted packages
+ */
+public class WhitelistFilter implements ClassFilter {
+
+    WhiteListNode _whiteList = new WhiteListNode();
+
+    /*we use a package tree here to make the whitelist check as performant as possible*/
+
+    class WhiteListNode {
+        Map<String, WhiteListNode> _value = new HashMap<String, WhiteListNode>();
+
+        public WhiteListNode addEntry(String key) {
+            if (_value.containsKey(key)) {
+                return _value.get(key);
+            }
+            WhiteListNode retVal = new WhiteListNode();
+            _value.put(key, retVal);
+            return retVal;
+        }
+
+        public Map<String, WhiteListNode> getValue() {
+            return _value;
+        }
+
+        public void setValue(Map<String, WhiteListNode> value) {
+            this._value = value;
+        }
+
+        public WhiteListNode get(String key) {
+            return _value.get(key);
+        }
+    }
+
+    public WhitelistFilter(List<String> whiteList) {
+        for (String singlePackage : whiteList) {
+            addEntry(singlePackage);
+        }
+    }
+
+    private void addEntry(String singlePackage) {
+        String[] subPackages = singlePackage.split("\\.");
+        WhiteListNode currPackage = _whiteList;
+        for (String subPackage : subPackages) {
+            currPackage = currPackage.addEntry(subPackage);
+        }
+    }
+
+    public boolean isAllowed(String clazz) {
+        String[] subParts = clazz.split("\\.");
+        WhiteListNode currPackage = _whiteList;
+        for (String subPart : subParts) {
+            currPackage = currPackage.get(subPart);
+            if (currPackage == null) {
+                return false;
+            }
+        }
+        return true;
+    }
+}

Propchange: myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/dependencyScan/WhitelistFilter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/dependencyScan/WhitelistFilter.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Modified: myfaces/extensions/scripting/trunk/core/core/src/main/resources/META-INF/faces-config.xml
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/core/src/main/resources/META-INF/faces-config.xml?rev=916346&r1=916345&r2=916346&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/core/src/main/resources/META-INF/faces-config.xml
(original)
+++ myfaces/extensions/scripting/trunk/core/core/src/main/resources/META-INF/faces-config.xml
Thu Feb 25 16:55:32 2010
@@ -33,9 +33,11 @@
 
     <render-kit>
         <renderer>
+
             <component-family>javax.faces.Output</component-family>
             <renderer-type>org.apache.myfaces.scripting.components.CompilerComponentRenderer</renderer-type>
             <renderer-class>org.apache.myfaces.scripting.components.CompilerComponentRenderer</renderer-class>
         </renderer>
+        
     </render-kit>
 </faces-config>
\ No newline at end of file

Added: myfaces/extensions/scripting/trunk/core/core/src/test/java/org/apache/myfaces/extensions/scripting/dependencyScan/FilterTest.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/core/src/test/java/org/apache/myfaces/extensions/scripting/dependencyScan/FilterTest.java?rev=916346&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/core/core/src/test/java/org/apache/myfaces/extensions/scripting/dependencyScan/FilterTest.java
(added)
+++ myfaces/extensions/scripting/trunk/core/core/src/test/java/org/apache/myfaces/extensions/scripting/dependencyScan/FilterTest.java
Thu Feb 25 16:55:32 2010
@@ -0,0 +1,44 @@
+package org.apache.myfaces.extensions.scripting.dependencyScan;
+
+import org.apache.myfaces.scripting.core.dependencyScan.DependencyRegistry;
+import org.apache.myfaces.scripting.core.dependencyScan.StandardNamespaceFilter;
+import org.apache.myfaces.scripting.core.dependencyScan.WhitelistFilter;
+import org.junit.Test;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+/**
+ *
+ */
+public class FilterTest {
+
+    @Test
+    public void testStandardNamespace() {
+        StandardNamespaceFilter filter = new StandardNamespaceFilter();
+
+        assertFalse("Standard namespace is not allowed", filter.isAllowed("java.lang.String"));
+        assertTrue("Non Standard namespace is not allowed", filter.isAllowed("booga.looga"));
+    }
+
+    @Test
+    public void testWhiteList() {
+        List<String> whiteList = new LinkedList<String>();
+        whiteList.add("com.booga.booga1");
+        whiteList.add("booga2");
+
+        WhitelistFilter filter = new WhitelistFilter(whiteList);
+        assertTrue("Whitelist test 1", filter.isAllowed("com.booga"));
+        assertTrue("Whitelist test 2", filter.isAllowed("com.booga.booga1"));
+        assertTrue("Whitelist test 3", filter.isAllowed("booga2"));
+
+        assertFalse("Whitelist test 4", filter.isAllowed("com.booga1"));
+        assertFalse("Whitelist test 5", filter.isAllowed("org.booga1"));
+        assertFalse("Whitelist test 6", filter.isAllowed("aaa"));
+
+    }
+
+}

Propchange: myfaces/extensions/scripting/trunk/core/core/src/test/java/org/apache/myfaces/extensions/scripting/dependencyScan/FilterTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/extensions/scripting/trunk/core/core/src/test/java/org/apache/myfaces/extensions/scripting/dependencyScan/FilterTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Modified: myfaces/extensions/scripting/trunk/examples/myfaces20-example/src/main/webapp/WEB-INF/java/org/apache/myfaces/javaloader/blog/BlogService.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/examples/myfaces20-example/src/main/webapp/WEB-INF/java/org/apache/myfaces/javaloader/blog/BlogService.java?rev=916346&r1=916345&r2=916346&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/examples/myfaces20-example/src/main/webapp/WEB-INF/java/org/apache/myfaces/javaloader/blog/BlogService.java
(original)
+++ myfaces/extensions/scripting/trunk/examples/myfaces20-example/src/main/webapp/WEB-INF/java/org/apache/myfaces/javaloader/blog/BlogService.java
Thu Feb 25 16:55:32 2010
@@ -49,7 +49,7 @@
             blogEntries.add(entry);
         }
     }
-    
+
     public List<Object> getBlogEntries() {
         return blogEntries;
     }

Modified: myfaces/extensions/scripting/trunk/examples/myfaces20-example/src/main/webapp/WEB-INF/java/org/apache/myfaces/javaloader/componentTest/JavaTestRenderer1.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/examples/myfaces20-example/src/main/webapp/WEB-INF/java/org/apache/myfaces/javaloader/componentTest/JavaTestRenderer1.java?rev=916346&r1=916345&r2=916346&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/examples/myfaces20-example/src/main/webapp/WEB-INF/java/org/apache/myfaces/javaloader/componentTest/JavaTestRenderer1.java
(original)
+++ myfaces/extensions/scripting/trunk/examples/myfaces20-example/src/main/webapp/WEB-INF/java/org/apache/myfaces/javaloader/componentTest/JavaTestRenderer1.java
Thu Feb 25 16:55:32 2010
@@ -41,7 +41,6 @@
  * class to the other
  */
 @FacesRenderer(componentFamily = "javax.faces.Input", rendererType = "at.irian.JavaTestRenderer")
-
 public class JavaTestRenderer1 extends HtmlTextRendererBase {
 
     static Logger log = Logger.getLogger(JavaTestRenderer1.class.getName());

Modified: myfaces/extensions/scripting/trunk/examples/myfaces20-example/src/main/webapp/WEB-INF/java/org/apache/myfaces/javaloader/componentTest/JavaTestRenderer2.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/examples/myfaces20-example/src/main/webapp/WEB-INF/java/org/apache/myfaces/javaloader/componentTest/JavaTestRenderer2.java?rev=916346&r1=916345&r2=916346&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/examples/myfaces20-example/src/main/webapp/WEB-INF/java/org/apache/myfaces/javaloader/componentTest/JavaTestRenderer2.java
(original)
+++ myfaces/extensions/scripting/trunk/examples/myfaces20-example/src/main/webapp/WEB-INF/java/org/apache/myfaces/javaloader/componentTest/JavaTestRenderer2.java
Thu Feb 25 16:55:32 2010
@@ -32,12 +32,11 @@
  * @author Werner Punz (latest modification by $Author$)
  * @version $Revision$ $Date$
  */
-
 public class JavaTestRenderer2 extends HtmlTextareaRendererBase {
 
-    private static final String MSG = "Hello world from Renderer 2";
+    private static final String MSG = "<h2> Hello world from Renderer 2 </h2>";
+    private static final String MSG2 = "<h3> hello world second var <h3>";
 
-    private static final String MSG2 = " hello world second var";
 
     @Override
     public void encodeBegin(FacesContext context, UIComponent component) throws IOException
{
@@ -47,5 +46,4 @@
         writer.write(MSG2);
         writer.write((String) ReflectUtil.executeMethod(component, "getMarker"));
     }
-
 }

Modified: myfaces/extensions/scripting/trunk/examples/myfaces20-example/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/examples/myfaces20-example/src/main/webapp/WEB-INF/web.xml?rev=916346&r1=916345&r2=916346&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/examples/myfaces20-example/src/main/webapp/WEB-INF/web.xml
(original)
+++ myfaces/extensions/scripting/trunk/examples/myfaces20-example/src/main/webapp/WEB-INF/web.xml
Thu Feb 25 16:55:32 2010
@@ -32,7 +32,6 @@
     </context-param>
 
 
-    <!--
     <context-param>
         <description>Additional comma separated loader paths to allow direct editing
on the sources directory instead
             of the deployment dir
@@ -69,7 +68,7 @@
         <param-name>facelets.RESOURCE_RESOLVER</param-name>
         <param-value>org.apache.myfaces.scripting.facelet.ReroutingResourceResolver</param-value>
     </context-param>
-    -->
+   
     <!--
     <context-param>
         <description>a comma separated whitelist of root packages which are compiled
those and nothing else



Mime
View raw message