You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by cz...@apache.org on 2002/09/24 13:49:21 UTC

cvs commit: xml-cocoon2/src/java/org/apache/cocoon/xml/dom DOMUtil.java

cziegeler    2002/09/24 04:49:21

  Modified:    src/java/org/apache/cocoon/xml/dom DOMUtil.java
  Log:
  Better handling of request attributes
  
  Revision  Changes    Path
  1.4       +42 -2     xml-cocoon2/src/java/org/apache/cocoon/xml/dom/DOMUtil.java
  
  Index: DOMUtil.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/xml/dom/DOMUtil.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DOMUtil.java	23 Sep 2002 12:03:27 -0000	1.3
  +++ DOMUtil.java	24 Sep 2002 11:49:21 -0000	1.4
  @@ -64,6 +64,7 @@
   import java.io.*;
   import java.util.Collection;
   import java.util.Iterator;
  +import java.util.Map;
   
   /**
    *  This class is an utitity class for miscellaneous DOM functions, like
  @@ -497,7 +498,7 @@
   
       /**
        * Implementation for <code>java.util.Collection</code> :
  -     * outputs the value by calling <code>xspExpr()</code> on each element of the
  +     * outputs the value by calling {@link valueOf(Node, Object)} on each element of the
        * collection.
        *
        * @param parent The node getting the value
  @@ -515,6 +516,39 @@
        }
   
       /**
  +     * Implementation for <code>java.util.Map</code> :
  +     * For each entry an element is created with the childs key and value
  +     * Outputs the value and the key by calling {@link valueOf(Node, Object)} 
  +     * on each value and key of the Map. 
  +     *
  +     * @param parent The node getting the value
  +     * @param v      the Map
  +     */
  +    public static void valueOf(Node parent, 
  +                                 Map  v) 
  +    throws ProcessingException {
  +        if (v != null) {
  +            Iterator iterator = v.keySet().iterator();
  +            Node mapNode = parent.getOwnerDocument().createElementNS(null, "java.util.map");
  +            parent.appendChild(mapNode);
  +            while (iterator.hasNext()) {
  +                Object key = iterator.next();
  +
  +                Node entryNode = mapNode.getOwnerDocument().createElementNS(null, "entry");
  +                mapNode.appendChild(entryNode);
  +
  +                Node keyNode = entryNode.getOwnerDocument().createElementNS(null, "key");
  +                entryNode.appendChild(keyNode);
  +                valueOf(keyNode, key);
  +                
  +                Node valueNode = entryNode.getOwnerDocument().createElementNS(null, "value");
  +                entryNode.appendChild(valueNode);
  +                valueOf(valueNode, v.get(key));
  +            }
  +        }
  +     }
  +
  +    /**
        * Implementation for <code>Object</code> depending on its class :
        * <ul>
        * <li>if it's an array, call {@link valueOf(Node, Object)} on all its elements,</li>
  @@ -558,6 +592,12 @@
            // Collection
            if (v instanceof Collection) {
                valueOf(parent, (Collection)v);
  +             return;
  +         }
  +
  +         // Map
  +         if (v instanceof Map) {
  +             valueOf(parent, (Map)v);
                return;
            }
   
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org