You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shale.apache.org by gv...@apache.org on 2006/09/30 02:53:19 UTC

svn commit: r451512 - in /shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay: component/chain/ config/ config/beans/ faces/ parser/builder/chain/

Author: gvanmatre
Date: Fri Sep 29 17:53:18 2006
New Revision: 451512

URL: http://svn.apache.org/viewvc?view=rev&rev=451512
Log:
Removed Clay dependencies on commons-validator, shale-application and shale-view.

Modified:
    shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/component/chain/CreateComponentCommand.java
    shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/component/chain/PropertyValueCommand.java
    shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/config/Globals.java
    shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/config/beans/ConfigDefinitionsWatchdogFilter.java
    shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/faces/ClayViewHandler.java
    shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/faces/ClayViewHandlerCommand.java
    shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/parser/builder/chain/JsfDefaultBuilderRule.java

Modified: shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/component/chain/CreateComponentCommand.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/component/chain/CreateComponentCommand.java?view=diff&rev=451512&r1=451511&r2=451512
==============================================================================
--- shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/component/chain/CreateComponentCommand.java (original)
+++ shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/component/chain/CreateComponentCommand.java Fri Sep 29 17:53:18 2006
@@ -169,7 +169,7 @@
         if (facetName != null) {
             facetName = replaceMnemonic(clayContext, facetName);
         }
