You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Amin <am...@imkenberg.net> on 2000/10/19 09:38:13 UTC

The Document Object Creation

Hi all,
I tried to create a new document object from scratch and manipulate it in <xsp:logic> tag as follows :

<?xml version="1.0"?>

<!-- Author: Mohammed Amin "amin@imkenberg.net" -->

<?cocoon-process type="xsp"?>
<?cocoon-process type="xslt"?>
<?xml-stylesheet href="doc1.xsl" type="text/xsl"?>

<xsp:page 
  language="java" 
  xmlns:xsp="http://www.apache.org/1999/XSP/Core">

<xsp:logic>

public Document getDoc(){
    Document doc = xspParser.createEmptyDocument();
    doc.createElement("Article");
    doc.appendChild(doc.createElement("Article_No"));
    doc.createTextNode("Hello From Amin");
    
return doc;
} 


public String PrintArt(Document doc){
    NodeList Art = doc.getElementsByTagName("Article");
    Node node = Art.item(0);
    
    NodeList Art_text = node.getChildNodes();
    node = Art_text.item(0);
   
return node.getNodeValue();
}


</xsp:logic>

<my_info>
    <p>
      <doc_text>
         <xsp:expr>PrintArt(getDoc())</xsp:expr>
      </doc_text> 
    </p>
 </my_info>
</xsp:page>


but cocoon raises the following exception :

Cocoon 1.7.4

                                              Error found handling the request.

          java.lang.NullPointerException: 
                  at _usr._local._jakarta_tomcat._webapps._ROOT._test_doc.PrintArt(_test_doc.java:42)
                  at _usr._local._jakarta_tomcat._webapps._ROOT._test_doc.populateDocument(_test_doc.java:119)
                  at org.apache.cocoon.processor.xsp.XSPPage.getDocument(XSPPage.java:96)
                  at org.apache.cocoon.processor.xsp.XSPProcessor.process(XSPProcessor.java:456)
                  at org.apache.cocoon.Engine.handle(Engine.java:305)
                  at org.apache.cocoon.Cocoon.service(Cocoon.java:167)
                  at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
                  at org.apache.tomcat.core.ServletWrapper.handleRequest(ServletWrapper.java:503)
                  at org.apache.tomcat.core.ContextManager.service(ContextManager.java:559)
                  at org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:160)
                  at org.apache.tomcat.service.TcpConnectionThread.run(SimpleTcpEndpoint.java:338)
                  at java.lang.Thread.run(Thread.java:475)



And i tried to create the document object and manipulate it using jdom classes as follows :

public org.jdom.Document getArticle(){
     
   org.jdom.Document jdoc = new  org.jdom.Document(new
   org.jdom.Element("Article").addChild     (new
   org.jdom.Element("ArticleNO").setContent("Hello Amin")));       

return jdoc;
  }


public String PrintArticle(org.jdom.Document jdoc){
    org.jdom.Element root = jdoc.getRootElement();
    String Art = root.getChild("ArticleNO").getContent();
   
return Art;
}


