forrest-svn mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cdupoiri...@apache.org
Subject svn commit: r370184 - in /forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.structurer/src/java/org/apache/forrest/dispatcher: DispatcherHelper.java transformation/DispatcherTransformer.java
Date Wed, 18 Jan 2006 16:54:16 GMT
Author: cdupoirieux
Date: Wed Jan 18 08:54:10 2006
New Revision: 370184

URL: http://svn.apache.org/viewcvs?rev=370184&view=rev
Log:
Add a condition - to the XPath - on the position() of hooks in case several hooks have the
same name at the same level in the DOM. (FOR-788)

Modified:
    forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.structurer/src/java/org/apache/forrest/dispatcher/DispatcherHelper.java
    forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.structurer/src/java/org/apache/forrest/dispatcher/transformation/DispatcherTransformer.java

Modified: forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.structurer/src/java/org/apache/forrest/dispatcher/DispatcherHelper.java
URL: http://svn.apache.org/viewcvs/forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.structurer/src/java/org/apache/forrest/dispatcher/DispatcherHelper.java?rev=370184&r1=370183&r2=370184&view=diff
==============================================================================
--- forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.structurer/src/java/org/apache/forrest/dispatcher/DispatcherHelper.java
(original)
+++ forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.structurer/src/java/org/apache/forrest/dispatcher/DispatcherHelper.java
Wed Jan 18 08:54:10 2006
@@ -157,6 +157,33 @@
 
     }
 
+    /**
+     * setAttributesXPathWithPosition(Attributes attr, String path, int position) generates
an XPath with the supplied attributes
+     * and add the condition on the position() to avoid confusion with hooks using the same
name.
+     * @param attr Attributes of the XPath
+     * @param path The path
+     * @param position The position of the node
+     * @throws DOMException
+     */
+    public String setAttributesXPathWithPosition(Attributes attr, String path, int position)
+            throws DOMException {
+        String xpath = "[";
+        if (attr.getLength() > 0) {
+            for (int i = 0; i < attr.getLength(); i++) {
+                String localName = attr.getLocalName(i);
+                String value = attr.getValue(i);
+                xpath = xpath + "@" + localName + "='" + value + "'";
+                if (i < (attr.getLength() )) {
+                    xpath = xpath + " and ";
+                }
+            }
+            xpath = xpath + " position()=" + position + "]";
+            path = path + xpath;
+        }
+        return path;
+
+    }
+
     public DispatcherHelper(ServiceManager manager)
             throws ParserConfigurationException {
         this.manager = manager;

Modified: forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.structurer/src/java/org/apache/forrest/dispatcher/transformation/DispatcherTransformer.java
URL: http://svn.apache.org/viewcvs/forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.structurer/src/java/org/apache/forrest/dispatcher/transformation/DispatcherTransformer.java?rev=370184&r1=370183&r2=370184&view=diff
==============================================================================
--- forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.structurer/src/java/org/apache/forrest/dispatcher/transformation/DispatcherTransformer.java
(original)
+++ forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.structurer/src/java/org/apache/forrest/dispatcher/transformation/DispatcherTransformer.java
Wed Jan 18 08:54:10 2006
@@ -185,6 +185,8 @@
 
     private String hooksXSL;
 
+    private HashMap hooksPosition;
+
     private HashMap parameterHelper;
 
     private SourceResolver m_resolver;
@@ -274,6 +276,8 @@
         storedPrefixMap = new HashMap();
         this.parameterHelper = new HashMap();
 
+        this.hooksPosition = new HashMap();
+
         this.allowMarkup = Boolean.getBoolean(parameters.getParameter(
                 DISPATCHER_ALLOW_MARKUP, null));
         this.requestedFormat = parameters.getParameter(
@@ -391,8 +395,19 @@
         /* create a DOM node from the current sax event */
         Element currentElement = dispatcher.getDocument().createElement(name);
         dispatcherHelper.setAttributesDOM(attr, currentElement);
-        String tempPath = path + "/" + name;
-        tempPath = dispatcherHelper.setAttributesXPath(attr, tempPath);
+        String tempPathWithoutAttr = path + "/" + name;
+        String tempPath = dispatcherHelper.setAttributesXPath(attr, tempPathWithoutAttr);
+        // If the hook has already been met, we use the position in the XPath to avoid confusion
...
+        if( hooksPosition.containsKey( tempPath ) )
+        {
+          int pos = ((Integer)hooksPosition.get( tempPath )).intValue() + 1;
+          hooksPosition.put( tempPath, new Integer( pos ) );
+          tempPath = dispatcherHelper.setAttributesXPathWithPosition(attr, tempPathWithoutAttr,
pos );
+        }
+        else
+        {
+          hooksPosition.put( tempPath, new Integer( 1 ) ) ;
+        }
         if (path == null || path.equals("")) {
             path = name;
             this.rootNode.appendChild(currentElement);



Mime
View raw message