You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Mala Ramakrishnan <ma...@speedtrak.com> on 2000/11/09 21:00:19 UTC

URLProducer: Redirecting Servlet generated pages to Cocoon

Hi,

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:

http://www.myserver.com/apage.xml?producer=URLProducer&xmlSource=http://www.client.com/tablevalues?table_name=client_table

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

Thanks,

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

             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
             xmlSource.

             For example, in my setup, I call:

          
http://www.myserver.com/apage.xml?producer=URLProducer&xmlSource=http://www.
             client.com/tablevalues?table_name=client_table

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


package org.apache.cocoon.producer;

             import java.io.*;
             import java.net.*;
             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
             document
              * 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
            
"xmlSource=http://www.webserver.org/filename?arg1=x&arg2=y..."
              *
              * @author <a href="mailto:sbelt@velos.com">Steve Belt</a>
              *
              */

             public class URLProducer extends AbstractProducer
implements Status {


              public Reader getStream(HttpServletRequest request) throws
IOException
              {
               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.substring(j,j+9).compareTo("xmlSource")==0)
                 urlString=urlString.substring(j+10); file://expects
parameter
             ...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)
                xmlbuffer=xmlbuffer+inputLine;
               in.close();
               return new StringReader(xmlbuffer);
              }

              public String getPath(HttpServletRequest request)
              {
               return "";
              }


              public String getStatus()
              {
               return "URL Producer";
              }
             }

---- Original Message -----
             From: Wolfgang Werner <ww...@picturesafe.de>
             To: <co...@xml.apache.org>
             Sent: Monday, January 03, 2000 10:46 AM
             Subject: Redirecting JSP or Servlet generated pages to
cocoon


             > 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
redirect
             > theses generated xml pages to cocoon.
             >
             > What do I have to do? Is there an how-to or article?
             >
             > Thanks in advcance,
             >
             > Wolfgang Werner
             >

Re: URLProducer: Redirecting Servlet generated pages to Cocoon

Posted by Mala Ramakrishnan <ma...@speedtrak.com>.
Answering my own question for anybody who is as lost as I was regarding
this: apage.xml is just a dummy xml file that is used to direct cocoon
to look at the arguments of the call.

Mala
--

Mala Ramakrishnan wrote:
> 
> Hi,
> 
> 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:
> 
> http://www.myserver.com/apage.xml?producer=URLProducer&xmlSource=http://www.client.com/tablevalues?table_name=client_table
> 
> What would apage.xml be?
> I am appending the email discussion for context.
> 
> Thanks,
> 
> Mala
> ------------------- Original Message ----------------
> Its so exciting when I can contribute, rather than always asking
> questions!
> 
>              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
>              xmlSource.
> 
>              For example, in my setup, I call:
> 
> 
> http://www.myserver.com/apage.xml?producer=URLProducer&xmlSource=http://www.
>              client.com/tablevalues?table_name=client_table
> 
>              Please feel free to modify this. I am a "hobbyist"
> programmer, so I am sure
>              this could be improved.
> <begin>
> 
> package org.apache.cocoon.producer;
> 
>              import java.io.*;
>              import java.net.*;
>              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
>              document
>               * 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
> 
> "xmlSource=http://www.webserver.org/filename?arg1=x&arg2=y..."
>               *
>               * @author <a href="mailto:sbelt@velos.com">Steve Belt</a>
>               *
>               */
> 
>              public class URLProducer extends AbstractProducer
> implements Status {
> 
>               public Reader getStream(HttpServletRequest request) throws
> IOException
>               {
>                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.substring(j,j+9).compareTo("xmlSource")==0)
>                  urlString=urlString.substring(j+10); file://expects
> parameter
>              ...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)
>                 xmlbuffer=xmlbuffer+inputLine;
>                in.close();
>                return new StringReader(xmlbuffer);
>               }
> 
>               public String getPath(HttpServletRequest request)
>               {
>                return "";
>               }
> 
>               public String getStatus()
>               {
>                return "URL Producer";
>               }
>              }
> 
> ---- Original Message -----
>              From: Wolfgang Werner <ww...@picturesafe.de>
>              To: <co...@xml.apache.org>
>              Sent: Monday, January 03, 2000 10:46 AM
>              Subject: Redirecting JSP or Servlet generated pages to
> cocoon
> 
>              > 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
> redirect
>              > theses generated xml pages to cocoon.
>              >
>              > What do I have to do? Is there an how-to or article?
>              >
>              > Thanks in advcance,
>              >
>              > Wolfgang Werner
>              >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: cocoon-users-help@xml.apache.org

--