coliver     2003/05/01 15:52:39

  Modified:    src/scratchpad/src/org/apache/cocoon/components/jxdom
                        DocumentAdapter.java
               src/scratchpad/src/org/apache/cocoon/generation
                        TraxGenerator.java
  Log:
  implemented hasChildNodes() in DocumentAdapter and removed duplicate call to 
setup in TraxGenerator: this stuff still doesn't work properly with Xalan but 
hopefully getting closer
  
  Revision  Changes    Path
  1.2       +264 -265  
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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DocumentAdapter.java      1 May 2003 21:53:18 -0000       1.1
  +++ DocumentAdapter.java      1 May 2003 22:52:38 -0000       1.2
  @@ -75,41 +75,41 @@
           GET_ROOT = JXPathContext.compile("/");
   
       private static NamedNodeMap EMPTY_NODE_MAP = new NamedNodeMap() {
  -         public Node getNamedItem(String name) {
  -             return null;
  -         }
  -         public Node setNamedItem(Node arg) 
  +            public Node getNamedItem(String name) {
  +                return null;
  +            }
  +            public Node setNamedItem(Node arg) 
                               throws DOMException {
  -             notSupported();
  -             return null;
  -         }
  -         public Node removeNamedItem(String name) 
  -             throws DOMException {
  -             notSupported();
  -             return null;
  -         }
  -         public Node item(int index) {
  -             return null;
  -         }
  -         public int getLength() {
  -             return 0;
  -         }
  -         public Node getNamedItemNS(String namespaceURI,
  -                                    String localName) {
  -             return null;
  -         }
  -         public Node setNamedItemNS(Node arg) 
  -             throws DOMException {
  -             notSupported();
  -             return null;
  -         }
  -         public Node removeNamedItemNS(String namespaceURI,
  -                                       String localName)
  -             throws DOMException {
  -             notSupported();
  -             return null;
  -         }
  -     };
  +                notSupported();
  +                return null;
  +            }
  +            public Node removeNamedItem(String name) 
  +                throws DOMException {
  +                notSupported();
  +                return null;
  +            }
  +            public Node item(int index) {
  +                return null;
  +            }
  +            public int getLength() {
  +                return 0;
  +            }
  +            public Node getNamedItemNS(String namespaceURI,
  +                                       String localName) {
  +                return null;
  +            }
  +            public Node setNamedItemNS(Node arg) 
  +                throws DOMException {
  +                notSupported();
  +                return null;
  +            }
  +            public Node removeNamedItemNS(String namespaceURI,
  +                                          String localName)
  +                throws DOMException {
  +                notSupported();
  +                return null;
  +            }
  +        };
   
       private static final NodeList EMPTY_NODE_LIST = new NodeList() {
               public int getLength() {
  @@ -121,21 +121,21 @@
           };
   
       private static final JXPathContextFactory jxpathContextFactory = 
  -     JXPathContextFactory.newInstance();
  +        JXPathContextFactory.newInstance();
   
       private static void notSupported() throws DOMException {
           throw new UnsupportedOperationException("Not Supported");
       }
   
       private static JXPathContext newContext(Object obj) {
  -     return jxpathContextFactory.newContext(null, obj);
  +        return jxpathContextFactory.newContext(null, obj);
       }
   
       private ElementAdapter root;
   
       public DocumentAdapter(Object obj, String tagName) {
           root = new ElementAdapter(this, 
  -                               GET_SELF.getPointer(newContext(obj), "."),
  +                                  GET_SELF.getPointer(newContext(obj), "."),
                                     -1,
                                     tagName,
                                     obj);
  @@ -177,14 +177,14 @@
               return expr.getPointer(getParentContext(), "???");
           }
   
  -     Object getValue(CompiledExpression expr) {
  +        Object getValue(CompiledExpression expr) {
               return expr.getValue(getContext());
           }
   
           abstract public String getNodeName();
   
           public String getNodeValue() {
  -         return "";
  +            return "";
           }
   
           public void setNodeValue(String nodeValue)
  @@ -230,26 +230,26 @@
                                    Node refChild)
               throws DOMException {
               notSupported();
  -         return null;
  +            return null;
           }
   
           public Node replaceChild(Node newChild, 
                                    Node oldChild)
               throws DOMException {
               notSupported();
  -         return null;
  +            return null;
           }
   
           public Node removeChild(Node oldChild)
               throws DOMException {
               notSupported();
  -         return null;
  +            return null;
           }
   
           public Node appendChild(Node newChild)
               throws DOMException {
               notSupported();
  -         return null;
  +            return null;
           }
   
           public boolean hasChildNodes() {
  @@ -258,7 +258,7 @@
   
           public Node cloneNode(boolean deep) {
               notSupported();
  -         return null;
  +            return null;
           }        
   
           public void normalize() {
  @@ -274,7 +274,7 @@
           }
   
           public String getPrefix() {
  -         return null;
  +            return null;
           }
   
           public void setPrefix(String prefix)
  @@ -294,94 +294,94 @@
   
       public class TextAdapter extends NodeAdapter implements Text {
   
  -     Object data;
  -     String strValue;
  +        Object data;
  +        String strValue;
   
  -     TextAdapter(Node parent, Pointer ptr, Object data) {
  -         super(parent, ptr);
  -         this.data = data;
  -     }
  +        TextAdapter(Node parent, Pointer ptr, Object data) {
  +            super(parent, ptr);
  +            this.data = data;
  +        }
   
           public Object unwrap() {
               return data;
           }
   
  -     public Node getParentNode() {
  -         return parent;
  -     }
  -
  -     public short getNodeType() {
  -         return TEXT_NODE;
  -     }
  -
  -     public String getNodeName() {
  -         return "#text";
  -     }
  -
  -     public String getNodeValue() {
  -         if (strValue == null) {
  -             if (data instanceof Boolean) {
  -                 if (((Boolean)data).booleanValue()) {
  -                     strValue = "true";
  -                 } else {
  -                     strValue = ""; // in XPath false is the empty string
  -                 }
  -             } else {
  -                 strValue = String.valueOf(data);
  -             }
  -         }
  -         return strValue;
  -     }
  -
  -     public String getData()
  -         throws DOMException {
  -         return getNodeValue();
  -     }
  -
  -     public void setData(String data)
  -         throws DOMException {
  -         notSupported();
  -     }
  -
  -     public int getLength() {
  -         return getData().length();
  -     }
  -
  -     public String substringData(int offset, 
  -                                 int count)
  -         throws DOMException {
  -         return getData().substring(0, count);
  -     }
  -
  -     public void appendData(String arg)
  -         throws DOMException {
  -         notSupported();
  -     }
  -
  -     public void insertData(int offset, 
  -                            String arg)
  -         throws DOMException {
  -         notSupported();
  -     }
  -
  -     public void deleteData(int offset, 
  -                            int count)
  -         throws DOMException {
  -         notSupported();
  -     }
  -
  -     public void replaceData(int offset, 
  -                             int count, 
  -                             String arg)
  -         throws DOMException {
  -         notSupported();
  -     }
  -
  -     public Text splitText(int offset)
  -         throws DOMException {
  -         notSupported();
  -         return null;
  -     }
  +        public Node getParentNode() {
  +            return parent;
  +        }
  +
  +        public short getNodeType() {
  +            return TEXT_NODE;
  +        }
  +
  +        public String getNodeName() {
  +            return "#text";
  +        }
  +
  +        public String getNodeValue() {
  +            if (strValue == null) {
  +                if (data instanceof Boolean) {
  +                    if (((Boolean)data).booleanValue()) {
  +                        strValue = "true";
  +                    } else {
  +                        strValue = ""; // in XPath false is the empty string
  +                    }
  +                } else {
  +                    strValue = String.valueOf(data);
  +                }
  +            }
  +            return strValue;
  +        }
  +
  +        public String getData()
  +            throws DOMException {
  +            return getNodeValue();
  +        }
  +
  +        public void setData(String data)
  +            throws DOMException {
  +            notSupported();
  +        }
  +
  +        public int getLength() {
  +            return getData().length();
  +        }
  +
  +        public String substringData(int offset, 
  +                                    int count)
  +            throws DOMException {
  +            return getData().substring(0, count);
  +        }
  +
  +        public void appendData(String arg)
  +            throws DOMException {
  +            notSupported();
  +        }
  +
  +        public void insertData(int offset, 
  +                               String arg)
  +            throws DOMException {
  +            notSupported();
  +        }
  +
  +        public void deleteData(int offset, 
  +                               int count)
  +            throws DOMException {
  +            notSupported();
  +        }
  +
  +        public void replaceData(int offset, 
  +                                int count, 
  +                                String arg)
  +            throws DOMException {
  +            notSupported();
  +        }
  +
  +        public Text splitText(int offset)
  +            throws DOMException {
  +            notSupported();
  +            return null;
  +        }
   
       }
   
  @@ -391,8 +391,8 @@
           String tagName;
           Object nodeValue;
           NodeList childNodes;
  -     NamedNodeMap attributes;
  -     Node firstChild, lastChild, nextSibling, prevSibling;
  +        NamedNodeMap attributes;
  +        Node firstChild, lastChild, nextSibling, prevSibling;
   
           public Object unwrap() {
               return nodeValue;
  @@ -437,57 +437,56 @@
               return parent;
           }
   
  -     public String getTagName() {
  +        public String getTagName() {
               return tagName;
  -     }
  +        }
   
           public String getNodeName() {
  -         return getTagName();
  +            return getTagName();
           }
   
           public String getLocalName() {
               return tagName;
           }
  -     
  -     public String getNodeValue() {
  +        
  +        public String getNodeValue() {
               if (ptr == null) {
                   return "";
               }
  -         return String.valueOf(nodeValue);
  -     }
  +            return String.valueOf(nodeValue);
  +        }
   
           public boolean hasChildNodes() {
               return getChildNodes().getLength() > 0;
           }
   
  -
           public NodeList getChildNodes() {
               if (childNodes == null) {
  -             final Pointer parentPtr = ptr;
  -             final List nodeList = new ArrayList();
  +                final Pointer parentPtr = ptr;
  +                final List nodeList = new ArrayList();
                   Iterator iter = 
GET_CHILD_NODES.iteratePointers(getContext());
                   for (int i = 0; iter.hasNext(); i++) {
  -                 NodePointer p = (NodePointer)iter.next();
  -                 Object nodeValue = p.getNode();
  +                    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();
                       }
  -                 if (nodeValue instanceof Node) {
  -                     nodeList.add(nodeValue);
  -                 } else {
  +                    if (nodeValue instanceof Node) {
  +                        nodeList.add(nodeValue);
  +                    } else {
                           QName q = p.getName();
  -                     nodeList.add(new ElementAdapter(this, p, i, 
  +                        nodeList.add(new ElementAdapter(this, p, i, 
                                                           q.getName(),
                                                           nodeValue));
  -                 }
  -             }
  +                    }
  +                }
                   childNodes = new NodeList() {
                           public int getLength() {
                               return nodeList.size();
  -                        }
  +                       }
                           public Node item(int i) {
                               return (Node)nodeList.get(i);
                           }
  @@ -497,28 +496,28 @@
           }
   
           public Node getFirstChild() {
  -         getChildNodes();
  -         if (childNodes.getLength() > 0) {
  -             return (Node)childNodes.item(0);
  -         }
  -         return null;
  +            getChildNodes();
  +            if (childNodes.getLength() > 0) {
  +                return (Node)childNodes.item(0);
  +            }
  +            return null;
           }
           
           public Node getLastChild() {
  -         getChildNodes();
  -         if (childNodes.getLength() > 0) {
  -             return (Node)childNodes.item(childNodes.getLength()-1);
  -         }
  -         return null;
  +            getChildNodes();
  +            if (childNodes.getLength() > 0) {
  +                return (Node)childNodes.item(childNodes.getLength()-1);
  +            }
  +            return null;
           }
           
           public Node getPreviousSibling() {
  -         if (prevSibling == null) {
  +            if (prevSibling == null) {
                   if (parent instanceof ElementAdapter) {
                       prevSibling = 
((ElementAdapter)parent).getPreviousSibling(myIndex);
                   }
  -         }
  -         return prevSibling;
  +            }
  +            return prevSibling;
           }
   
           Node getPreviousSibling(int index) {
  @@ -530,12 +529,12 @@
           }
   
           public Node getNextSibling() {
  -         if (nextSibling == null) {
  +            if (nextSibling == null) {
                   if (parent instanceof ElementAdapter) {
                       nextSibling = 
((ElementAdapter)parent).getNextSibling(myIndex);
                   }
  -         }
  -         return nextSibling;
  +            }
  +            return nextSibling;
           }
   
           Node getNextSibling(int index) {
  @@ -606,12 +605,12 @@
                           public Node setNamedItem(Node arg) 
                               throws DOMException {
                               notSupported();
  -                         return null;
  +                            return null;
                           }
                           public Node removeNamedItem(String name) 
                               throws DOMException {
                               notSupported();
  -                         return null;
  +                            return null;
                           }
                           public Node item(int index) {
                                   return (Node)attrList.get(index);
  @@ -629,113 +628,113 @@
                           public Node setNamedItemNS(Node arg) 
                               throws DOMException {
                               notSupported();
  -                         return null;
  +                            return null;
                           }
                           public Node removeNamedItemNS(String namespaceURI,
                                                         String localName)
                               throws DOMException {
                               notSupported();
  -                         return null;
  +                            return null;
                           }
                       };
               }
  -         return attributes;
  -     }
  +            return attributes;
  +        }
   
  -     public String getAttribute(String name) {
  -         Attr a = getAttributeNode(name);
  -         if (a == null) return null;
  -         return a.getValue();
  -     }
  -
  -     public void setAttribute(String name, 
  -                              String value)
  -         throws DOMException {
  -         notSupported();
  -     }
  -
  -     public void removeAttribute(String name)
  -         throws DOMException {
  -         notSupported();
  -     }
  -
  -     public Attr getAttributeNode(String name) {
  -         NamedNodeMap map = getAttributes();
  -         if (map == null) return null;
  -         return (Attr)map.getNamedItem(name);
  -     }
  -
  -     public Attr setAttributeNode(Attr newAttr)
  -         throws DOMException {
  -         notSupported();
  -         return null;
  -     }
  -
  -     public Attr removeAttributeNode(Attr oldAttr)
  -         throws DOMException {
  -         notSupported();
  -         return null;
  -     }
  -
  -     public NodeList getElementsByTagName(String name) {
  -         return EMPTY_NODE_LIST;
  -     }
  -
  -     public String getAttributeNS(String namespaceURI, 
  -                                  String localName) {
  -         Attr a = getAttributeNodeNS(namespaceURI, localName);
  -         if (a == null) return null;
  -         return a.getValue();
  -     }
  -
  -     public void setAttributeNS(String namespaceURI, 
  -                                String qualifiedName, 
  -                                String value)
  -         throws DOMException {
  -         notSupported();
  -     }
  -
  -     public void removeAttributeNS(String namespaceURI, 
  -                                   String localName)
  -         throws DOMException {
  -         notSupported();
  -     }
  -
  -     public Attr getAttributeNodeNS(String namespaceURI, 
  -                                    String localName) {
  -         NamedNodeMap map = getAttributes();
  -         if (map == null) return null;
  -         return (Attr)map.getNamedItemNS(namespaceURI, localName);
  -     }
  -
  -     public Attr setAttributeNodeNS(Attr newAttr)
  -         throws DOMException {
  -         notSupported();
  -         return null;
  -     }
  -
  -     public NodeList getElementsByTagNameNS(String namespaceURI, 
  -                                            String localName) {
  -         return EMPTY_NODE_LIST;
  -     }
  -
  -     public boolean hasAttribute(String name) {
  -         return getAttributeNode(name) != null;
  -     }
  -
  -     public boolean hasAttributeNS(String namespaceURI, 
  -                                   String localName) {
  -         return getAttributeNodeNS(namespaceURI, localName) != null;
  -     }
  +        public String getAttribute(String name) {
  +            Attr a = getAttributeNode(name);
  +            if (a == null) return null;
  +            return a.getValue();
  +        }
  +
  +        public void setAttribute(String name, 
  +                                 String value)
  +            throws DOMException {
  +            notSupported();
  +        }
  +
  +        public void removeAttribute(String name)
  +            throws DOMException {
  +            notSupported();
  +        }
  +
  +        public Attr getAttributeNode(String name) {
  +            NamedNodeMap map = getAttributes();
  +            if (map == null) return null;
  +            return (Attr)map.getNamedItem(name);
  +        }
  +
  +        public Attr setAttributeNode(Attr newAttr)
  +            throws DOMException {
  +            notSupported();
  +            return null;
  +        }
  +
  +        public Attr removeAttributeNode(Attr oldAttr)
  +            throws DOMException {
  +            notSupported();
  +            return null;
  +        }
  +
  +        public NodeList getElementsByTagName(String name) {
  +            return EMPTY_NODE_LIST;
  +        }
  +
  +        public String getAttributeNS(String namespaceURI, 
  +                                     String localName) {
  +            Attr a = getAttributeNodeNS(namespaceURI, localName);
  +            if (a == null) return null;
  +            return a.getValue();
  +        }
  +
  +        public void setAttributeNS(String namespaceURI, 
  +                                   String qualifiedName, 
  +                                   String value)
  +            throws DOMException {
  +            notSupported();
  +        }
  +
  +        public void removeAttributeNS(String namespaceURI, 
  +                                      String localName)
  +            throws DOMException {
  +            notSupported();
  +        }
  +
  +        public Attr getAttributeNodeNS(String namespaceURI, 
  +                                       String localName) {
  +            NamedNodeMap map = getAttributes();
  +            if (map == null) return null;
  +            return (Attr)map.getNamedItemNS(namespaceURI, localName);
  +        }
  +
  +        public Attr setAttributeNodeNS(Attr newAttr)
  +            throws DOMException {
  +            notSupported();
  +            return null;
  +        }
  +
  +        public NodeList getElementsByTagNameNS(String namespaceURI, 
  +                                               String localName) {
  +            return EMPTY_NODE_LIST;
  +        }
  +
  +        public boolean hasAttribute(String name) {
  +            return getAttributeNode(name) != null;
  +        }
  +
  +        public boolean hasAttributeNS(String namespaceURI, 
  +                                      String localName) {
  +            return getAttributeNodeNS(namespaceURI, localName) != null;
  +        }
   
           public boolean hasAttributes() {
               return getAttributes().getLength() > 0;
           }
  -     
  +        
       }
   
       public DocumentType getDoctype() {
  -     return null;
  +        return null;
       }
   
       public DOMImplementation getImplementation() {
  @@ -749,7 +748,7 @@
       public Element createElement(String tagName)
           throws DOMException {
           notSupported();
  -     return null;
  +        return null;
       }
   
       public DocumentFragment createDocumentFragment() {
  @@ -871,35 +870,35 @@
                                Node refChild)
           throws DOMException {
           notSupported();
  -     return null;
  +        return null;
       }
   
       public Node replaceChild(Node newChild, 
                                Node oldChild)
           throws DOMException {
           notSupported();
  -     return null;
  +        return null;
       }
   
       public Node removeChild(Node oldChild)
           throws DOMException {
           notSupported();
  -     return null;
  +        return null;
       }
   
       public Node appendChild(Node newChild)
           throws DOMException {
           notSupported();
  -     return null;
  +        return null;
       }
   
       public boolean hasChildNodes() {
  -        return false;
  +        return root.hasChildNodes();
       }
   
       public Node cloneNode(boolean deep) {
           notSupported();
  -     return null;
  +        return null;
       }        
   
       public void normalize() {
  @@ -916,7 +915,7 @@
       }
   
       public String getPrefix() {
  -     return root.getPrefix();
  +        return root.getPrefix();
       }
   
       public void setPrefix(String prefix)
  
  
  
  1.2       +21 -23    
cocoon-2.1/src/scratchpad/src/org/apache/cocoon/generation/TraxGenerator.java
  
  Index: TraxGenerator.java
  ===================================================================
  RCS file: 
/home/cvs/cocoon-2.1/src/scratchpad/src/org/apache/cocoon/generation/TraxGenerator.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TraxGenerator.java        1 May 2003 21:53:18 -0000       1.1
  +++ TraxGenerator.java        1 May 2003 22:52:39 -0000       1.2
  @@ -67,7 +67,6 @@
   import org.w3c.dom.Node;
   import org.apache.cocoon.components.jxdom.DocumentAdapter;
   import org.apache.cocoon.xml.XMLConsumer;
  -import org.apache.commons.jxpath.JXPathContext;
   import org.apache.commons.jxpath.JXPathIntrospector;
   import org.apache.commons.jxpath.JXPathBeanInfo;
   import org.apache.commons.jxpath.DynamicPropertyHandler;
  @@ -93,17 +92,17 @@
       public void setup(SourceResolver resolver, Map objectModel,
                         String src, Parameters parameters)
           throws ProcessingException, SAXException, IOException {
  -     super.setup(resolver, objectModel, src, parameters);
  +        super.setup(resolver, objectModel, src, parameters);
           // FIX ME: When we decide proper way to pass "bean" and "kont"
           Object bean = ((Environment)resolver).getAttribute("bean-dict");
           WebContinuation kont = 
  -         (WebContinuation)((Environment)resolver).getAttribute("kont");
  -     Map map = new HashMap();
  -     Request request = ObjectModelHelper.getRequest(objectModel);
  -     Response response = ObjectModelHelper.getResponse(objectModel);
  -     Context context = ObjectModelHelper.getContext(objectModel);
  +            (WebContinuation)((Environment)resolver).getAttribute("kont");
  +        Map map = new HashMap();
  +        Request request = ObjectModelHelper.getRequest(objectModel);
  +        Response response = ObjectModelHelper.getResponse(objectModel);
  +        Context context = ObjectModelHelper.getContext(objectModel);
           if (bean != null) {
  -         fillContext(bean, map);
  +            fillContext(bean, map);
               map.put("flowContext", bean);
               map.put("continuation", kont);
           }
  @@ -114,8 +113,7 @@
           if (session != null) {
               map.put("session", session);
           }
  -     doc = new DocumentAdapter(map, "document");
  -        super.setup(resolver, objectModel, src, parameters);
  +        doc = new DocumentAdapter(map, "document");
       }
   
       private void fillContext(Object contextObject, Map map) {
  @@ -132,7 +130,7 @@
                   for (int i = 0; i < result.length; i++) {
                       try {
                           map.put(result[i], 
  -                             (h.getProperty(contextObject, result[i])));
  +                                (h.getProperty(contextObject, result[i])));
                       } catch (Exception exc) {
                           exc.printStackTrace();
                       }
  @@ -158,24 +156,24 @@
   
       public void generate()
           throws IOException, SAXException, ProcessingException {
  -     DOMSource src = new DOMSource(doc);
  -     javax.xml.transform.Transformer transformer = 
  -         transformerHandler.getTransformer();
  -     SAXResult result = new SAXResult(xmlConsumer);
  -     try {
  -         transformer.transform(src, result);
  -     } catch (TransformerException exc) {
  -         throw new SAXException(exc.getMessage(), exc);
  -     }
  +        javax.xml.transform.Transformer transformer = 
  +            transformerHandler.getTransformer();
  +        DOMSource src = new DOMSource(doc);
  +        SAXResult result = new SAXResult(xmlConsumer);
  +        try {
  +            transformer.transform(src, result);
  +        } catch (TransformerException exc) {
  +            throw new SAXException(exc.getMessage(), exc);
  +        }
       }
   
       public void setConsumer(XMLConsumer consumer) {
  -     xmlConsumer = consumer;
  +        xmlConsumer = consumer;
       }
   
       public void recycle() {
  -     super.recycle();
  -     doc = null;
  +        super.recycle();
  +        doc = null;
       }
   
   }
  
  
  

Reply via email to