cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r491255 - in /cocoon/trunk/core: cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/spring/configurator/impl/ cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/
Date Sat, 30 Dec 2006 17:14:48 GMT
Author: cziegeler
Date: Sat Dec 30 09:14:46 2006
New Revision: 491255

URL: http://svn.apache.org/viewvc?view=rev&rev=491255
Log:
Reduce dependencies

Modified:
    cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/spring/configurator/impl/AbstractElementParser.java
    cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/SitemapElementParser.java

Modified: cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/spring/configurator/impl/AbstractElementParser.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/spring/configurator/impl/AbstractElementParser.java?view=diff&rev=491255&r1=491254&r2=491255
==============================================================================
--- cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/spring/configurator/impl/AbstractElementParser.java
(original)
+++ cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/spring/configurator/impl/AbstractElementParser.java
Sat Dec 30 09:14:46 2006
@@ -19,6 +19,7 @@
 package org.apache.cocoon.spring.configurator.impl;
 
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 
@@ -38,6 +39,8 @@
 import org.springframework.core.io.ResourceLoader;
 import org.springframework.web.context.support.ServletContextResourcePatternResolver;
 import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
 
 /**
  * This is a base class for all bean definition parsers used in Cocoon. It
@@ -53,8 +56,8 @@
 
     /**
      * Get the value of an attribute or if the attribute is not present return
-     * the default value. For any strange reason, getAttribute() does not return
-     * null if the attribute is not present but an empty string!
+     * the default value. As Element#getAttribute(String) returns an empty string
+     * and not null, we have to check this.
      */
     protected String getAttributeValue(Element element, String attributeName, String defaultValue)
{
         String value = element.getAttribute(attributeName);
@@ -62,6 +65,21 @@
             value = defaultValue;
         }
         return value;
+    }
+
+    /**
+     * Returns all Element children of an Element that have the given local name.
+     */
+    protected Element[] getChildElements(Element element, String localName) {
+        final ArrayList elements = new ArrayList();
+        final NodeList nodeList = element.getChildNodes();
+        for (int i = 0; i < nodeList.getLength(); i++) {
+            final Node node = nodeList.item(i);
+            if (node instanceof Element && localName.equals(node.getLocalName()))
{
+                elements.add(node);
+            }
+        }
+        return (Element[])elements.toArray(new Element[elements.size()]);
     }
 
     /**

Modified: cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/SitemapElementParser.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/SitemapElementParser.java?view=diff&rev=491255&r1=491254&r2=491255
==============================================================================
--- cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/SitemapElementParser.java
(original)
+++ cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/SitemapElementParser.java
Sat Dec 30 09:14:46 2006
@@ -27,7 +27,6 @@
 import org.apache.cocoon.spring.configurator.impl.AbstractElementParser;
 import org.apache.cocoon.spring.configurator.impl.RunningModeHelper;
 import org.apache.cocoon.spring.configurator.impl.SettingsElementParser;
-import org.apache.cocoon.xml.dom.DomHelper;
 import org.springframework.beans.factory.BeanDefinitionStoreException;
 import org.springframework.beans.factory.config.BeanDefinition;
 import org.springframework.beans.factory.support.RootBeanDefinition;
@@ -45,20 +44,15 @@
  */
 public class SitemapElementParser extends AbstractElementParser {
 
-    protected Element getComponentsElement(Element rootElement) {
-        final Element componentsElement = DomHelper.getChildElement(rootElement, rootElement.getNamespaceURI(),
"components");
-        return componentsElement;
-    }
-
-    protected List getPropertyIncludes(Element componentsElement)
+    protected List getPropertyIncludes(Element childSettingsElement)
     throws Exception {
         List propertyDirs = null;
-        if ( componentsElement != null ) {
-            final Element[] propertyDirConfigs = DomHelper.getChildElements(componentsElement,
componentsElement.getNamespaceURI(), "include-properties");
+        if ( childSettingsElement != null ) {
+            final Element[] propertyDirConfigs = this.getChildElements(childSettingsElement,
"include-properties");
             if ( propertyDirConfigs != null && propertyDirConfigs.length > 0 )
{
                 propertyDirs = new ArrayList();
                 for(int i=0; i < propertyDirConfigs.length; i++) {
-                    propertyDirs.add(DomHelper.getAttribute(propertyDirConfigs[i], "dir"));
+                    propertyDirs.add(this.getAttributeValue(propertyDirConfigs[i], "dir",
null));
                 }
             }
         }
@@ -68,14 +62,15 @@
     /**
      * Get additional properties.
      */
-    protected Properties getAdditionalProperties(Element rootElement)
+    protected Properties getAdditionalProperties(Element childSettingsElement)
     throws Exception {
         Properties variables = null;
-        final Element[] properties = DomHelper.getChildElements(rootElement, rootElement.getNamespaceURI(),
"property");
+        final Element[] properties = this.getChildElements(childSettingsElement, "property");
         if ( properties != null && properties.length > 0 ) {
             variables = new Properties();
             for(int i=0; i<properties.length; i++) {
-                variables.setProperty(DomHelper.getAttribute(properties[i], "name"), DomHelper.getAttribute(properties[i],
"value"));
+                variables.setProperty(this.getAttributeValue(properties[i], "name", null),
+                                      this.getAttributeValue(properties[i], "value", null));
             }
         }
         return variables;
@@ -117,16 +112,16 @@
             }
             // search for includes
             if ( element.hasChildNodes() ) {
-                final Element[] includeElements = DomHelper.getChildElements(element, element.getNamespaceURI(),
"include-beans");
+                final Element[] includeElements = this.getChildElements(element, "include-beans");
                 if ( includeElements != null ) {
                     for(int i = 0 ; i < includeElements.length; i++ ) {
-                        final String src = DomHelper.getAttribute(includeElements[i], "src",
null);
-                        final String dir = DomHelper.getAttribute(includeElements[i], "dir",
null);
-                        final String pattern = DomHelper.getAttribute(includeElements[i],
"pattern", "*.xml");
-                        final boolean optional = DomHelper.getAttributeAsBoolean(includeElements[i],
"optional", false);
+                        final String src = this.getAttributeValue(includeElements[i], "src",
null);
+                        final String dir = this.getAttributeValue(includeElements[i], "dir",
null);
+                        final String pattern = this.getAttributeValue(includeElements[i],
"pattern", "*.xml");
+                        final boolean optional = Boolean.valueOf(this.getAttributeValue(includeElements[i],
"optional", "false")).booleanValue();
 
                         this.handleBeanInclude(parserContext, src, dir, pattern, optional);
-                        
+
                         // TODO do we really need both src/dir attributes? The
                         // quiet precedence of 'src' over 'dir' attribute is at
                         // least unclear.



Mime
View raw message