cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Steve Belt" <sb...@VELOS.COM>
Subject Re: Redirecting JSP or Servlet generated pages to cocoon
Date Mon, 03 Jan 2000 22:25:59 GMT
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.

(note: Remember to define the producer in the .conf file)

<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 <wwerner@picturesafe.de>
To: <cocoon-users@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
>
> Picture/Safe Media Data Bank GmbH
> Großer Burstah 36-38
> 20457 Hamburg
>
> eMail wwerner@picture-safe.de
> Telefon +49 (0)40 / 37 41 27 - 81
> Telefax +49 (0)40 / 37 41 27 - 99
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: cocoon-users-help@xml.apache.org

----- Original Message -----
From: Wolfgang Werner <wwerner@picturesafe.de>
To: <cocoon-users@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
>
> Picture/Safe Media Data Bank GmbH
> Großer Burstah 36-38
> 20457 Hamburg
>
> eMail wwerner@picture-safe.de
> Telefon +49 (0)40 / 37 41 27 - 81
> Telefax +49 (0)40 / 37 41 27 - 99
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: cocoon-users-help@xml.apache.org


Mime
View raw message