Hi there, I get a FOPException while processing a XSL-FO with Fop-0.20.3rc. For testing I'm transforming a xml document into xsl-fo using a xsl stylesheet, which should be transformed into a pdf (and returned). But, alas, I get a FOPException with the message "no protocol":
javax.servlet.ServletException: FOPException: no protocol: <?xml version="1.0" encoding="iso-8859-1"?> <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"> <fo:layout-master-set> ... ... ... </fo:root> The error occurs in the renderFO(..) method down below. Any suggestions? I got no idea, and the API says about FOPException "Exception thrown when FOP has a problem" - not quite helpfull. -------------- THE SERVLET ---------------------------------- // alot of imports: import ... public class DeliverPDF extends HttpServlet { public static String XSL_SOURCE_FILE = "/xml/print.xsl"; public static String XML_SOURCE_FILE = "/xml/japan.xml"; Logger log = null; public void doPost( javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException { /** * Der Logger f�r die PDF Transformation wird gesetzt. * �ber diesen werden Fehlermeldungen und Warnungen an den Benutzer * weitergegeben. */ if (log == null) { Hierarchy hierarchy = Hierarchy.getDefaultHierarchy(); log = hierarchy.getLoggerFor("fop"); log.setPriority(Priority.WARN); } String foTempString = new String(); StreamSource xmlStreamSource = null; StreamSource xslStreamSource = null; try { /** * TransformerFactory ist eine abstrakte Klasse, d.h. sie hat keinen Konstruktor. * Es wird eine neue Instanz angelegt. */ TransformerFactory tFactory = TransformerFactory.newInstance(); /** Stream Source wird jeweils mit den Dateinamen(java.io.File) initialisiert, * d.h. die SystemID wird automatisch erzeugt, �ber die die Dateien * eindeutig lokalisiert werden. * Nun kann in der Source erst mit den dateien gearbeitet werden. */ URL url = getClass().getResource(XSL_SOURCE_FILE); if (url == null) { response.getOutputStream().println("Couldn't locate " + XSL_SOURCE_FILE + "."); } else { xslStreamSource = new StreamSource(url.toString()); } url = getClass().getResource(XML_SOURCE_FILE); if (url == null) { response.getOutputStream().println("Couldn't locate " + XML_SOURCE_FILE + "."); } else { xmlStreamSource = new StreamSource(url.toString()); } /** Wenn das Anlegen der beiden StreamSources erfolgreich war, * wird die eigentliche transformation durchgef�hrt und das * Ergebnis pr�sentiert. */ if (xmlStreamSource != null && xslStreamSource != null) { /** �ber die Factory wird nun ein neuer Transformator erzeugt, * initialisiert mit der Datei, die die Anweisungen f�r die * Transformation enth�lt(XSL-Source). */ Transformer transformer = tFactory.newTransformer(xslStreamSource); /** Durchf�hren der Transformation, Ergebnis in ein File wegschreiben. */ StringWriter sw = new StringWriter(); transformer.transform( xmlStreamSource, new StreamResult(sw)); /** * Umsetzung nach PDF und rausschreiben an den Client */ renderFO(new InputSource(sw.toString()), response); } } catch (Exception e) { e.printStackTrace(); } } /** * renders an FO inputsource into a PDF file which is rendered * directly to the response object's OutputStream */ public void renderFO(InputSource foFile, HttpServletResponse response) throws ServletException { try { ByteArrayOutputStream out = new ByteArrayOutputStream(); response.setContentType("application/pdf"); Driver driver = new Driver(foFile, out); driver.setRenderer(Driver.RENDER_PDF); driver.run(); byte[] content = out.toByteArray(); response.setContentLength(content.length); response.getOutputStream().write(content); response.getOutputStream().flush(); } catch (FOPException fopE) { throw new ServletException("FOPException: " + fopE.getMessage()); } catch (IOException ioE) { throw new ServletException("IOException: " + ioE.getMessage()); } } } --------------------- END OF SERVLET --------------------------- Thanks for reading that far :) Sebastian Will ______________________________________________________________________________ Darf es ein bisschen mehr sein? Mehr Speicher, mehr Mail, mehr Erlebnis, mehr Leistung, mehr Pr�mie unter http://club.web.de/?mc=021102
