Hi 
I am able to run the fo from command line and get the printed output.
Now the next is to embed in servlet.
I tried running this servlet from jbuilder.
with the library pointing to fop.jar,xalan.jar xcerces.jar , batik.jar,
buildtools.jar
I run into following error.

javax.xml.transform.TransformerConfigurationException: Namespace not
supported by SAXParser


import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import org.apache.fop.apps.*;
import org.xml.sax.*;
import javax.xml.transform.*;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.stream.StreamResult;


public class fotest extends HttpServlet {
  
  /**Initialize global variables*/
  public void init() throws ServletException {
  }
  /**Process the HTTP Get request*/
  public void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {

try{
    XMLReader xmlreader =createParser();

    Writer writer = new StringWriter();

    // Get an xslt processor factory
    TransformerFactory tFactory = TransformerFactory.newInstance();

    File xmlfile = new File("d:\\temp\\Footnotes.xml");
    Source xmlSource  = new StreamSource(xmlfile);
    File xslfile = new File("d:\\temp\\Footnotes.xsl");
    Source xslSheet  = new StreamSource(xslfile);
    StreamResult xmlResult = new StreamResult(writer);

    Transformer transformer = tFactory.newTransformer(xslSheet);

    // Perform the transformation.
    transformer.transform(xmlSource, xmlResult);


    // send output from xsl transformation to a string reader
    // create a input source containing the xsl:fo file which can be fed to
    //Fop
    Reader reader = new StringReader(writer.toString());
    writer.flush();
    writer.close();

    //set Driver methods to start Fop processing
    Driver driver = new Driver();

    driver.setRenderer("org.apache.fop.render.pdf.PDFRenderer",".14");
    driver.addElementMapping("org.apache.fop.fo.StandardElementMapping");
    driver.addElementMapping("org.apache.fop.svg.SVGElementMapping");
    driver.addPropertyList("org.apache.fop.fo.StandardPropertyListMapping");
    driver.addPropertyList("org.apache.fop.svg.SVGPropertyListMapping");

    // send pdf writer output to a byte array stream
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintWriter printWriter = new PrintWriter(baos);
    //driver.setWriter(printWriter);
    driver.setOutputStream(baos);
    driver.buildFOTree(xmlreader, new InputSource(reader));
    driver.format();
    driver.render();

    // send the bytes out to the servlet output stream
    response.setContentType("application/pdf");
    response.setContentLength(baos.size());

    long sixty = System.currentTimeMillis() + 60*1000;
    response.setDateHeader("Expires", sixty);
    baos.writeTo(response.getOutputStream());
    response.getOutputStream().flush();
    }
    catch (Exception e) {
            System.out.println(e);
        }


  }

 /**
       * creates a SAX parser, using the value of org.xml.sax.parser
       * defaulting to org.apache.xerces.parsers.SAXParser
       *
       * @return the created SAX parser
       */
    static XMLReader createParser()
    {
     XMLReader  xmlreader = null;
        try {
         String parserClassName = System.getProperty("org.xml.sax.parser");
        if (parserClassName == null) {
            parserClassName = "org.apache.xerces.parsers.SAXParser";
        }
        xmlreader= (XMLReader) Class.forName(parserClassName).newInstance();

        } catch (Exception e) {
            System.out.println(e);
        }
        return xmlreader;
    }

  /**Clean up resources*/
  public void destroy() {
  }
}
-------------
Do let me know what the problem is .
Thanks in advance.
Mary

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

Reply via email to