cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mala Ramakrishnan <>
Subject URLProducer: Redirecting Servlet generated pages to Cocoon
Date Thu, 09 Nov 2000 20:00:19 GMT

I found exactly what I need in one of the mails from the archive. I need
to convert the output xml of a servlet to html and to do this, an
example of a URLProducer is what I found. However, I am a bit confused
about the usage that has been explained and will be thankful if someone
can throw some light on it. The usage of the example URLProducer given
below is as follows:

What would apage.xml be? 
I am appending the email discussion for context.


------------------- Original Message ----------------
Its so exciting when I can contribute, rather than always asking

             I was tasked with the same project.

             1. I created a servlet which would take select statement
parameters, and
             return the results in .XML.
             2. Created a "URL Producer" (see docs on producers) which
would access the
             URL, get the XML, combine it with the XSL, then return HTML
to the client.

             Here is the code I used for the URL Producer

             To use it, pass the url which provides the xml source as a
parameter called

             For example, in my setup, I call:


             Please feel free to modify this. I am a "hobbyist"
programmer, so I am sure
             this could be improved.

package org.apache.cocoon.producer;

             import java.util.*;
             import javax.servlet.http.*;
             import org.apache.cocoon.*;
             import org.apache.cocoon.framework.*;

              * This class implements the producer interface in order to
produce a
              * based on a provided URL. This code was shamlessly built
upon the
             shoulders of
              * sample files created by Stefano Mazzocchi.
              * the url used is passed by parameter
              * @author <a href="">Steve Belt</a>

             public class URLProducer extends AbstractProducer
implements Status {

              public Reader getStream(HttpServletRequest request) throws
               String urlString=request.getQueryString();
               // get the URL information
               //  this must be parsed out as the "&" in any passed
parameters cause the
             url to gag
               for(int j=0;j<=urlString.length()-12; j++)
                if (
                 urlString=urlString.substring(j+10); file://expects
             ...xmlSource=http://... without surrounding quotes
               URL xmlSourceURL = new URL(urlString);
                BufferedReader in = new BufferedReader(new
             InputStreamReader(xmlSourceURL.openStream() ) );

               String inputLine;
               String xmlbuffer="";

               while( (inputLine = in.readLine() ) != null)
               return new StringReader(xmlbuffer);

              public String getPath(HttpServletRequest request)
               return "";

              public String getStatus()
               return "URL Producer";

---- Original Message -----
             From: Wolfgang Werner <>
             To: <>
             Sent: Monday, January 03, 2000 10:46 AM
             Subject: Redirecting JSP or Servlet generated pages to

             > Hi there,
             > I'm looking for infos. I need to generate XML files by
jsp files or
             > servlets (ok, basically the same), for instance becaus I
need to
             > retrieve the xml content from a database, and want to
             > theses generated xml pages to cocoon.
             > What do I have to do? Is there an how-to or article?
             > Thanks in advcance,
             > Wolfgang Werner

View raw message