/** * Returns a new FopFactory instance that is configured only by the default configuration * parameters. * * @param baseURI the base URI to resolve resource URIs against * @return the requested FopFactory instance. */ public static FopFactory newInstance(URI baseURI) { return new FopFactoryBuilder(baseURI).build(); }
/** * Generate a document, given an initialized Fop object * @param userAgent the user agent * @param outputFormat the output format to generate (MIME type, see MimeConstants) * @param out the output stream to write the generated output to (may be null if not applicable) * @throws FOPException in case of an error during processing */ public void renderTo(FOUserAgent userAgent, String outputFormat, OutputStream out) throws FOPException { String baseURL = null; try { baseURL = new File(sourcefile.getAbsolutePath()) .getParentFile().toURI().toURL().toExternalForm(); } catch (Exception e) { baseURL = ""; } FopFactory factory = new FopFactoryBuilder(URI.create(baseURL)) .build(); Fop fop; if (out != null) { fop = factory.newFop(outputFormat, userAgent, out); } else { fop = factory.newFop(outputFormat, userAgent); } // Resulting SAX events (the generated FO) must be piped through to FOP Result res = new SAXResult(fop.getDefaultHandler()); transformTo(res); }
/** * {@inheritDoc} */ public void init() throws ServletException { this.uriResolver = new ServletContextURIResolver(getServletContext()); this.transFactory = TransformerFactory.newInstance(); transFactory.setAttribute("http://javax.xml.XMLConstants/property/accessExternalDTD", ""); transFactory.setAttribute("http://javax.xml.XMLConstants/property/accessExternalStylesheet", ""); this.transFactory.setURIResolver(this.uriResolver); //Configure FopFactory as desired // TODO: Double check this behaves properly!! ResourceResolver resolver = new ResourceResolver() { public OutputStream getOutputStream(URI uri) throws IOException { URL url = getServletContext().getResource(uri.toASCIIString()); return url.openConnection().getOutputStream(); } public Resource getResource(URI uri) throws IOException { return new Resource(getServletContext().getResourceAsStream(uri.toASCIIString())); } }; FopFactoryBuilder builder = new FopFactoryBuilder(new File(".").toURI(), resolver); configureFopFactory(builder); fopFactory = builder.build(); }
FopFactory fopFactory = new FopFactoryBuilder(baseURI).setConfiguration(cfg) .build(); final String mimeType = Constants.APPLICATION_PDF;
public FopConfParser(InputStream fopConfStream, URI baseURI, EnvironmentProfile enviro) throws SAXException, IOException { DefaultConfigurationBuilder cfgBuilder = new DefaultConfigurationBuilder(); Configuration cfg; try { cfg = cfgBuilder.build(fopConfStream); } catch (ConfigurationException e) { throw new FOPException(e); } // The default base URI is taken from the directory in which the fopConf resides fopFactoryBuilder = new FopFactoryBuilder(enviro).setConfiguration(cfg); configure(baseURI, enviro.getResourceResolver(), cfg); }
FopFactoryBuilder fopFactoryBuilder; if (userConfigFile == null) { fopFactoryBuilder = new FopFactoryBuilder(baseURI); fopFactoryBuilder.setStrictFOValidation(strictValidation); fopFactoryBuilder.setTargetResolution(targetResolution);