-        
+
         if (facetName != null) {
             child = parent.getFacet(displayElement.getFacetName());
         } else {

Modified: shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/component/chain/PropertyValueCommand.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/component/chain/PropertyValueCommand.java?view=diff&rev=451512&r1=451511&r2=451512
==============================================================================
--- shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/component/chain/PropertyValueCommand.java (original)
+++ shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/component/chain/PropertyValueCommand.java Fri Sep 29 17:53:18 2006
@@ -19,6 +19,8 @@
  */
 package org.apache.shale.clay.component.chain;
 
+import java.util.Map;
+
 import javax.faces.component.UIComponentBase;
 import javax.faces.context.FacesContext;
 import javax.faces.el.PropertyNotFoundException;
@@ -31,7 +33,6 @@
 import org.apache.shale.util.ConverterHelper;
 import org.apache.shale.util.PropertyHelper;
 import org.apache.shale.util.Tags;
-import org.apache.shale.validator.CommonsValidator;
 
 /**
  * <p>
@@ -195,16 +196,20 @@
             } catch (Exception e) {
                 if (child instanceof UIComponentBase) {
                   ((UIComponentBase) child).getAttributes().put(attributeBean.getName(), expr);
-                } else if (child instanceof CommonsValidator) {
-                   //vars collection is like the components attributes
-                   //native support for shale components
-                  ((CommonsValidator) child).getVars().put(attributeBean.getName(), expr);  
                 } else {
-                   throw e;
+                   if (child.getClass().getName().equals("org.apache.shale.validator.CommonsValidator")) {
+                      Map vars = (Map) propertyHelper.getValue(child, "vars");
+                      //vars collection is like the components attributes
+                      //native support for shale components
+                      vars.put(attributeBean.getName(), expr);
+                   } else {
+                      throw e;
+                   }
                 }
             }
         }
 
         return isFinal;
     }
+
 }

Modified: shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/config/Globals.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/config/Globals.java?view=diff&rev=451512&r1=451511&r2=451512
==============================================================================
--- shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/config/Globals.java (original)
+++ shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/config/Globals.java Fri Sep 29 17:53:18 2006
@@ -118,7 +118,7 @@
 
     /**
      * <p>The name of the initializtion parameter in the web deployment descriptor that
-     * defines the default charset for all html templates.  If not specified, the 
+     * defines the default charset for all html templates.  If not specified, the
      * "<code>file.encoding</code>" system parameter is the default.  The charset can
      * be overridden for each template file using a special comment directive,
      * <code>"&lt;!-- ### clay:page charset="UTF-8" /### --&gt;"</code>.</p>

Modified: shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/config/beans/ConfigDefinitionsWatchdogFilter.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/config/beans/ConfigDefinitionsWatchdogFilter.java?view=diff&rev=451512&r1=451511&r2=451512
==============================================================================
--- shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/config/beans/ConfigDefinitionsWatchdogFilter.java (original)
+++ shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/config/beans/ConfigDefinitionsWatchdogFilter.java Fri Sep 29 17:53:18 2006
@@ -19,11 +19,20 @@
  */
 package org.apache.shale.clay.config.beans;
 
+import java.io.IOException;
+import java.io.StreamTokenizer;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Pattern;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.commons.chain.Command;
 import org.apache.commons.chain.Context;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.shale.application.AbstractRegExpFilter;
-import org.apache.shale.faces.ShaleWebContext;
+
 
 /**
  * <p>This is the timing mechanism for looking for modified
@@ -31,7 +40,43 @@
  * filter chains command that should only be used in the
  * development environment.</p>
  */
-public class ConfigDefinitionsWatchdogFilter extends AbstractRegExpFilter {
+public class ConfigDefinitionsWatchdogFilter implements Command {
+
+    /**
+     * <p>Comma-delimited regular expression patterns to include remote host
+     * names that match.</p>
+     */
+    private String includes = null;
+
+    /**
+     * <p>Array of regular expression patterns for the includes list.</p>
+     */
+    private Pattern[] includesPatterns = new Pattern[0];
+
+    /**
+     * @return an array of regular expression patterns for the includes list.
+     */
+    private Pattern[] getIncludesPatterns() { return includesPatterns; }
+
+    /**
+     * @return Return the comma-delimited regular expresson patterns to include
+     * remote host names that match, if any; otherwise, return
+     * <code>null</code>.
+     */
+    public String getIncludes() { return this.includes; }
+
+
+    /**
+     * <p>Set the comma-delimited regular expression patterns to include
+     * remote host names that match, if any; or <code>null</code> for no
+     * restrictions.</p>
+     *
+     * @param includes New include pattern(s)
+     */
+    public void setIncludes(String includes) {
+        this.includes = includes;
+        this.includesPatterns = precompile(includes);
+    }
 
     /**
      * <p>Log instance for this class.</p>
@@ -46,13 +91,14 @@
      * @param context <code>Context</code> for the current request
      * @return servletPath and pathInfo
      */
-    protected String value(ShaleWebContext context) {
+    protected String value(Context context) {
 
-        String servletPath = context.getRequest().getServletPath();
+        HttpServletRequest request = (HttpServletRequest) context.get("request");
+        String servletPath = request.getServletPath();
         if (servletPath == null) {
             servletPath = "";
         }
-        String pathInfo = context.getRequest().getPathInfo();
+        String pathInfo = request.getPathInfo();
         if (pathInfo == null) {
             pathInfo = "";
         }
@@ -75,8 +121,7 @@
     public boolean execute(Context context) throws Exception {
 
         // Acquire the value to be tested
-        ShaleWebContext webContext = (ShaleWebContext) context;
-        String value = value(webContext);
+        String value = value(context);
         if (log.isDebugEnabled()) {
             log.debug("execute(" + value + ")");
         }
@@ -86,7 +131,7 @@
             if (log.isTraceEnabled()) {
                 log.trace("  accept(include)");
             }
-            accept(webContext);
+            accept(context);
         }
 
         return false;
@@ -107,10 +152,92 @@
      * @param context <code>Context</code> for the current request
      * @exception Exception thrown back to the caller
      */
-    protected void accept(ShaleWebContext context) throws Exception {
-
+    protected void accept(Context context) throws Exception {
         ConfigBeanFactory.refresh();
     }
 
+    /**
+     * <p>Parse the specified string of comma-delimited (and optionally quoted,
+     * if an embedded comma is required) regular expressions into an array
+     * of precompiled <code>Pattern</code> instances that represent these
+     * expressons.</p>
+     *
+     * @param expr Comma-delimited regular expressions
+     * @return Recognized regular expressions
+     */
+     private Pattern[] precompile(String expr) {
+
+        if (expr == null) {
+            return new Pattern[0];
+        }
+
+        // Set up to parse the specified expression
+        StreamTokenizer st =
+          new StreamTokenizer(new StringReader(expr));
+        st.eolIsSignificant(false);
+        st.lowerCaseMode(false);
+        st.slashSlashComments(false);
+        st.slashStarComments(false);
+        st.wordChars(0x00, 0xff);
+        st.quoteChar('\'');
+        st.quoteChar('"');
+        st.whitespaceChars(0, ' ');
+        st.whitespaceChars(',', ',');
+        List list = new ArrayList();
+        int type = 0;
+
+        // Parse each included expression
+        while (true) {
+            try {
+                type = st.nextToken();
+            } catch (IOException e) {
+                ; // Can not happen
+            }
+            if (type == StreamTokenizer.TT_EOF) {
+                break;
+            } else if (type == StreamTokenizer.TT_NUMBER) {
+                list.add(Pattern.compile("" + st.nval));
+            } else if (type == StreamTokenizer.TT_WORD) {
+                list.add(Pattern.compile(st.sval.trim()));
+            } else {
+                throw new IllegalArgumentException(expr);
+            }
+        }
+
+        // Return the precompiled patterns as an array
+        return (Pattern[]) list.toArray(new Pattern[list.size()]);
+
+    }
+
+     /**
+      * <p>Match the specified expression against the specified precompiled
+      * patterns.  If there are no patterns, return the specified unrestricted
+      * return value; otherwise, return <code>true</code> if the expression
+      * matches one of the patterns, or <code>false</code> otherwise.</p>
+      *
+      * @param expr Expression to be tested
+      * @param patterns Array of <code>Pattern</code> to be tested against
+      * @param unrestricted Result to be returned if there are no matches
+      * @return <code>true</code> if a match is found
+      */
+     protected boolean matches(String expr, Pattern[] patterns,
+                             boolean unrestricted) {
+
+         // Check for the unrestricted case
+         if ((patterns == null) || (patterns.length == 0)) {
+             return unrestricted;
+         }
+
+         // Compare each pattern in turn for a match
+         for (int i = 0; i < patterns.length; i++) {
+             if (patterns[i].matcher(expr).matches()) {
+                 return true;
+             }
+         }
+
+         // No match found, so return false
+         return false;
+
+     }
 
 }

Modified: shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/faces/ClayViewHandler.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/faces/ClayViewHandler.java?view=diff&rev=451512&r1=451511&r2=451512
==============================================================================
--- shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/faces/ClayViewHandler.java (original)
+++ shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/faces/ClayViewHandler.java Fri Sep 29 17:53:18 2006
@@ -30,6 +30,7 @@
 import javax.faces.component.UIViewRoot;
 import javax.faces.context.FacesContext;
 import javax.faces.context.ResponseWriter;
+import javax.faces.el.MethodBinding;
 import javax.servlet.http.HttpServletResponse;
 
 import org.apache.commons.logging.Log;
@@ -37,9 +38,6 @@
 import org.apache.shale.clay.component.Clay;
 import org.apache.shale.clay.config.Globals;
 import org.apache.shale.clay.config.beans.PageNotFoundException;
-import org.apache.shale.view.ViewControllerMapper;
-import org.apache.shale.view.faces.FacesConstants;
-import org.apache.shale.view.impl.DefaultViewControllerMapper;
 
 /**
  * <p>This <code>ViewHandler</code> will handle full HTML template views using the
@@ -83,13 +81,6 @@
     private String[] suffixes = null;
 
     /**
-     * <p>The cached {@link ViewControllerMapper} we will use to translate
-     * view identifiers to the class name of a {@link ViewController}.
-     * This code is borrowed from <code>ShaleViewController</code>.</p>
-     */
-    private ViewControllerMapper mapper = null;
-
-    /**
      * <p>This is an overloaded constructor passing the <code>original</code>
      * view handler.</p>
      *
@@ -112,6 +103,16 @@
     }
 
     /**
+     * <p>Application scope attribute under which the
+     * <code>ViewControllerMapper</code> for translating view identifiers
+     * to class names of the corresponding <code>ViewController</code>
+     * is stored.</p>
+     */
+    public static final String VIEW_MAPPER =
+      "org$apache$shale$view$VIEW_MAPPER";
+
+
+    /**
      * @param context faces context
      * @return render kit id calculated from the original handler
      */
@@ -489,16 +490,20 @@
      * @return default managed bean name associated with the view
      */
     protected String getManagedBeanName(FacesContext context, String viewId) {
-        if (mapper == null) {
-            mapper = (ViewControllerMapper)
-              context.getExternalContext().getApplicationMap().
-              get(FacesConstants.VIEW_MAPPER);
+        String managedBeanName = null;
 
-            if (mapper == null) {
-               mapper = new DefaultViewControllerMapper();
-            }
+        Object mapper = context.getApplication().getVariableResolver()
+                                 .resolveVariable(context, VIEW_MAPPER);
+        // is there a view controller mapper
+        if (mapper != null) {
+            StringBuffer el = new StringBuffer();
+            el.append("#{").append(VIEW_MAPPER).append(".mapViewId").append("}");
+            MethodBinding mb = context.getApplication()
+                    .createMethodBinding(el.toString(), new Class[] {String.class});
+            managedBeanName = (String) mb.invoke(context, new Object[] {viewId});
         }
-        return mapper.mapViewId(viewId);
+
+        return managedBeanName;
     }
 
 }

Modified: shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/faces/ClayViewHandlerCommand.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/faces/ClayViewHandlerCommand.java?view=diff&rev=451512&r1=451511&r2=451512
==============================================================================
--- shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/faces/ClayViewHandlerCommand.java (original)
+++ shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/faces/ClayViewHandlerCommand.java Fri Sep 29 17:53:18 2006
@@ -19,10 +19,13 @@
  */
 package org.apache.shale.clay.faces;
 
+import javax.servlet.ServletContext;
+import javax.servlet.ServletRequest;
+import javax.servlet.http.HttpServletRequest;
+
 import org.apache.commons.chain.Command;
 import org.apache.commons.chain.Context;
 import org.apache.shale.clay.config.Globals;
-import org.apache.shale.faces.ShaleWebContext;
 
 /**
  * <p>This is a Shale "preprocess" command that should be registered
@@ -54,10 +57,10 @@
      */
     public boolean execute(Context context) throws Exception {
 
-        ShaleWebContext webContext = (ShaleWebContext) context;
-        int index = indexOfClayTemplateSuffix(webContext);
+        ServletRequest request = (ServletRequest) context.get("request");
+        int index = indexOfClayTemplateSuffix(context);
         if (index != -1) {
-           webContext.getRequest().setAttribute(Globals.CLAY_FULL_VIEW_SUFFIX, suffixes[index]);
+           request.setAttribute(Globals.CLAY_FULL_VIEW_SUFFIX, suffixes[index]);
         }
 
         return false;
@@ -72,25 +75,26 @@
      * @param context commons chains
      * @return index into <code>suffixes</code>
      */
-    protected int indexOfClayTemplateSuffix(ShaleWebContext context) {
-
+    protected int indexOfClayTemplateSuffix(Context context) {
+        HttpServletRequest request = (HttpServletRequest) context.get("request");
+        ServletContext servletContext = (ServletContext) context.get("context");
         if (suffixes == null) {
             suffixes = new String[2];
 
-            suffixes[0] = context.getContext().getInitParameter(
+            suffixes[0] = servletContext.getInitParameter(
                     Globals.CLAY_HTML_TEMPLATE_SUFFIX);
             if (suffixes[0] == null) {
                 suffixes[0] = Globals.CLAY_DEFAULT_HTML_TEMPLATE_SUFFIX;
             }
 
-            suffixes[1] = context.getContext().getInitParameter(
+            suffixes[1] = servletContext.getInitParameter(
                     Globals.CLAY_XML_TEMPLATE_SUFFIX);
             if (suffixes[1] == null) {
                 suffixes[1] = Globals.CLAY_DEFAULT_XML_TEMPLATE_SUFFIX;
             }
 
         }
-        String uri = context.getRequest().getRequestURI();
+        String uri = request.getRequestURI();
 
         if (uri != null) {
             //look at the path

Modified: shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/parser/builder/chain/JsfDefaultBuilderRule.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/parser/builder/chain/JsfDefaultBuilderRule.java?view=diff&rev=451512&r1=451511&r2=451512
==============================================================================
--- shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/parser/builder/chain/JsfDefaultBuilderRule.java (original)
+++ shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/parser/builder/chain/JsfDefaultBuilderRule.java Fri Sep 29 17:53:18 2006
@@ -21,7 +21,6 @@
 
 import org.apache.commons.chain.Command;
 import org.apache.commons.chain.Context;
-import org.apache.shale.clay.parser.builder.Builder;
 import org.apache.shale.clay.parser.builder.JsfDefaultBuilder;