You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Matthew Smith <co...@dork.com> on 2001/03/22 21:14:21 UTC

Building Nodes with Java

    I'm hoping someone can give me a starting point for building on to my
result xml documents dynamicly.  I think that's what I want to say.  I
noticed the brief bit of information on xml fragments.  I also saw that
through xsp you have access to the result tree through the org.w3c classes.
Which should I use?  I couldn't find the API for the org.w3c classes such as
Document and Node after looking for quite a while.
    I'd really appretiate any help anyone could give me.  Links to tutorials
and documentation would be great.

Thanks,
Matt


---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>

To unsubscribe, e-mail: <co...@xml.apache.org>
For additional commands, e-mail: <co...@xml.apache.org>


Re: Building Nodes with Java

Posted by Gritsenko <vg...@acm.org>.
See also my solution, without Producer:

Brief:

I wanted to generate XML in Servlet dynamically and pass it to Cocoon
somehow
without resorting to saving this xml to file and redirecting user's browser
to URL of this file.

I have found another
(better, easier, safer? than hacking Cocoon Producer) solution.

It works!




See source code attached.

In few words:

I am a Servlet,
I generate XML document (from Value Object JavaBEan which I take from
HTTPSession) , then make a String of it,
I wrap my HTTPRequest and  my XML document as String,    into provided
CocoonServletRequest,
I instantiate CocoonEngine in myself,
I invoke 'handle' method of this engine, while passing to it :
        my cocoonized wrapped Request,
        my own Response.

The effect is that Cocoon makes my Response to output PDF.

Viktor

PS.
This article have lead me to this solution:

http://www.javaworld.com/javaworld/jw-02-2001/jw-0209-xmlj2ee.html







----- Original Message -----
From: Mike Kowalski <mk...@stewartsshops.com>
To: <co...@xml.apache.org>
Sent: Thursday, March 22, 2001 3:52 PM
Subject: Re: Building Nodes with Java


> I use producers and jdom to build xml dynamically.  Here is a link to a
tutorial
> on producers.
>
>
http://www.xmlmag.com/upload/free/features/xml/2000/04fal00/kj0004/kj0004.as
p
>
> www.jdom.org  is where to find jdom.
>
> Here is how I hook the jdom output back into the producer.  Any
suggestions on a
> better technique would be greatly appreciated.
>
> file://---- Some things you will need -----
>  private XMLOutputter fmt = new XMLOutputter();
>  private StringReader sr = null;
>  private StringWriter sw = new StringWriter();
>
> file://---- Below is the relevant snippet of code after I have created the
dynamic
> bit of XML and placed it  a jdom Element
>    Document doc = new Document(elm);
>
>    doc.addContent(CocoonHelper.getXSLTPI());
>    doc.addContent(CocoonHelper.getStyleSheetPI(stylesheet));
>
>    fmt.output( doc, sw );
>
>    return sw.toString();
>
> // the above code is then used by the producer as follows
>
> public java.io.Reader getStream(javax.servlet.http.HttpServletRequest
request) {
>
>       Inquiry inq = new Inquiry(request);
>       return new StringReader(inq.getResultXML());
>
>  }
>
> An XML string is returned and processed be the producer.
>
> I hope that helps.
>
>
> Matthew Smith wrote:
>
> >     I'm hoping someone can give me a starting point for building on to
my
> > result xml documents dynamicly.  I think that's what I want to say.  I
> > noticed the brief bit of information on xml fragments.  I also saw that
> > through xsp you have access to the result tree through the org.w3c
classes.
> > Which should I use?  I couldn't find the API for the org.w3c classes
such as
> > Document and Node after looking for quite a while.
> >     I'd really appretiate any help anyone could give me.  Links to
tutorials
> > and documentation would be great.
> >
> > Thanks,
> > Matt
> >
> > ---------------------------------------------------------------------
> > Please check that your question has not already been answered in the
> > FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>
> >
> > To unsubscribe, e-mail: <co...@xml.apache.org>
> > For additional commands, e-mail: <co...@xml.apache.org>
>
>
> ---------------------------------------------------------------------
> Please check that your question has not already been answered in the
> FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>
>
> To unsubscribe, e-mail: <co...@xml.apache.org>
> For additional commands, e-mail: <co...@xml.apache.org>
>

Re: Building Nodes with Java

Posted by Mike Kowalski <mk...@stewartsshops.com>.
I use producers and jdom to build xml dynamically.  Here is a link to a tutorial
on producers.

http://www.xmlmag.com/upload/free/features/xml/2000/04fal00/kj0004/kj0004.asp

www.jdom.org  is where to find jdom.

Here is how I hook the jdom output back into the producer.  Any suggestions on a
better technique would be greatly appreciated.

//---- Some things you will need -----
 private XMLOutputter fmt = new XMLOutputter();
 private StringReader sr = null;
 private StringWriter sw = new StringWriter();

//---- Below is the relevant snippet of code after I have created the dynamic
bit of XML and placed it  a jdom Element
   Document doc = new Document(elm);

   doc.addContent(CocoonHelper.getXSLTPI());
   doc.addContent(CocoonHelper.getStyleSheetPI(stylesheet));

   fmt.output( doc, sw );

   return sw.toString();

// the above code is then used by the producer as follows

public java.io.Reader getStream(javax.servlet.http.HttpServletRequest request) {

      Inquiry inq = new Inquiry(request);
      return new StringReader(inq.getResultXML());

 }

An XML string is returned and processed be the producer.

I hope that helps.


Matthew Smith wrote:

>     I'm hoping someone can give me a starting point for building on to my
> result xml documents dynamicly.  I think that's what I want to say.  I
> noticed the brief bit of information on xml fragments.  I also saw that
> through xsp you have access to the result tree through the org.w3c classes.
> Which should I use?  I couldn't find the API for the org.w3c classes such as
> Document and Node after looking for quite a while.
>     I'd really appretiate any help anyone could give me.  Links to tutorials
> and documentation would be great.
>
> Thanks,
> Matt
>
> ---------------------------------------------------------------------
> Please check that your question has not already been answered in the
> FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>
>
> To unsubscribe, e-mail: <co...@xml.apache.org>
> For additional commands, e-mail: <co...@xml.apache.org>


---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>

To unsubscribe, e-mail: <co...@xml.apache.org>
For additional commands, e-mail: <co...@xml.apache.org>