Loading ...
Sorry, an error occurred while loading the content.

Re: [XSL-FO] fop & jsp

Expand Messages
  • mustapha maalej
    hi I use this code: ****************************************************** package embedding; //Java import java.io.File; import java.io.IOException; import
    Message 1 of 4 , Mar 18, 2004
    • 0 Attachment
      hi

      I use this code:

      ******************************************************
      package embedding;

      //Java
      import java.io.File;
      import java.io.IOException;
      import java.io.OutputStream;

      //JAXP
      import javax.xml.transform.Transformer;
      import javax.xml.transform.TransformerFactory;
      import javax.xml.transform.TransformerException;
      import javax.xml.transform.Source;
      import javax.xml.transform.Result;
      import javax.xml.transform.stream.StreamSource;
      import javax.xml.transform.sax.SAXResult;

      //Avalon
      import org.apache.avalon.framework.ExceptionUtil;
      import
      org.apache.avalon.framework.logger.ConsoleLogger;
      import org.apache.avalon.framework.logger.Logger;

      //FOP
      import org.apache.fop.apps.Driver;
      import org.apache.fop.apps.FOPException;
      import org.apache.fop.messaging.MessageHandler;

      /**
      * This class demonstrates the conversion of an XML
      file to PDF using
      * JAXP (XSLT) and FOP (XSL:FO).
      */
      public class ExampleXML2PDF {

      public void convertXML2PDF(File xml, File xslt,
      File pdf)
      throws IOException, FOPException,
      TransformerException {
      //Construct driver
      Driver driver = new Driver();

      //Setup logger
      Logger logger = new
      ConsoleLogger(ConsoleLogger.LEVEL_INFO);
      driver.setLogger(logger);
      MessageHandler.setScreenLogger(logger);

      //Setup Renderer (output format)
      driver.setRenderer(Driver.RENDER_PDF);

      //Setup output
      OutputStream out = new
      java.io.FileOutputStream(pdf);
      try {
      driver.setOutputStream(out);

      //Setup XSLT
      TransformerFactory factory =
      TransformerFactory.newInstance();
      Transformer transformer =
      factory.newTransformer(new StreamSource(xslt));

      //Setup input for XSLT transformation
      Source src = new StreamSource(xml);

      //Resulting SAX events (the generated FO)
      must be piped through to FOP
      Result res = new
      SAXResult(driver.getContentHandler());

      //Start XSLT transformation and FOP
      processing
      transformer.transform(src, res);
      } finally {
      out.close();
      }
      }


      public static void main(String[] args) {
      try {
      System.out.println("FOP ExampleXML2PDF ");
      System.out.println("Preparing...");

      //Setup directories
      File baseDir = new File(".");
      File outDir = new File(baseDir, "out");
      outDir.mkdirs();

      //Setup input and output files
      File xmlfile = new File(baseDir,
      "xml/xml/projectteam.xml");
      File xsltfile = new File(baseDir,
      "xml/xslt/projectteam2FO.xsl");
      File pdffile = new File(outDir,
      "ResultXML2PDF.pdf");

      System.out.println("Input: XML (" +
      xmlfile + ")");
      System.out.println("Stylesheet: " +
      xsltfile);
      System.out.println("Output: PDF (" +
      pdffile + ")");
      System.out.println();
      System.out.println("Transforming...");

      ExampleXML2PDF app = new ExampleXML2PDF();
      app.convertXML2PDF(xmlfile, xsltfile,
      pdffile);

      System.out.println("Success!");
      } catch (Exception e) {

      System.err.println(ExceptionUtil.printStackTrace(e));
      System.exit(-1);
      }
      }
      }
      ******************************************************




      but with JSP i get this message :



      ******************************************************
      Location: /jsp/ordertool/order/deliveryNote.jsp
      Internal Servlet Error:

      javax.servlet.ServletException
      at
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:508)
      at
      javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
      at
      org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:405)
      at
      org.apache.tomcat.core.Handler.service(Handler.java:287)
      at
      org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
      at
      org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:812)
      at
      org.apache.tomcat.core.ContextManager.service(ContextManager.java:758)
      at
      org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:213)
      at
      org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
      at
      org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:501)
      at java.lang.Thread.run(Thread.java:484)

      Root cause:
      java.lang.NoSuchMethodError
      at
      org.apache.fop.apps.Driver.getParserClassName(Driver.java:208)
      at
      org.apache.fop.svg.SVGElementMapping.setupSVG(SVGElementMapping.java:72)
      at
      org.apache.fop.svg.SVGElementMapping.addToBuilder(SVGElementMapping.java:134)
      at
      org.apache.fop.apps.Driver.addElementMapping(Driver.java:439)
      at
      org.apache.fop.apps.Driver.addElementMapping(Driver.java:450)
      at
      org.apache.fop.apps.Driver.setupDefaultMappings(Driver.java:314)
      at org.apache.fop.apps.Driver.(Driver.java:222)
      at
      com.osram.omd.common.print.ExampleXML2PDF.convertXML2PDF(ExampleXML2PDF.java:68)
      at
      jsp.ordertool.order._0002fjsp_0002fordertool_0002forder_0002fdeliveryNote_0002ejspdeliveryNote_jsp_0._jspService(_0002fjsp_0002fordertool_0002forder_0002fdeliveryNote_0002ejspdeliveryNote_jsp_0.java:98)
      at
      com.osram.omd.client.jsp.base.OMDBaseJsp.omdService(OMDBaseJsp.java:126)
      at
      com.osram.omd.client.base.OMDHttpServlet.baseService(OMDHttpServlet.java:160)
      at
      com.osram.omd.client.base.OMDHttpServlet.service(OMDHttpServlet.java:125)
      at
      javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
      at
      org.apache.jasper.servlet.JspServlet$JspCountedServlet.service(JspServlet.java:130)
      at
      javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
      at
      org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:282)
      at
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:429)
      at
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:500)
      at
      javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
      at
      org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:405)
      at
      org.apache.tomcat.core.Handler.service(Handler.java:287)
      at
      org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
      at
      org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:812)
      at
      org.apache.tomcat.core.ContextManager.service(ContextManager.java:758)
      at
      org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:213)
      at
      org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
      at
      org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:501)
      at java.lang.Thread.run(Thread.java:484)

      *******************************************************


      Thanks :)))

      Sbata




















      Yahoo! Mail : votre e-mail personnel et gratuit qui vous suit partout !
      Créez votre Yahoo! Mail sur http://fr.benefits.yahoo.com/

      Dialoguez en direct avec vos amis grâce à Yahoo! Messenger !Téléchargez Yahoo! Messenger sur http://fr.messenger.yahoo.com
    Your message has been successfully submitted and would be delivered to recipients shortly.