RE: FOP in server

2002-02-06 Thread Zahigian, Mike
Here's a simple servlet that will work.  Like the FOP servlet, you give it a
fo file or an xml/xsl combination in a get parameter.  You have to have the
latest xalan and xerces in addition to fop, because I handle the xml
transformation within the servlet as opposed to using the fop methods for
transformation.  

If you're using tomcat, your url to hit the servlet will be something like, 
http://localhost:8080/app/simple?fo=../webapps/app/xslfo/test.fo  

Make sure you're  element has a master-reference attribute
and not a master-name attribute.  This was a recent change, I guess.  Here's
the code for the simple servlet as well as a test fo document.

Mike Z

SERVLET

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import org.xml.sax.InputSource;
import org.apache.fop.apps.Driver;
import javax.xml.transform.stream.*;
import javax.xml.transform.*;

public class SimpleServlet extends HttpServlet {

private static final String FO_REQUEST_PARAM = "fo";
private static final String XML_REQUEST_PARAM = "xml";
private static final String XSL_REQUEST_PARAM = "xsl";

// you might want to override init() and set up a log4j category for the
servlet so you can easily add debugging
// code

public void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {

   try {
   // you might want to set up a constant to represent the
directory path or pull the directory path
   // from a configuration file, otherwise you have to
supply the path in the get parameter
String foParam = request.getParameter(FO_REQUEST_PARAM);
String xmlParam = request.getParameter(XML_REQUEST_PARAM);
String xslParam = request.getParameter(XSL_REQUEST_PARAM);

ByteArrayOutputStream out = new ByteArrayOutputStream();
InputSource input = null;

// set content type as pdf so browser will know it's getting pdf
content and display it properly
response.setContentType("application/pdf");

if ((request.getParameter(FO_REQUEST_PARAM)) != null) {
FileInputStream fo = new FileInputStream(foParam);
input = new InputSource(fo);
} else if(((request.getParameter(XML_REQUEST_PARAM)) != null) &&
((request.getParameter(XSL_REQUEST_PARAM)) != null)) {
File xml = new File(xmlParam);
File xsl = new File(xslParam);
Source xmlSource = new StreamSource(xml);
Source xslSource = new StreamSource(xsl);
StringWriter sw = new StringWriter();
TransformerFactory tFactory =
TransformerFactory.newInstance();
//create Templates so the xsl document will
function as a template and will be cached in
//order to optimize performance
Templates cachedXSLT =
tFactory.newTemplates(xslSource);
Transformer transformer =
cachedXSLT.newTransformer();
//transform the xml we've been given using
the cached xsl
transformer.transform(xmlSource, new
StreamResult(sw));
Reader r = new StringReader(sw.toString());
input = new InputSource(r);
} else {
// handle situation:  get parameters are not
correct
}
if (input != null) {
Driver driver = new Driver(input, out);
driver.setRenderer(Driver.RENDER_PDF);
driver.run();
}

//send content to the browser now
byte[] content = out.toByteArray();
response.setContentLength(content.length);
response.getOutputStream().write(content);
response.getOutputStream().flush();
} catch (Exception e) {
// handle exceptions.
}
}

// pass post data received to get for processing
public void doPost(HttpServletRequest request,
  HttpServletResponse
response)
throws IOException, ServletException
{
doGet(request, response);
}
}


FO
__


http://www.w3.org/1999/XSL/Format";>










John
Doe
5130
B27
2819
XPT





-Original Message-
From: Pedro Barco Bernal [mailto:[EMAIL PROTECTED]
Sent: Monday, February 04, 2002 11:20 PM
To: [EMAIL PROTECTED]
Subject: FOP in server


¿Someone have used

FOP in server don´t works

2002-02-05 Thread Pedro Barco Bernal



This class works perfectly at local. But when I try 
tu run it at server make a Exception...
 
The Exception is: File out.fo not found 

 
But the same class works perfectly at local 
!!
Can someone tell me why?? The server works 
perfectly with other class...
 

  import 
  javax.xml.transform.TransformerFactory;import 
  javax.xml.transform.Transformer;import 
  javax.xml.transform.stream.StreamSource;import 
  javax.xml.transform.stream.StreamResult;import 
  javax.xml.transform.TransformerException;import 
  javax.xml.transform.TransformerConfigurationException;
   
  import 
  org.apache.fop.apps.Driver;import 
  org.xml.sax.InputSource;
   
  import 
  java.io.FileOutputStream;/** * A Class class. * 
   * @author SADIEL */public class FOP2 extends 
  Object {
   
      
  /** * Render to PDF. OutputStream must be 
  set */    public static final 
  int RENDER_PDF = 1;
   
    /**   * 
  Constructor   */  public FOP2() {  
  try{
   
   TransformerFactory tFactory = 
  TransformerFactory.newInstance(); Transformer transformer = 
  tFactory.newTransformer(new 
  StreamSource("xsl.xsl")); transformer.transform(new 
  StreamSource("xml.xml"), new StreamResult(new 
  FileOutputStream("out.fo")));
   
    InputSource inputsource = new 
  InputSource("out.fo");
   
    FileOutputStream out = new 
  FileOutputStream("out.pdf");  Driver driver = new Driver( 
  inputsource, out);  driver.setRenderer(RENDER_PDF);  
  driver.run();
   
      }catch(Exception 
  e){  System.out.println("Excepcion");  
  System.out.println(e.toString());  }
   
    }
  }


FOP in server

2002-02-05 Thread Pedro Barco Bernal
¿Someone have used FOP in server?

We are calling FOP from Java Server Pages and the server send a ERROR
message like this:

exception sax : org.xml.sax.SAXParseException: The root element is required
in a well-formed document.
error The root element is required in a well-formed document.
ERROR: The root element is required in a well-formed document.

But when we call FOP from local there aren`t any problem!!! The document is
well-formed sure!!

Please help!!!

- Original Message -
From: "Carlos" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, February 05, 2002 1:20 AM
Subject: Problems with 0.20.3rc


> I'm trying to convert a document to PDF, having successfully done it
before
> and now get the following error:
>
> [localhost:~/docbook] carlosar% /usr/local/fop/fop.sh  webct-boot-camp.xml
> boot.fo
> [INFO]: FOP 0.20.3rc
> [INFO]: building formatting object tree
> [ERROR]: Unknown formatting object ^article
> [ERROR]: Root element must be root, not (none):article
> [localhost:~/docbook] carlosar%
>
> Any help is appreciated
> Carlos
> --
> Carlos E. Araya
> ---+ WebCT Administrator/Trainer
>  P | California Virtual Campus
>  - | C/O De Anza College
>  G | 21250 Stevens Creek Blvd
> ---+ Cupertino, CA 95014
>
> email   [EMAIL PROTECTED]
> web http://www.cvc1.org/ (work)
> http://www.silverwolf-net.net (personal)
> phone   408 257 0420 (work)
> PGP Fingerprint:E629 5DFD 7EAE 4995 E9D7  3D2F 5A9F 0CE7 DFE7 1756
>
> We cannot put off living until we are ready. The most salient
> characteristic of life is its  coerciveness: it is always urgent,  'here
and
> now' without any possible postponement. Life is  fired at us point blank.
> Jose Ortega Y Gasset
>



FOP in server

2002-02-04 Thread Pedro Barco Bernal
Can someone help us?

I want to call FOP from server. But FOP don't respond. 
There aren't any PDF file, there aren't any Exception... 

How can I execute FOP?