curcuru     01/06/28 12:23:47

  Modified:    test/java/src/org/apache/qetest/xalanj2 XalanDumper.java
  Log:
  Improve/simplify printouts of Nodes, NodeLists
  
  Revision  Changes    Path
  1.3       +69 -6     
xml-xalan/test/java/src/org/apache/qetest/xalanj2/XalanDumper.java
  
  Index: XalanDumper.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/test/java/src/org/apache/qetest/xalanj2/XalanDumper.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- XalanDumper.java  2001/05/21 22:30:28     1.2
  +++ XalanDumper.java  2001/06/28 19:23:46     1.3
  @@ -58,6 +58,8 @@
   package org.apache.qetest.xalanj2;
   import org.apache.qetest.*;
   
  +import org.w3c.dom.Attr;
  +import org.w3c.dom.Element;
   import org.w3c.dom.Node;
   import org.w3c.dom.NodeList;
   
  @@ -83,7 +85,7 @@
    * logging utilities to output our data without escaping, etc.
    * 
    * @author [EMAIL PROTECTED]
  - * @version $Id: XalanDumper.java,v 1.2 2001/05/21 22:30:28 curcuru Exp $
  + * @version $Id: XalanDumper.java,v 1.3 2001/06/28 19:23:46 curcuru Exp $
    */
   public abstract class XalanDumper 
   {
  @@ -109,8 +111,10 @@
       /** Simple output formats: a contained object.  */
       public static final int DUMP_CONTAINED = 2;
       /** Simple output formats: don't close block.  */
  -    public static final int DUMP_NOCLOSE = 3;
  +    public static final int DUMP_NOCLOSE = 4;
   
  +    /** Cheap-o recursion marker: already recursing in Nodes/NodeLists.  */
  +    public static final int DUMP_NODE_RECURSION = 16;
   
       /**
        * Return String describing an ElemTemplateElement.
  @@ -252,8 +256,43 @@
       {
           if (null == n)
               return "Node" + LBRACKET + NULL + RBRACKET;
  -        return "Node" + LBRACKET 
  -            + org.apache.xalan.trace.TracerEvent.printNode(n) + RBRACKET;
  +
  +        // Copied but modified from TracerEvent; ditch hashCode
  +        StringBuffer buf = new StringBuffer();
  +
  +        if (n instanceof Element)
  +        {
  +            buf.append(n.getNodeName());
  +
  +            Node c = n.getFirstChild();
  +
  +            while (null != c)
  +            {
  +                if (c instanceof Attr)
  +                {
  +                    buf.append(dump(c, dumpLevel | DUMP_NODE_RECURSION) + " 
");
  +                }
  +                c = c.getNextSibling();
  +            }
  +        }
  +        else
  +        {
  +            if (n instanceof Attr)
  +            {
  +                buf.append(n.getNodeName() + "=" + n.getNodeValue());
  +            }
  +            else
  +            {
  +                buf.append(n.getNodeName());
  +            }
  +        }
  +
  +            
  +        // If we're already recursing, don't bother printing out 'Node' again
  +        if (DUMP_NODE_RECURSION == (dumpLevel & DUMP_NODE_RECURSION))
  +            return LBRACKET + buf.toString() + RBRACKET;
  +        else
  +            return "Node" + LBRACKET + buf.toString() + RBRACKET;
       }
   
       /**
  @@ -266,10 +305,34 @@
       public static String dump(NodeList nl, int dumpLevel)
       {
           if (null == nl)
  -            return NULL + SEP + "NodeList";
  +            return "NodeList" + LBRACKET + NULL + RBRACKET;
  +
  +        StringBuffer buf = new StringBuffer();
  +
  +        int len = nl.getLength() - 1;
  +        int i = 0;
  +        while (i < len)
  +        {
  +            Node n = nl.item(i);
  +            if (null != n)
  +            {
  +                buf.append(dump(n, dumpLevel) + ", ");
  +            }
  +            ++i;
  +        }
  +
  +        if (i == len)
  +        {
  +            Node n = nl.item(len);
  +            if (null != n)
  +            {
  +                buf.append(dump(n, dumpLevel));
  +            }
  +        }
           return "NodeList" + LBRACKET 
  -            + org.apache.xalan.trace.TracerEvent.printNodeList(nl) + 
RBRACKET;
  +            + buf.toString() + RBRACKET;
       }
  +
   
       /**
        * Print String type of node.  
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to