Re: FopServlet example!

2003-02-12 Thread Ken Masters


Thank you both. I have now implemented a class that takes two strings 
(xml-source and xsl-source and the servlet-response) and the class deals 
with converting this.

If anyone would like a copy of this please let me know.

Thanks again.

Ghulam



From: J.Pietschmann [EMAIL PROTECTED]
Reply-To: [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Subject: Re: FopServlet example!
Date: Tue, 11 Feb 2003 23:44:50 +0100

Ken Masters wrote:

I am new to Apache FOP, and am finding a little problem with what I'm 
doing. The XSLTInputHandler class has two parameters, the XML and XSL 
File's. Basically what I would like to do is pass an XML as a Java String 
(since it is dynamically created) and the XSL can be passed as a File.

FAQ:
  http://xml.apache.org/fop/faq.html#faq-N102B3

J.Pietschmann


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]



_
Express yourself with cool emoticons http://messenger.msn.co.uk


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]




Re: FopServlet example!

2003-02-12 Thread Ken Masters

Hi,

Ive attached the Java class, (and included it at the bottom incase 
attachment fails to send).

There are two methods, and they both require the HttpServletResponse. It 
provides options for either sending it the XML and XSL as files or strings.

Ensure that you have copied the following jar files into your 
TOMCAT_HOME\lib directory:

* avalon-framework-cvs-20020315.jar
* batik.jar
* fop.jar

which are all found in the Apache FOP distribution.

Hope it help.

Ken



-
import javax.servlet.*;
import javax.servlet.http.*;

import java.io.*;
import javax.xml.transform.*;
import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.sax.SAXResult;

import org.apache.fop.apps.Driver;
import org.apache.fop.apps.Version;
import org.apache.fop.apps.XSLTInputHandler;
import org.apache.fop.messaging.MessageHandler;


public class ConvertToPDF
{

 private TransformerFactory xsltFact = TransformerFactory.newInstance();


   public ConvertToPDF()
   {
   //Default Constructor
   }//Constructor()



	public void convertXmlToPDF( String xmlsource, String xslsource, 
HttpServletResponse response )
	{
	  response.setContentType(application/pdf);

 try {

   Reader xmlReader = new StringReader(xmlsource);
   Reader xslReader = new StringReader(xslsource);

   Source xml = new StreamSource(xmlReader);
   Source xsl = new StreamSource(xslReader);


	Driver driver =new Driver();
	driver.setOutputStream(response.getOutputStream());
	driver.setRenderer(Driver.RENDER_PDF);

	Transformer transformer = 
TransformerFactory.newInstance().newTransformer(xsl);
	transformer.transform(xml, new SAXResult(driver.getContentHandler()));
   }//try
 catch (Exception ex) {
   ex.printStackTrace();
   }//catch

   }//convertXmlToPDF()




	public void convertXmlToPDF( String xmlsource, File xslPath, 
HttpServletResponse response )
	{
	response.setContentType(application/pdf);

 try {
   Reader xmlReader = new StringReader(xmlsource);

   Source xml = new StreamSource(xmlReader);
   Source xsl = new StreamSource(xslPath);


	Driver driver =new Driver();
	driver.setOutputStream(response.getOutputStream());
	driver.setRenderer(Driver.RENDER_PDF);

	Transformer transformer = 
TransformerFactory.newInstance().newTransformer(xsl);
	transformer.transform(xml, new SAXResult(driver.getContentHandler()));

   }//try
 catch (Exception ex) {
   ex.printStackTrace();
   }//catch

   }//convertXmlToPDF()

}//End all
-





_
Use MSN Messenger to send music and pics to your friends 
http://messenger.msn.co.uk


ConvertToPDF.java
Description: java/
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]


RE: FopServlet example!

2003-02-11 Thread Mark C. Allman
Write your own InputHandler to do what you need.  Then do the usual
driver.render() call:

Driver driver = new Driver();

InputHandler inputHandler =
new MyCustomInputHandler(..whatever your InputHandler needs..);

driver.setOutputStream(..wherever you want the output to go..);
driver.render(inputHandler.getParser(),
inputHandler.getInputSource());

-- Mark C. Allman
-- Allman Professional Consulting, Inc.
-- www.allmanpc.com, 617-947-4263


-Original Message-
From: Ken Masters [mailto:[EMAIL PROTECTED]] 
Sent: Tuesday, February 11, 2003 4:16 PM
To: [EMAIL PROTECTED]
Subject: FopServlet example!

Hi everyone,

I am new to Apache FOP, and am finding a little problem with what I'm
doing. 
The XSLTInputHandler class has two parameters, the XML and XSL File's. 
Basically what I would like to do is pass an XML as a Java String (since
it 
is dynamically created) and the XSL can be passed as a File.

How would I go about doing something like this, where the XML is created

dynamically by a Servlet (from an XML database,Apache-Xindice), and
passing 
this onto the XSLTInputHandler class (or any other class).

Thanking you in advance!

Ken



_
Overloaded with spam? With MSN 8, you can filter it out 
http://join.msn.com/?page=features/junkmailpgmarket=en-gbXAPID=32DI=1
059


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]




Re: FopServlet example!

2003-02-11 Thread J.Pietschmann
Ken Masters wrote:

I am new to Apache FOP, and am finding a little problem with what I'm 
doing. The XSLTInputHandler class has two parameters, the XML and XSL 
File's. Basically what I would like to do is pass an XML as a Java 
String (since it is dynamically created) and the XSL can be passed as a 
File.

FAQ:
  http://xml.apache.org/fop/faq.html#faq-N102B3

J.Pietschmann


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]