but cocoon raises the following exceptions :

        java.lang.Exception: XSP Java Compiler: Compilation failed for _doc1.java
        26: class _usr._local._jakarta_tomcat._webapps._ROOT._doc1 must be declared abstract. It does not define void   populateDocument(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, org.w3c.dom.Document) from class org.apache.cocoon.processor.xsp.XSPPage.
            public class _doc1 extends XSPPage {
                         ^
        42: Incompatible type for declaration. Explicit cast needed to convert org.w3c.dom.Document to org.jdom.Document.
            Document doc = xspParser.createEmptyDocument();
                     ^
        43: Method createElement(java.lang.String) not found in class org.jdom.Document.
            doc.createElement("Article");
                             ^
        44: Method createElement(java.lang.String) not found in class org.jdom.Document.
            doc.appendChild(doc.createElement("Article_No"));
                                             ^
        45: Method createTextNode(java.lang.String) not found in class org.jdom.Document.
            doc.createTextNode("Hello From Amin");
                              ^
        61: No variable ownerDocument defined in class org.jdom.Document.
            Node doc2 = (Node)doc.ownerDocument;
                                 ^
        62: Incompatible type for method. Explicit cast needed to convert org.jdom.Document to org.w3c.dom.Node.
            doc2.replaceChild(doc,doc2);
                              ^
        63: Method getElementsByTagName(java.lang.String) not found in class org.jdom.Document.
            NodeList Art = doc.getElementsByTagName("Article");
                                                   ^
        84: Incompatible type for declaration. Explicit cast needed to convert org.jdom.Document to org.w3c.dom.Node.
                Node xspCurrentNode = document;
                     ^
        96: Method createProcessingInstruction(java.lang.String, java.lang.String) not found in class org.jdom.Document.
                    document.createProcessingInstruction(
                                                        ^
        103: Method createProcessingInstruction(java.lang.String, java.lang.String) not found in class org.jdom.Document.
                    document.createProcessingInstruction(
                                                        ^
        112: Method createElement(java.lang.String) not found in class org.jdom.Document.
              document.createElement("my_info");
                                    ^
        117: Method createTextNode(java.lang.String) not found in class org.jdom.Document.
              document.createTextNode("\n    ")
                                     ^
        123: Method createElement(java.lang.String) not found in class org.jdom.Document.
              document.createElement("p");
                                    ^
        128: Method createTextNode(java.lang.String) not found in class org.jdom.Document.
              document.createTextNode("\n      ")
                                     ^
        134: Method createElement(java.lang.String) not found in class org.jdom.Document.
              document.createElement("doc_text");
                                    ^
        139: Method createTextNode(java.lang.String) not found in class org.jdom.Document.
              document.createTextNode("\n         ")
                                     ^
        143: Incompatible type for method. Explicit cast needed to convert org.jdom.Document to org.w3c.dom.Document.
                  xspExpr(PrintArt(getDoc()), document)
                                              ^
        147: Method createTextNode(java.lang.String) not found in class org.jdom.Document.
              document.createTextNode("\n      ")
                                     ^
        151: Method normalize() not found in class org.jdom.Element.
            ((Element) xspCurrentNode).normalize();
                                                ^
        155: Method createTextNode(java.lang.String) not found in class org.jdom.Document.
              document.createTextNode(" \n    ")
                                     ^
        159: Method normalize() not found in class org.jdom.Element.
            ((Element) xspCurrentNode).normalize();
                                                ^
        163: Method createTextNode(java.lang.String) not found in class org.jdom.Document.
              document.createTextNode("\n ")
                                     ^
        167: Method normalize() not found in class org.jdom.Element.
            ((Element) xspCurrentNode).normalize();
                                                ^
        Note: /usr/local/jakarta-tomcat/bin/repository/_usr/_local/_jakarta_tomcat/_webapps/_ROOT/_doc1.java uses or overrides a deprecated API.  Recompile with "-deprecation" for details.
        24 errors, 1 warning


                at org.apache.cocoon.processor.xsp.language.java.XSPJavaProcessor.compile(XSPJavaProcessor.java:159)
                at org.apache.cocoon.processor.xsp.XSPProcessor.process(XSPProcessor.java:451)
                at org.apache.cocoon.Engine.handle(Engine.java:305)
                at org.apache.cocoon.Cocoon.service(Cocoon.java:167)
                at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
                at org.apache.tomcat.core.ServletWrapper.handleRequest(ServletWrapper.java:503)
                at org.apache.tomcat.core.ContextManager.service(ContextManager.java:559)
                at org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:160)
                at org.apache.tomcat.service.TcpConnectionThread.run(SimpleTcpEndpoint.java:338)
                at java.lang.Thread.run(Thread.java:475)



??????.....The primary obstacle anonying me is that : How can i create a Document object from scratch to manipulate it ?


Thanks,
M. Amin

Re: The Document Object Creation

Posted by Ulrich Mayring <ul...@denic.de>.
Donald Ball wrote:
> 
> create a new Document object using the xspParser helper object and import
> it. however, this begs the question, why in the hell do you want to play
> with DOM directly in an XSP page? why not create and modify the XML
> elements using xsp straight up? e.g.

Well, if you receive XML fragments in the form of a java.lang.String
from another source, you have to parse and append them to the current
DOM tree.

Ulrich

-- 
Ulrich Mayring
DENIC eG, Systementwicklung

Re: The Document Object Creation

Posted by Donald Ball <ba...@webslingerZ.com>.
On Thu, 19 Oct 2000, Amin wrote:

> ??????.....The primary obstacle anonying me is that : How can i create
> a Document object from scratch to manipulate it ?

create a new Document object using the xspParser helper object and import
it. however, this begs the question, why in the hell do you want to play
with DOM directly in an XSP page? why not create and modify the XML
elements using xsp straight up? e.g.

if (test == true) {
 <my-element>true</my-element>
} else {
 <my-element>false</my-element>
}

that's what xsp is all about, man.

- donald