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

cvs commit: cocoon-2.1/src/scratchpad/src/org/apache/cocoon/components/jxdom DocumentAdapter.java

coliver     2003/05/02 12:49:24

  Modified:    src/scratchpad/src/org/apache/cocoon/components/jxdom
                        DocumentAdapter.java
  Log:
  handle null values as empty text nodes
  
  Revision  Changes    Path
  1.3       +23 -21    cocoon-2.1/src/scratchpad/src/org/apache/cocoon/components/jxdom/DocumentAdapter.java
  
  Index: DocumentAdapter.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/scratchpad/src/org/apache/cocoon/components/jxdom/DocumentAdapter.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DocumentAdapter.java	1 May 2003 22:52:38 -0000	1.2
  +++ DocumentAdapter.java	2 May 2003 19:49:24 -0000	1.3
  @@ -136,7 +136,7 @@
       public DocumentAdapter(Object obj, String tagName) {
           root = new ElementAdapter(this, 
                                     GET_SELF.getPointer(newContext(obj), "."),
  -                                  -1,
  +                                  -10,
                                     tagName,
                                     obj);
       }
  @@ -392,7 +392,7 @@
           Object nodeValue;
           NodeList childNodes;
           NamedNodeMap attributes;
  -        Node firstChild, lastChild, nextSibling, prevSibling;
  +        Node nextSibling, prevSibling;
   
           public Object unwrap() {
               return nodeValue;
  @@ -410,13 +410,15 @@
               super(parent, ptr);
               myIndex = index;
               this.tagName = tagName;
  +            if (nodeValue == null) {
  +                nodeValue = "";
  +            }
               this.nodeValue = nodeValue;
               if (nodeValue instanceof String ||
                   nodeValue instanceof Boolean ||
                   nodeValue instanceof Number) {
                   final TextAdapter text = new TextAdapter(this, ptr,
                                                            nodeValue);
  -                firstChild = lastChild = text;
                   childNodes = new NodeList() {
                           public int getLength() {
                               return 1;
  @@ -462,35 +464,34 @@
   
           public NodeList getChildNodes() {
               if (childNodes == null) {
  -                final Pointer parentPtr = ptr;
                   final List nodeList = new ArrayList();
  +                childNodes = new NodeList() {
  +                        public int getLength() {
  +                            return nodeList.size();
  +                       }
  +                        public Node item(int i) {
  +                            return (Node)nodeList.get(i);
  +                        }
  +                    };
                   Iterator iter = GET_CHILD_NODES.iteratePointers(getContext());
                   for (int i = 0; iter.hasNext(); i++) {
                       NodePointer p = (NodePointer)iter.next();
  -                    Object nodeValue = p.getNode();
  -                    if (nodeValue instanceof NodeAdapter) {
  -                        p = (NodePointer) ((NodeAdapter)nodeValue).ptr;
  -                        nodeValue = p.getNode();
  -                    } else if (nodeValue instanceof DocumentAdapter) {
  -                        nodeValue = ((DocumentAdapter)nodeValue).unwrap();
  +                    Object value = p.getNode();
  +                    if (value instanceof NodeAdapter) {
  +                        p = (NodePointer) ((NodeAdapter)value).ptr;
  +                        value = p.getNode();
  +                    } else if (value instanceof DocumentAdapter) {
  +                        value = ((DocumentAdapter)value).unwrap();
                       }
  -                    if (nodeValue instanceof Node) {
  -                        nodeList.add(nodeValue);
  +                    if (value instanceof Node) {
  +                        nodeList.add(value);
                       } else {
                           QName q = p.getName();
                           nodeList.add(new ElementAdapter(this, p, i, 
                                                           q.getName(),
  -                                                        nodeValue));
  +                                                        value));
                       }
                   }
  -                childNodes = new NodeList() {
  -                        public int getLength() {
  -                            return nodeList.size();
  -                       }
  -                        public Node item(int i) {
  -                            return (Node)nodeList.get(i);
  -                        }
  -                    };
               }
               return childNodes;
           }
  @@ -584,6 +585,7 @@
   
           
           public NamedNodeMap getAttributes() {
  +            if (true) return EMPTY_NODE_MAP;
               if (attributes == null) {
                   Iterator iter = GET_ATTRS.iteratePointers(getContext());
                   final List attrList = new ArrayList();