cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vgritse...@apache.org
Subject svn commit: r160295 - in cocoon/trunk: ./ src/java/org/apache/cocoon/components/modules/input/
Date Wed, 06 Apr 2005 13:59:31 GMT
Author: vgritsenko
Date: Wed Apr  6 06:59:30 2005
New Revision: 160295

URL: http://svn.apache.org/viewcvs?view=rev&rev=160295
Log:
support namespaced xml in the jxpath modules

Modified:
    cocoon/trunk/src/java/org/apache/cocoon/components/modules/input/AbstractJXPathModule.java
    cocoon/trunk/src/java/org/apache/cocoon/components/modules/input/JXPathHelper.java
    cocoon/trunk/src/java/org/apache/cocoon/components/modules/input/JXPathHelperConfiguration.java
    cocoon/trunk/src/java/org/apache/cocoon/components/modules/input/JXPathMetaModule.java
    cocoon/trunk/src/java/org/apache/cocoon/components/modules/input/XMLFileModule.java
    cocoon/trunk/status.xml

Modified: cocoon/trunk/src/java/org/apache/cocoon/components/modules/input/AbstractJXPathModule.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/components/modules/input/AbstractJXPathModule.java?view=diff&r1=160294&r2=160295
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/components/modules/input/AbstractJXPathModule.java
(original)
+++ cocoon/trunk/src/java/org/apache/cocoon/components/modules/input/AbstractJXPathModule.java
Wed Apr  6 06:59:30 2005
@@ -1,19 +1,18 @@
 /*
- * Copyright 1999-2004 The Apache Software Foundation.
- * 
+ * Copyright 1999-2005 The Apache Software Foundation.
+ *
  * Licensed 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.cocoon.components.modules.input;
 
 import java.util.Iterator;
@@ -26,43 +25,63 @@
  * JXPathModule allows to access properties of any object in generic
  * way.  JXPath provides APIs for the traversal of graphs of
  * JavaBeans, DOM and other types of objects using the XPath
- * syntax. JXPathMetaModule is based on this class and duplicates
- * the code since multiple inheritance is not possible. Please keep both
- * classes in sync.
+ * syntax.
+ *
+ * <p><strong>Note:</strong> JXPathMetaModule is based on this class
+ * and duplicates the code since multiple inheritance is not possible.
+ * Please keep both classes in sync.</p>
  *
- * <p>Configuration example:</p>
+ * <h3>Configuration</h3>
  * <table>
- * <tr><td><code>&lt;lenient&gt;false&lt;/lenient&gt;</td>
- * <td>When set to true, non-existing attributes return null, when set to false,
- *     an exception is thrown. Default is true.</td> 
- *</tr>
- * <tr><td><code>&lt;parameter&gt;foo&lt;/parameter&gt;</td>
- * <td>When set overrides attribute name passed to module.</td> 
- *</tr>
- * <tr><td><code>&lt;function name="java.lang.String" prefix="str"/&gt;</td>
- * <td>Imports the class "String" as extension class to the JXPathContext using 
- * the prefix "str". Thus "str:length(xpath)" would apply the method "length" to 
- * the string object obtained from the xpath expression. Please note that the class
- * needs to be fully qualified.</td> 
- *</tr>
- * <tr><td><code>&lt;package name="java.util" prefix="util"/&gt;</td>
- * <td>Imports all classes in the package "java.util" as extension classes to the 
- * JXPathContext using the prefix "util". Thus "util:Date.new()" would create a 
- * new java.util.Date object.</td> 
- * </tr></table>
+ * <tr>
+ *   <td><code>&lt;lenient&gt;false&lt;/lenient&gt;</code></td>
+ *   <td>When set to true, non-existing attributes return null; when set to false,
+ *       an exception is thrown. Default is true.</td>
+ * </tr>
+ * <tr>
+ *   <td><code>&lt;parameter&gt;foo&lt;/parameter&gt;</td>
+ *   <td>When set overrides attribute name passed to module.</td>
+ * </tr>
+ * <tr>
+ *   <td><code>&lt;function name="java.lang.String" prefix="str"/&gt;</td>
+ *   <td>Imports the class "String" as extension class to the JXPathContext using
+ *   the prefix "str". Thus "str:length(xpath)" would apply the method "length" to
+ *   the string object obtained from the xpath expression. Please note that the class
+ *   needs to be fully qualified.</td>
+ * </tr>
+ * <tr>
+ *   <td><code>&lt;package name="java.util" prefix="util"/&gt;</td>
+ *   <td>Imports all classes in the package "java.util" as extension classes to the
+ *   JXPathContext using the prefix "util". Thus "util:Date.new()" would create a
+ *   new java.util.Date object.</td>
+ * </tr>
+ * <tr>
+ *   <td><code>&lt;namespace uri="uri:foo" prefix="bar"/&gt;</td>
+ *   <td>Registers the namespace identified by URI <code>uri:foo</code>
+ *   with the JXPathContext using the prefix <code>bar</code>. Thus
+ *   expressions can query XML with nodes in this namespace using
+ *   registered prefix.</td>
+ * </tr>
+ * </table>
  *
  * @author <a href="mailto:kpiroumian@apache.org">Konstantin Piroumian</a>
  * @author <a href="mailto:haul@apache.org">Christian Haul</a>
- * @version CVS $Id: AbstractJXPathModule.java,v 1.4 2004/03/05 13:02:48 bdelacretaz Exp
$
+ * @author <a href="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
+ * @version $Id$
  */
 public abstract class AbstractJXPathModule extends AbstractInputModule {
 
-    protected JXPathHelperConfiguration configuration = null;
-
-    private static final boolean lenient = true; 
+    /**
+     * Contains all globally registered extension classes and
+     * packages. Thus the lookup and loading of globally registered
+     * extensions is done only once.
+     */
+    protected JXPathHelperConfiguration configuration;
 
-    /** override attribute name */
-    protected String parameter = null;
+    /**
+     * Overrides attribute name
+     */
+    protected String parameter;
 
     /**
      * Configure component. Preprocess list of packages and functions
@@ -73,23 +92,23 @@
      */
     public void configure(Configuration config) throws ConfigurationException {
 
-        this.configuration = JXPathHelper.setup(config, lenient); 
+        this.configuration = JXPathHelper.setup(config);
     }
 
 
     public Object getAttribute(String name, Configuration modeConf, Map objectModel)
-        throws ConfigurationException {
+    throws ConfigurationException {
 
         Object contextObj = getContextObject(modeConf, objectModel);
-        if (modeConf != null) { 
-            name = modeConf.getChild("parameter").getValue(this.parameter != null ? this.parameter
: name); 
+        if (modeConf != null) {
+            name = modeConf.getChild("parameter").getValue(this.parameter != null ? this.parameter
: name);
         }
         return JXPathHelper.getAttribute(name, modeConf, this.configuration, contextObj);
     }
 
 
     public Iterator getAttributeNames(Configuration modeConf, Map objectModel)
-        throws ConfigurationException {
+    throws ConfigurationException {
 
         Object contextObj = getContextObject(modeConf, objectModel);
         return JXPathHelper.getAttributeNames(this.configuration, contextObj);
@@ -97,11 +116,11 @@
 
 
     public Object[] getAttributeValues(String name, Configuration modeConf, Map objectModel)
-        throws ConfigurationException {
+    throws ConfigurationException {
 
         Object contextObj = getContextObject(modeConf, objectModel);
-        if (modeConf != null) { 
-            name = modeConf.getChild("parameter").getValue(this.parameter != null ? this.parameter
: name); 
+        if (modeConf != null) {
+            name = modeConf.getChild("parameter").getValue(this.parameter != null ? this.parameter
: name);
         }
         return JXPathHelper.getAttributeValues(name, modeConf, this.configuration, contextObj);
     }
@@ -114,5 +133,6 @@
      * Examples are: request, session and application context objects.
      */
     protected abstract Object getContextObject(Configuration modeConf,
-                                               Map objectModel) throws ConfigurationException;
+                                               Map objectModel)
+    throws ConfigurationException;
 }

Modified: cocoon/trunk/src/java/org/apache/cocoon/components/modules/input/JXPathHelper.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/components/modules/input/JXPathHelper.java?view=diff&r1=160294&r2=160295
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/components/modules/input/JXPathHelper.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/components/modules/input/JXPathHelper.java Wed
Apr  6 06:59:30 2005
@@ -1,12 +1,12 @@
 /*
- * Copyright 1999-2004 The Apache Software Foundation.
- * 
+ * Copyright 1999-2005 The Apache Software Foundation.
+ *
  * Licensed 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.
@@ -15,22 +15,22 @@
  */
 package org.apache.cocoon.components.modules.input;
 
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.commons.jxpath.ClassFunctions;
-import org.apache.commons.jxpath.FunctionLibrary;
+
 import org.apache.commons.jxpath.JXPathBeanInfo;
 import org.apache.commons.jxpath.JXPathContext;
 import org.apache.commons.jxpath.JXPathIntrospector;
-import org.apache.commons.jxpath.PackageFunctions;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
 
 /**
  * @author <a href="mailto:haul@apache.org">Christian Haul</a>
- * @version CVS $Id$
+ * @author <a href="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
+ * @version $Id$
  */
 public class JXPathHelper {
 
@@ -39,73 +39,21 @@
     }
 
     /**
-     * Configure component. Preprocess list of packages and functions
-     * to add to JXPath context later.
+     * Configure component. Preprocess list of packages, functions
+     * and namespaces to add to the JXPath context later.
+     *
+     * This method used in both AbstractJXPathModule and JXPathMetaModule
+     * to configure JXPath.
      *
      * @param config a <code>Configuration</code> value
      * @exception ConfigurationException if an error occurs
      */
-    public static JXPathHelperConfiguration setup(Configuration config, boolean lenient)
throws ConfigurationException {
-
-        // JXPathMetaModule starts copying here
-        // please keep both in sync.
+    public static JXPathHelperConfiguration setup(Configuration config)
+    throws ConfigurationException {
 
-        lenient = config.getChild("lenient").getValueAsBoolean(lenient);
-        FunctionLibrary library = new FunctionLibrary();
-        getFunctions(library, config);
-        getPackages(library, config);
-        // the following is necessary to be able to use methods on objects without
-        // explicitely registering extension functions (see PackageFunctions javadoc)
-        library.addFunctions(new PackageFunctions("", null));
-        return new JXPathHelperConfiguration(library, lenient);
+        return new JXPathHelperConfiguration(config);
     }
 
-    /**
-     * Register all extension functions listed in the configuration
-     * through <code>&lt;function name="fully.qualified.Class"
-     * prefix="prefix"/&gt;</code> in the given FunctionLibrary.
-     *
-     * @param lib a <code>FunctionLibrary</code> value
-     * @param conf a <code>Configuration</code> value
-     */
-    private static void getFunctions(FunctionLibrary lib, Configuration conf) {
-
-        Configuration[] children = conf.getChildren("function");
-        int i = children.length;
-        while (i-- > 0) {
-            String clazzName = children[i].getAttribute("name", null);
-            String prefix = children[i].getAttribute("prefix", null);
-            if (clazzName != null && prefix != null) {
-                try {
-                    Class clazz = Class.forName(clazzName);
-                    lib.addFunctions(new ClassFunctions(clazz, prefix));
-                } catch (ClassNotFoundException cnf) {
-                    // ignore
-                }
-            }
-        }
-    }
-
-    /**
-     * Register all extension packages listed in the configuration
-     * through <code>&lt;package name="fully.qualified.package"
-     * prefix="prefix"/&gt;</code> in the given FunctionLibrary.
-     *
-     * @param lib a <code>FunctionLibrary</code> value
-     * @param conf a <code>Configuration</code> value
-     */
-    private static void getPackages(FunctionLibrary lib, Configuration conf) {
-
-        Configuration[] children = conf.getChildren("package");
-        int i = children.length;
-        while (i-- > 0) {
-            String packageName = children[i].getAttribute("name", null);
-            String prefix = children[i].getAttribute("prefix", null);
-            if (packageName != null && prefix != null) {
-                lib.addFunctions(new PackageFunctions(packageName, prefix));
-            }
-        }
-    }
 
     /**
      * Actually add global functions and packages as well as those
@@ -115,36 +63,37 @@
      * @param conf a <code>Configuration</code> value holding local
      * packages and functions.
      */
-    private static void setupExtensions(JXPathHelperConfiguration setup, JXPathContext context,
Configuration conf) {
+    private static void setup(JXPathHelperConfiguration setup, JXPathContext context, Configuration
conf)
+    throws ConfigurationException {
 
-        FunctionLibrary localLib = null;
+        // Create local config (if necessary)
+        JXPathHelperConfiguration local = conf == null ? setup : new JXPathHelperConfiguration(setup,
conf);
 
-        if (conf != null) {
-            localLib = new FunctionLibrary();
-            localLib.addFunctions(setup.getLibrary());
-            getPackages(localLib, conf);
-            getFunctions(localLib, conf);
-        } else {
-            localLib = setup.getLibrary();
+        // Setup context with local config
+        context.setLenient(setup.isLenient());
+        context.setFunctions(local.getLibrary());
+        if (local.getNamespaces() != null) {
+            for (Iterator i = local.getNamespaces().entrySet().iterator(); i.hasNext();)
{
+                final Map.Entry entry = (Map.Entry) i.next();
+                context.registerNamespace((String) entry.getKey(), (String) entry.getValue());
+            }
         }
-
-        context.setFunctions(localLib);
     }
 
-    public static Object getAttribute(
-        String name,
-        Configuration modeConf,
-        JXPathHelperConfiguration setup,
-        Object contextObj)
-        throws ConfigurationException {
+    public static Object getAttribute(String name,
+                                      Configuration modeConf,
+                                      JXPathHelperConfiguration setup,
+                                      Object contextObj)
+    throws ConfigurationException {
 
-        if (contextObj == null)
+        if (contextObj == null) {
             return null;
+        }
+
         try {
             JXPathContext jxContext = JXPathContext.newContext(contextObj);
-            setupExtensions(setup, jxContext, modeConf);
-            if (setup.isLenient())
-                jxContext.setLenient(true); // return null insted of exception on non existing
property
+            setup(setup, jxContext, modeConf);
+
             Object obj = jxContext.getValue(name);
             return obj;
         } catch (Exception e) {
@@ -152,33 +101,34 @@
         }
     }
 
-    public static Object[] getAttributeValues(
-        String name,
-        Configuration modeConf,
-        JXPathHelperConfiguration setup,
-        Object contextObj)
-        throws ConfigurationException {
-            
-        if (contextObj == null)
+    public static Object[] getAttributeValues(String name,
+                                              Configuration modeConf,
+                                              JXPathHelperConfiguration setup,
+                                              Object contextObj)
+    throws ConfigurationException {
+
+        if (contextObj == null) {
             return null;
+        }
+
         try {
             JXPathContext jxContext = JXPathContext.newContext(contextObj);
+            setup(setup, jxContext, modeConf);
+
             List values = null;
-            setupExtensions(setup, jxContext, modeConf);
-            if (setup.isLenient())
-                jxContext.setLenient(true); // return null insted of exception on non existing
property
             Iterator i = jxContext.iterate(name);
-            if (i.hasNext()) { 
-                values = new LinkedList(); 
-            } 
+            if (i.hasNext()) {
+                values = new LinkedList();
+            }
             while (i.hasNext()) {
                 values.add(i.next());
             }
             Object[] obj = null;
             if (values != null) {
                 obj = values.toArray();
-                if (obj.length == 0)
+                if (obj.length == 0) {
                     obj = null;
+                }
             }
             return obj;
         } catch (Exception e) {
@@ -187,21 +137,25 @@
     }
 
 
-    public static Iterator getAttributeNames(JXPathHelperConfiguration setup, Object contextObj)
throws ConfigurationException {
+    public static Iterator getAttributeNames(JXPathHelperConfiguration setup, Object contextObj)
+    throws ConfigurationException {
 
-        if (contextObj == null)
+        if (contextObj == null) {
             return null;
+        }
+
         try {
             JXPathBeanInfo info = JXPathIntrospector.getBeanInfo(contextObj.getClass());
             java.beans.PropertyDescriptor[] properties = info.getPropertyDescriptors();
-            java.util.List names = new java.util.LinkedList();
+
+            List names = new LinkedList();
             for (int i = 0; i < properties.length; i++) {
                 names.add(properties[i].getName());
             }
+
             return names.listIterator();
         } catch (Exception e) {
             throw new ConfigurationException("Error retrieving attribute names for class:
" + contextObj.getClass(), e);
         }
-
     }
 }

Modified: cocoon/trunk/src/java/org/apache/cocoon/components/modules/input/JXPathHelperConfiguration.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/components/modules/input/JXPathHelperConfiguration.java?view=diff&r1=160294&r2=160295
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/components/modules/input/JXPathHelperConfiguration.java
(original)
+++ cocoon/trunk/src/java/org/apache/cocoon/components/modules/input/JXPathHelperConfiguration.java
Wed Apr  6 06:59:30 2005
@@ -1,12 +1,12 @@
 /*
- * Copyright 1999-2004 The Apache Software Foundation.
- * 
+ * Copyright 1999-2005 The Apache Software Foundation.
+ *
  * Licensed 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.
@@ -15,11 +15,20 @@
  */
 package org.apache.cocoon.components.modules.input;
 
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+
+import org.apache.commons.jxpath.ClassFunctions;
 import org.apache.commons.jxpath.FunctionLibrary;
+import org.apache.commons.jxpath.PackageFunctions;
+
+import java.util.HashMap;
+import java.util.Map;
 
 /**
  * @author <a href="mailto:haul@apache.org">Christian Haul</a>
- * @version CVS $Id: JXPathHelperConfiguration.java,v 1.3 2004/05/01 00:05:45 joerg Exp $
+ * @author <a href="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
+ * @version $Id$
  */
 public class JXPathHelperConfiguration {
 
@@ -27,30 +36,144 @@
      * Contains all globally registered extension classes and
      * packages. Thus the lookup and loading of globally registered
      * extensions is done only once.
-     *
      */
-    private FunctionLibrary library = null;
+    private FunctionLibrary library;
+
+    /**
+     * Set lenient mode for jxpath
+     * (i.e. throw an exception on unsupported attributes)?
+     * Defaults to true.
+     */
+    private boolean lenient;
 
-    /** set lenient mode for jxpath (i.e. throw an exception on
-     * unsupported attributes) ? 
+    /**
+     * Contains all registered namespace prefixes.
      */
-    private boolean lenient = true;
+    private Map namespaces;
 
 
+    /**
+     * Create empty jxpath configuration
+     */
     public JXPathHelperConfiguration() {
+        this.lenient = true;
     }
 
-    public JXPathHelperConfiguration(FunctionLibrary library, boolean lenient) {
-        this.library = library;
-        this.lenient = lenient;
+    /**
+     * Create root jxpath configuration
+     */
+    public JXPathHelperConfiguration(Configuration config)
+    throws ConfigurationException {
+        this.lenient = config.getChild("lenient").getValueAsBoolean(true);
+        this.library = new FunctionLibrary();
+        setup(config);
+
+        // the following is necessary to be able to use methods on objects without
+        // explicitely registering extension functions (see PackageFunctions javadoc)
+        this.library.addFunctions(new PackageFunctions("", null));
+    }
+
+    /**
+     * Create child jxpath configuration
+     */
+    public JXPathHelperConfiguration(JXPathHelperConfiguration global, Configuration config)
+    throws ConfigurationException {
+        this.lenient = global.lenient;
+        this.library = new FunctionLibrary();
+        this.library.addFunctions(global.getLibrary());
+        if (global.getNamespaces() != null) {
+            this.namespaces = new HashMap(global.getNamespaces());
+        }
+        setup(config);
     }
 
+
     public boolean isLenient() {
-        return lenient;
+        return this.lenient;
     }
 
     public FunctionLibrary getLibrary() {
-        return library;
+        return this.library;
+    }
+
+    public Map getNamespaces() {
+        return this.namespaces;
+    }
+
+
+    private void setup(Configuration config)
+    throws ConfigurationException {
+        getFunctions(config);
+        getPackages(config);
+        getNamespaces(config);
+    }
+
+    /**
+     * Register all extension functions listed in the configuration
+     * through <code>&lt;function name="fully.qualified.Class"
+     * prefix="prefix"/&gt;</code> in the given FunctionLibrary.
+     *
+     * @param conf a <code>Configuration</code> value
+     */
+    private void getFunctions(Configuration conf) {
+
+        Configuration[] children = conf.getChildren("function");
+        int i = children.length;
+        while (i-- > 0) {
+            String clazzName = children[i].getAttribute("name", null);
+            String prefix = children[i].getAttribute("prefix", null);
+            if (clazzName != null && prefix != null) {
+                try {
+                    Class clazz = Class.forName(clazzName);
+                    this.library.addFunctions(new ClassFunctions(clazz, prefix));
+                } catch (ClassNotFoundException cnf) {
+                    // ignore
+                }
+            }
+        }
     }
 
+    /**
+     * Register all extension packages listed in the configuration
+     * through <code>&lt;package name="fully.qualified.package"
+     * prefix="prefix"/&gt;</code> in the given FunctionLibrary.
+     *
+     * @param conf a <code>Configuration</code> value
+     */
+    private void getPackages(Configuration conf) {
+
+        Configuration[] children = conf.getChildren("package");
+        int i = children.length;
+        while (i-- > 0) {
+            String packageName = children[i].getAttribute("name", null);
+            String prefix = children[i].getAttribute("prefix", null);
+            if (packageName != null && prefix != null) {
+                this.library.addFunctions(new PackageFunctions(packageName, prefix));
+            }
+        }
+    }
+
+    /**
+     * Register all namespaces listed in the configuration
+     * through <code>&lt;namespace uri="uri:foo"
+     * prefix="bar"/&gt;</code> in the configuration.
+     *
+     * @param conf a <code>Configuration</code> value
+     */
+    private void getNamespaces(Configuration conf)
+    throws ConfigurationException {
+
+        Configuration[] children = conf.getChildren("namespace");
+        int i = children.length;
+        if (i > 0) {
+            this.namespaces = new HashMap(i + 2);
+        }
+        while (i-- > 0) {
+            String uri = children[i].getAttribute("uri");
+            String prefix = children[i].getAttribute("prefix");
+            if (uri != null && prefix != null) {
+                this.namespaces.put(prefix, uri);
+            }
+        }
+    }
 }

Modified: cocoon/trunk/src/java/org/apache/cocoon/components/modules/input/JXPathMetaModule.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/components/modules/input/JXPathMetaModule.java?view=diff&r1=160294&r2=160295
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/components/modules/input/JXPathMetaModule.java
(original)
+++ cocoon/trunk/src/java/org/apache/cocoon/components/modules/input/JXPathMetaModule.java
Wed Apr  6 06:59:30 2005
@@ -1,19 +1,18 @@
 /*
- * Copyright 1999-2004 The Apache Software Foundation.
- * 
+ * Copyright 1999-2005 The Apache Software Foundation.
+ *
  * Licensed 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.cocoon.components.modules.input;
 
 import java.util.Iterator;
@@ -28,37 +27,53 @@
  * JXPathModule allows to access properties of any object in generic
  * way.  JXPath provides APIs for the traversal of graphs of
  * JavaBeans, DOM and other types of objects using the XPath
- * syntax. This is based on the AbstractJXPathModule and duplicates
- * the code since multiple inheritance is not possible. Please keep both
- * classes in sync.
+ * syntax.
+ *
+ * <p><strong>Note:</strong> This is based on the AbstractJXPathModule
+ * and duplicates the code since multiple inheritance is not possible.
+ * Please keep both classes in sync.</p>
  *
  * <p>Configuration example:</p>
  * <table>
- * <tr><td><code>&lt;lenient&gt;false&lt;/lenient&gt;</td>
- * <td>When set to true, non-existing attributes return null, when set to false,
- *     an exception is thrown. Default is true.</td> 
- *</tr>
- * <tr><td><code>&lt;parameter&gt;false&lt;/parameter&gt;</td>
- * <td>Attribute name to be used instead of passed attribute name.</td> 
- *</tr>
- * <tr><td><code>&lt;from-parameter&gt;false&lt;/from-parameter&gt;</td>
- * <td>Attribute name to pass to configured input module</td> 
- *</tr>
- * <tr><td><code>&lt;input-module name="request-attr"/&gt;</td>
- * <td>Uses the "request-attr" input module to obtain a value and 
- *     applies the given JXPath expression to it.</td> 
- *</tr>
- * <tr><td><code>&lt;function name="java.lang.String" prefix="str"/&gt;</td>
- * <td>Imports the class "String" as extension class to the JXPathContext using 
- * the prefix "str". Thus "str:length(xpath)" would apply the method "length" to 
- * the string object obtained from the xpath expression. Please note that the class
- * needs to be fully qualified.</td> 
- *</tr>
- * <tr><td><code>&lt;package name="java.util" prefix="util"/&gt;</td>
- * <td>Imports all classes in the package "java.util" as extension classes to the 
- * JXPathContext using the prefix "util". Thus "util:Date.new()" would create a 
- * new java.util.Date object.</td> 
- * </tr></table>
+ * <tr>
+ *   <td><code>&lt;lenient&gt;false&lt;/lenient&gt;</td>
+ *   <td>When set to true, non-existing attributes return null, when set to false,
+ *       an exception is thrown. Default is true.</td>
+ * </tr>
+ * <tr>
+ *   <td><code>&lt;parameter&gt;false&lt;/parameter&gt;</td>
+ *   <td>Attribute name to be used instead of passed attribute name.</td>
+ * </tr>
+ * <tr>
+ *   <td><code>&lt;from-parameter&gt;false&lt;/from-parameter&gt;</td>
+ *   <td>Attribute name to pass to configured input module</td>
+ * </tr>
+ * <tr>
+ *   <td><code>&lt;input-module name="request-attr"/&gt;</td>
+ *   <td>Uses the "request-attr" input module to obtain a value and
+ *       applies the given JXPath expression to it.</td>
+ * </tr>
+ * <tr>
+ *   <td><code>&lt;function name="java.lang.String" prefix="str"/&gt;</td>
+ *   <td>Imports the class "String" as extension class to the JXPathContext using
+ *   the prefix "str". Thus "str:length(xpath)" would apply the method "length" to
+ *   the string object obtained from the xpath expression. Please note that the class
+ *   needs to be fully qualified.</td>
+ * </tr>
+ * <tr>
+ *   <td><code>&lt;package name="java.util" prefix="util"/&gt;</td>
+ *   <td>Imports all classes in the package "java.util" as extension classes to the
+ *   JXPathContext using the prefix "util". Thus "util:Date.new()" would create a
+ *   new java.util.Date object.</td>
+ * </tr>
+ * <tr>
+ *   <td><code>&lt;namespace uri="uri:foo" prefix="bar"/&gt;</td>
+ *   <td>Registers the namespace identified by URI <code>uri:foo</code>
+ *   with the JXPathContext using the prefix <code>bar</code>. Thus
+ *   expressions can query XML with nodes in this namespace using
+ *   registered prefix.</td>
+ * </tr>
+ * </table>
  *
  * <p>In addition, it accepts the attributes "parameter" to override
  * the attribute name and "from-parameter" to pass as attribute name
@@ -66,29 +81,28 @@
  *
  * @author <a href="mailto:kpiroumian@apache.org">Konstantin Piroumian</a>
  * @author <a href="mailto:haul@apache.org">Christian Haul</a>
- * @version CVS $Id$
+ * @author <a href="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
+ * @version $Id$
  */
-public class JXPathMetaModule extends AbstractMetaModule implements Configurable, ThreadSafe
{
+public class JXPathMetaModule extends AbstractMetaModule
+                              implements Configurable, ThreadSafe {
 
     /**
      * Contains all globally registered extension classes and
      * packages. Thus the lookup and loading of globally registered
      * extensions is done only once.
-     *
      */
-    protected JXPathHelperConfiguration configuration = null;
+    protected JXPathHelperConfiguration configuration;
 
-    /** set lenient mode for jxpath (i.e. throw an exception on
-     * unsupported attributes) ? 
+    /**
+     * Overrides attribute name
      */
-    private static final boolean lenient = true;
-
     protected String parameter = "";
 
 
     public JXPathMetaModule() {
         // this value has a default in the super class
-        this.defaultInput = "request-attr";
+        super.defaultInput = "request-attr";
     }
 
 
@@ -105,23 +119,23 @@
         this.defaultInput = this.inputConf.getAttribute("name",this.defaultInput);
         this.parameter = config.getChild("parameter").getValue(this.parameter);
 
-        this.configuration = JXPathHelper.setup(config, lenient);
+        this.configuration = JXPathHelper.setup(config);
     }
 
 
     public Object getAttribute(String name, Configuration modeConf, Map objectModel)
-        throws ConfigurationException {
+    throws ConfigurationException {
 
         Object contextObj = getContextObject(modeConf, objectModel);
-        if (modeConf != null) { 
-            name = modeConf.getChild("parameter").getValue(!this.parameter.equals("") ? this.parameter
: name); 
+        if (modeConf != null) {
+            name = modeConf.getChild("parameter").getValue(!this.parameter.equals("") ? this.parameter
: name);
         }
         return JXPathHelper.getAttribute(name, modeConf, this.configuration, contextObj);
     }
 
 
     public Iterator getAttributeNames(Configuration modeConf, Map objectModel)
-        throws ConfigurationException {
+    throws ConfigurationException {
 
         Object contextObj = getContextObject(modeConf, objectModel);
         return JXPathHelper.getAttributeNames(this.configuration, contextObj);
@@ -129,10 +143,10 @@
 
 
     public Object[] getAttributeValues(String name, Configuration modeConf, Map objectModel)
-        throws ConfigurationException {
+    throws ConfigurationException {
 
         Object contextObj = getContextObject(modeConf, objectModel);
-        if (modeConf != null) { 
+        if (modeConf != null) {
             name = modeConf.getChild("parameter").getValue(!this.parameter.equals("") ? this.parameter
: name);
         }
         return JXPathHelper.getAttributeValues(name, modeConf, this.configuration, contextObj);
@@ -140,41 +154,44 @@
 
 
     /**
-     * Looks up object from configured InputModule. 
+     * Looks up object from configured InputModule.
      *
      * @param modeConf a <code>Configuration</code> value
      * @param objectModel a <code>Map</code> value
      * @return an <code>Object</code> value
      */
-    protected  Object getContextObject(Configuration modeConf, Map objectModel) throws ConfigurationException
{
+    protected  Object getContextObject(Configuration modeConf, Map objectModel)
+    throws ConfigurationException {
 
         if (!this.initialized) {
-            this.lazy_initialize();
+            lazy_initialize();
         }
 
         Configuration mConf = null;
-        String inputName=null;
+        String inputName = null;
         String parameter = this.parameter;
-        if (modeConf!=null) {
-            mConf   = modeConf.getChild("input-module");
-            inputName   = mConf.getAttribute("name",null);
-            parameter   = modeConf.getChild("from-parameter").getValue(parameter);
-        }
-
-        if (getLogger().isDebugEnabled())
-            getLogger().debug("modeConf is "+modeConf+" this.inputConf is "+this.inputConf
-                              +" mConf is "+mConf+" this.input is "+this.input
-                              +" this.defaultInput is "+this.defaultInput
-                              +" inputName is "+inputName+" parameter is "+parameter);
-
-        Object obj =  this.getValue(parameter, objectModel, 
-                                    this.input, this.defaultInput, this.inputConf,
-                                    null, inputName, mConf);
-        
-        if (getLogger().isDebugEnabled())
-            getLogger().debug("returning an "+(obj == null ? "null" : obj.getClass().getName())+"
as "+obj);
+        if (modeConf != null) {
+            mConf = modeConf.getChild("input-module");
+            inputName = mConf.getAttribute("name", null);
+            parameter = modeConf.getChild("from-parameter").getValue(parameter);
+        }
+
+        if (getLogger().isDebugEnabled()) {
+            getLogger().debug("modeConf is " + modeConf + " this.inputConf is " + this.inputConf
+                              + " mConf is " + mConf + " this.input is " + this.input
+                              + " this.defaultInput is " + this.defaultInput
+                              + " inputName is " + inputName + " parameter is " + parameter);
+        }
+
+        Object obj = getValue(parameter, objectModel,
+                              this.input, this.defaultInput, this.inputConf,
+                              null, inputName, mConf);
+
+        if (getLogger().isDebugEnabled()) {
+            getLogger().debug("returning an " + (obj == null ? "null" : obj.getClass().getName())
+
+                              " as " + obj);
+        }
 
         return obj;
     }
-
 }

Modified: cocoon/trunk/src/java/org/apache/cocoon/components/modules/input/XMLFileModule.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/components/modules/input/XMLFileModule.java?view=diff&r1=160294&r2=160295
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/components/modules/input/XMLFileModule.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/components/modules/input/XMLFileModule.java Wed
Apr  6 06:59:30 2005
@@ -1,5 +1,5 @@
 /*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2005 The Apache Software Foundation.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -39,7 +39,7 @@
  <grammar>
     <define name="input.module.config.contents" combine="choice">
        <optional><element name="reloadable"><data type="boolean"/></element></optional>
-       <optional><element name="cachable"><data type="boolean"/></element></optional>
+       <optional><element name="cacheable"><data type="boolean"/></element></optional>
        <optional>
           <ref name="org.apache.cocoon.components.modules.input.XMLFileModule:file">
        </optional>
@@ -55,7 +55,7 @@
        <element name="file">
           <attribute name="src"><data type="anyURI"/></attribute>
           <optional><attribute name="reloadable"><data type="boolean"/></attribute></optional>
-          <optional><attribute name="cachable"><data type="boolean"/></attribute></optional>
+          <optional><attribute name="cacheable"><data type="boolean"/></attribute></optional>
        </element>
     </define>
  </grammar>
@@ -83,7 +83,7 @@
  *
  * @author <a href="mailto:jefft@apache.org">Jeff Turner</a>
  * @author <a href="mailto:haul@apache.org">Christian Haul</a>
- * @version CVS $Id$
+ * @version $Id$
  */
 public class XMLFileModule extends AbstractJXPathModule implements Serviceable, ThreadSafe
{
 

Modified: cocoon/trunk/status.xml
URL: http://svn.apache.org/viewcvs/cocoon/trunk/status.xml?view=diff&r1=160294&r2=160295
==============================================================================
--- cocoon/trunk/status.xml (original)
+++ cocoon/trunk/status.xml Wed Apr  6 06:59:30 2005
@@ -426,7 +426,11 @@
    </action>
   </release>
   <release version="2.1.8" date="TBD">
-    <action dev="AG" type="fix" fixes-bug="34325"i due-to="Joachim Breitsprecher" due-to-email="jb@dserv.net">
+    <action dev="VG" type="update">
+      Add support for namespaced XML elements to the JXPath based input
+      modules (includes JXPathMetaModule, XMLFileModule, and others).
+    </action>
+    <action dev="AG" type="fix" fixes-bug="34325" due-to="Joachim Breitsprecher" due-to-email="jb@dserv.net">
       XInclude transformer does not handle fallback correctly.
     </action>
     <action dev="VG" type="update">



Mime
View raw message