當前位置: 首頁>>代碼示例>>Java>>正文


Java FopFactory類代碼示例

本文整理匯總了Java中org.apache.fop.apps.FopFactory的典型用法代碼示例。如果您正苦於以下問題:Java FopFactory類的具體用法?Java FopFactory怎麽用?Java FopFactory使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


FopFactory類屬於org.apache.fop.apps包,在下文中一共展示了FopFactory類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: render

import org.apache.fop.apps.FopFactory; //導入依賴的package包/類
protected void render(FopFactory fopFactory, FOUserAgent foUserAgent, String outputFormat, Source foDocumentSrc, PlaceholderReplacementHandler.PlaceholderLookup placeholderLookup, OutputStream outputStream) throws Docx4JException {
	Fop fop = null;
	Result result = null;
	try {
		if (foUserAgent==null) {
			fop = fopFactory.newFop(outputFormat, outputStream);
		} else {
			fop = fopFactory.newFop(outputFormat, foUserAgent, outputStream);				
		}
		result = (placeholderLookup == null ?
				//1 Pass
				new SAXResult(fop.getDefaultHandler()) :
				//2 Pass
				new SAXResult(new PlaceholderReplacementHandler(fop.getDefaultHandler(), placeholderLookup)));
	} catch (FOPException e) {
		throw new Docx4JException("Exception setting up result for fo transformation: " + e.getMessage(), e);
	}
	
	XmlSerializerUtil.serialize(foDocumentSrc, result, false, false);
}
 
開發者ID:plutext,項目名稱:docx4j-export-FO,代碼行數:21,代碼來源:FORendererApacheFOP.java

示例2: createFopInstance

import org.apache.fop.apps.FopFactory; //導入依賴的package包/類
/** Returns a new Fop instance. Note: FOP documentation recommends using
 * a Fop instance for one transform run only.
 * @param out The target (result) OutputStream instance
 * @param outputFormat Optional output format, defaults to "application/pdf"
 * @param foUserAgent FOUserAgent object which may contains encryption-params in render options
 * @return Fop instance
 */
public static Fop createFopInstance(OutputStream out, String outputFormat, FOUserAgent foUserAgent) throws FOPException {
    if (UtilValidate.isEmpty(outputFormat)) {
        outputFormat = MimeConstants.MIME_PDF;
    }
    if (UtilValidate.isEmpty(foUserAgent)) {
        FopFactory fopFactory = getFactoryInstance();
        foUserAgent = fopFactory.newFOUserAgent();
    }
    Fop fop;
    if (out != null) {
        fop = fopFactory.newFop(outputFormat, foUserAgent, out);
    } else {
        fop = fopFactory.newFop(outputFormat, foUserAgent);
    }
    return fop;
}
 
開發者ID:ilscipio,項目名稱:scipio-erp,代碼行數:24,代碼來源:ApacheFopWorker.java

示例3: export

import org.apache.fop.apps.FopFactory; //導入依賴的package包/類
public void export(OutputStream out) throws FOPException, IOException, TransformerException {
    FopFactory fopFactory = FopFactory.newInstance(new File(".").toURI());

    Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, out);

    // Setup XSLT
    TransformerFactory Factory = TransformerFactory.newInstance();
    Transformer transformer = Factory.newTransformer(xsltSource);

    // Set the value of a <param> in the stylesheet
    transformer.setParameter("versionParam", "2.0");

    // Setup input for XSLT transformation
    Reader reader = composeXml();
    Source src = new StreamSource(reader);

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

    // Start XSLT transformation and FOP processing
    transformer.transform(src, res);

    reader.close();
    out.flush();
}
 
開發者ID:ManyDesigns,項目名稱:Portofino,代碼行數:27,代碼來源:FormPdfExporter.java

示例4: render

import org.apache.fop.apps.FopFactory; //導入依賴的package包/類
/**
 * <p>render</p>
 *
 * @param in a {@link java.io.Reader} object.
 * @param out a {@link java.io.OutputStream} object.
 * @param xslt a {@link java.io.Reader} object.
 * @throws org.opennms.reporting.availability.render.ReportRenderException if any.
 */
public void render(Reader in, OutputStream out, Reader xslt) throws ReportRenderException {
    try {

        FopFactory fopFactory = FopFactory.newInstance();
        fopFactory.setStrictValidation(false);
        Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, out);

        TransformerFactory tfact = TransformerFactory.newInstance();
        Transformer transformer = tfact.newTransformer(new StreamSource(xslt));
        transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
        transformer.transform(new StreamSource(in), new SAXResult(fop.getDefaultHandler()));

    } catch (TransformerConfigurationException tce) {
        log.fatal("TransformerConfigurationException", tce);
        throw new ReportRenderException(tce);
    } catch (TransformerException te) {
        log.fatal("TransformerException", te);
        throw new ReportRenderException(te);
    } catch (FOPException e) {
        log.fatal("FOPException", e);
        throw new ReportRenderException(e);
    }
}
 
開發者ID:vishwaabhinav,項目名稱:OpenNMS,代碼行數:32,代碼來源:PDFReportRenderer.java

示例5: getFopFactory

import org.apache.fop.apps.FopFactory; //導入依賴的package包/類
protected  static FopFactory getFopFactory(String userConfig) throws FOPException {

		//The current implementation doesn't pass the user config to the fop factory 
		//if there is only a factory per Thread, all documents rendered in that  
		//Thread would use the configuration done for the first document.
		//For this reason disable the reuse of the FopFactories until this issue 
		//gets resolved.
		return createFopFactory(userConfig);
//		FopFactory fopFactory = fopFactories.get(Thread.currentThread().getId());
//		if (fopFactory == null) {
//			synchronized(fopFactories) {
//				fopFactory = createFopFactory(userConfig);
//				fopFactories.put(Thread.currentThread().getId(), fopFactory);
//			}
//		}
//		fopFactory.setUserConfig(userConfig);
//		return fopFactory;
	}
 
開發者ID:plutext,項目名稱:docx4j-export-FO,代碼行數:19,代碼來源:FORendererApacheFOP.java

示例6: initFopFactoryFromJar

import org.apache.fop.apps.FopFactory; //導入依賴的package包/類
public FopFactory initFopFactoryFromJar() throws IOException, SAXException, ConfigurationException {

        FopFactory fopFactory = FopFactory.newInstance();

        FOURIResolver uriResolver = (FOURIResolver) fopFactory.getURIResolver();

        if (context != null) {
            uriResolver.setCustomURIResolver(new CustomResolver(context));
        } else {
            uriResolver.setCustomURIResolver(new CustomResolver());
        }

        DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
        Configuration cfg = builder.build(getClass().getResourceAsStream("fop-pdf-thai.xml"));
        fopFactory.setUserConfig(cfg);

        return fopFactory;
    }
 
開發者ID:jampajeen,項目名稱:fop-pdf-thai,代碼行數:19,代碼來源:FopPdfThai.java

示例7: fopFactory

import org.apache.fop.apps.FopFactory; //導入依賴的package包/類
@Bean
public FopFactory fopFactory() throws Exception {
    String baseUri = propertyResolver.getProperty(PROP_BASEURI, "resources/pdf/");
    String pageHeight = propertyResolver.getProperty(PROP_PAGE_HEIGHT, "297mm");
    String pageWidth = propertyResolver.getProperty(PROP_PAGE_WIDTH, "210mm");
    Float resolution = propertyResolver.getProperty(PROP_PAGE_RESOLUTION, Float.class, 96.0f);
    Boolean strict = propertyResolver.getProperty(PROP_STRICT, Boolean.class, true);

    try {
        FopFactoryBuilder fopFactoryBuilder = new FopFactoryBuilder(new File(baseUri).toURI());
        fopFactoryBuilder = fopFactoryBuilder
            .setPageHeight(pageHeight)
            .setPageWidth(pageWidth)
            .setStrictUserConfigValidation(strict)
            .setTargetResolution(resolution)
            .setStrictFOValidation(strict);

        return fopFactoryBuilder.build();
    } catch (Exception e) {
        throw new Exception(e);
    }
}
 
開發者ID:RWTH-i5-IDSG,項目名稱:BikeMan,代碼行數:23,代碼來源:PdfConfiguration.java

示例8: export

import org.apache.fop.apps.FopFactory; //導入依賴的package包/類
public void export(OutputStream out) throws FOPException, IOException, TransformerException {
    FopFactory fopFactory = FopFactory.newInstance();

    Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, out);

    // Setup XSLT
    TransformerFactory Factory = TransformerFactory.newInstance();
    Transformer transformer = Factory.newTransformer(xsltSource);

    // Set the value of a <param> in the stylesheet
    transformer.setParameter("versionParam", "2.0");

    // Setup input for XSLT transformation
    Reader reader = composeXml();
    Source src = new StreamSource(reader);

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

    // Start XSLT transformation and FOP processing
    transformer.transform(src, res);

    reader.close();
    out.flush();
}
 
開發者ID:hongliangpan,項目名稱:manydesigns.cn,代碼行數:27,代碼來源:FormPdfExporter.java

示例9: toPDF

import org.apache.fop.apps.FopFactory; //導入依賴的package包/類
public void toPDF(OutputStream os) {
    try {
        FOUserAgent userAgent = FopFactory.newInstance().newFOUserAgent();
        Fop fop = FopFactory.newInstance().newFop(MimeConstants.MIME_PDF, userAgent, os);
        TransformerFactory factory = TransformerFactory.newInstance();
        Transformer transformer = factory.newTransformer();

        Source src = new StreamSource(new StringReader(fo));
        Result res = new SAXResult(fop.getDefaultHandler());

        transformer.transform(src, res);
    }
    catch (FOPException fope) {
        LOGGER.log(Level.SEVERE, "{0}", new Object[]{fope.getMessage()});
    }
    catch (TransformerConfigurationException tce) {
        LOGGER.log(Level.SEVERE, "{0}", new Object[]{tce.getMessage()});
    }
    catch (TransformerException te) {
        LOGGER.log(Level.SEVERE, "{0}", new Object[]{te.getMessage()});
    }
}
 
開發者ID:akullpp,項目名稱:fopdf,代碼行數:23,代碼來源:Builder.java

示例10: resolveView

import org.apache.fop.apps.FopFactory; //導入依賴的package包/類
public void resolveView(ServletRequest request, ServletResponse response, Preferences preferences, Object viewData) throws Exception {
    InputStream is = new ByteArrayInputStream(((String) viewData).getBytes("UTF-8"));
    
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    
    FopFactory fopFactory = FopFactory.newInstance();
    fopFactory.setStrictValidation(false);
    FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
    Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out);
    
    TransformerFactory tfact = TransformerFactory.newInstance();
    Transformer transformer = tfact.newTransformer();
    Source src = new StreamSource(is);
    Result res = new SAXResult(fop.getDefaultHandler());
    transformer.transform(src, res);
    
    byte[] contents = out.toByteArray();
    response.setContentLength(contents.length);
    response.getOutputStream().write(contents);

}
 
開發者ID:qoswork,項目名稱:opennmszh,代碼行數:22,代碼來源:OnmsPdfViewResolver.java

示例11: buildFontList

import org.apache.fop.apps.FopFactory; //導入依賴的package包/類
/**
 * Builds the font list from configuration.
 * @param cfg the configuration object
 * @param fontResolver a font resolver
 * @param listener the font event listener
 * @return the list of {@link EmbedFontInfo} objects
 * @throws FOPException if an error occurs while processing the configuration
 */
protected List<EmbedFontInfo> buildFontList(Configuration cfg, FontResolver fontResolver,
                FontEventListener listener) throws FOPException {
    FopFactory factory = userAgent.getFactory();
    FontManager fontManager = factory.getFontManager();
    if (fontResolver == null) {
        //Ensure that we have minimal font resolution capabilities
        fontResolver
            = FontManager.createMinimalFontResolver
                ( userAgent.isComplexScriptFeaturesEnabled() );
    }

    boolean strict = factory.validateUserConfigStrictly();

    //Read font configuration
    FontInfoConfigurator fontInfoConfigurator
        = new FontInfoConfigurator(cfg, fontManager, fontResolver, listener, strict);
    List<EmbedFontInfo> fontInfoList = new ArrayList<EmbedFontInfo>();
    fontInfoConfigurator.configure(fontInfoList);
    return fontInfoList;
}
 
開發者ID:pellcorp,項目名稱:fop,代碼行數:29,代碼來源:PrintRendererConfigurator.java

示例12: checkAll

import org.apache.fop.apps.FopFactory; //導入依賴的package包/類
/**
 * Perform all checks on the area tree and, optionally, on the intermediate format.
 * @param fopFactory the FOP factory
 * @param testFile Test case XML file
 * @param result The layout results
 * @throws TransformerException if a problem occurs in XSLT/JAXP
 */
protected void checkAll(FopFactory fopFactory, File testFile, LayoutResult result)
        throws TransformerException {
    Element testRoot = testAssistant.getTestRoot(testFile);

    NodeList nodes;
    //AT tests only when checks are available
    nodes = testRoot.getElementsByTagName("at-checks");
    if (nodes.getLength() > 0) {
        Element atChecks = (Element)nodes.item(0);
        doATChecks(atChecks, result);
    }

    //IF tests only when checks are available
    nodes = testRoot.getElementsByTagName("if-checks");
    if (nodes.getLength() > 0) {
        Element ifChecks = (Element)nodes.item(0);
        Document ifDocument = createIF(fopFactory, testFile, result.getAreaTree());
        ifTester.doIFChecks(testFile.getName(), ifChecks, ifDocument);
    }
}
 
開發者ID:pellcorp,項目名稱:fop,代碼行數:28,代碼來源:LayoutEngineTestCase.java

示例13: testDocumentHandlerLevel

import org.apache.fop.apps.FopFactory; //導入依賴的package包/類
@Test
public void testDocumentHandlerLevel() throws Exception {
    FopFactory fopFactory = FopFactory.newInstance();
    RendererFactory factory = fopFactory.getRendererFactory();
    FOUserAgent ua;
    IFDocumentHandler handler;
    IFDocumentHandler overrideHandler;

    ua = fopFactory.newFOUserAgent();
    handler = factory.createDocumentHandler(ua, MimeConstants.MIME_PDF);

    ua = fopFactory.newFOUserAgent();
    overrideHandler = new PDFDocumentHandler();
    overrideHandler.setContext(new IFContext(ua));
    ua.setDocumentHandlerOverride(overrideHandler);
    handler = factory.createDocumentHandler(ua, null);
    assertTrue(handler == overrideHandler);

    ua = fopFactory.newFOUserAgent();
    try {
        handler = factory.createDocumentHandler(ua, "invalid/format");
        fail("Expected UnsupportedOperationException");
    } catch (UnsupportedOperationException uoe) {
        //expected
    }
}
 
開發者ID:pellcorp,項目名稱:fop,代碼行數:27,代碼來源:RendererFactoryTestCase.java

示例14: readInput

import org.apache.fop.apps.FopFactory; //導入依賴的package包/類
protected void readInput(PipelineContext context, ProcessorInput input, Config config, OutputStream outputStream) {
    try {
        // Setup FOP to output PDF
        final FopFactory fopFactory = FopFactory.newInstance();
        final FOUserAgent foUserAgent = fopFactory.newFOUserAgent();

        final URL configFileUrl = this.getClass().getClassLoader().getResource("fop-userconfig.xml");
        if (configFileUrl == null) {
            logger.warn("FOP config file not found. Please put a fop-userconfig.xml file in your classpath for proper display of UTF-8 characters.");
        } else {
            final File userConfigXml = new File(configFileUrl.getFile());
            fopFactory.setUserConfig(userConfigXml);
        }

        Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, outputStream);

        // Send data to FOP
        readInputAsSAX(context, INPUT_DATA, new ForwardingXMLReceiver(fop.getDefaultHandler()));
    } catch (Exception e) {
        throw new OXFException(e);
    }
}
 
開發者ID:evlist,項目名稱:orbeon-forms,代碼行數:23,代碼來源:XSLFOSerializer.java

示例15: getFactoryInstance

import org.apache.fop.apps.FopFactory; //導入依賴的package包/類
/** Returns an instance of the FopFactory class. FOP documentation recommends
 * the reuse of the factory instance because of the startup time.
 * @return FopFactory The FopFactory instance
 */
public static FopFactory getFactoryInstance() {
    if (fopFactory == null) {
        synchronized (ApacheFopWorker.class) {
            if (fopFactory != null) {
                return fopFactory;
            }

            try {
                String ofbizHome = System.getProperty("ofbiz.home");
                File userConfigFile = FileUtil.getFile(ofbizHome + fopPath + "/fop.xconf");
                if (userConfigFile.exists()) {
                    fopFactory = FopFactory.newInstance(userConfigFile);
                } else {
                    Debug.logWarning("FOP configuration file not found: " + userConfigFile, module);
                }
                File fontBaseFile = FileUtil.getFile(ofbizHome + fopFontBaseProperty);
                if (fontBaseFile.isDirectory()) {
                    fopFactory.getFontManager().setResourceResolver(ResourceResolverFactory.createDefaultInternalResourceResolver(fontBaseFile.toURI()));
                } else {
                    Debug.logWarning("FOP font base URL not found: " + fontBaseFile, module);
                }
                Debug.logInfo("FOP FontBaseURL: " + fopFactory.getFontManager().getResourceResolver().getBaseURI(), module);
            } catch (Exception e) {
                Debug.logWarning(e, "Error reading FOP configuration: ", module);
            }
        }
    }
    return fopFactory;
}
 
開發者ID:ilscipio,項目名稱:scipio-erp,代碼行數:34,代碼來源:ApacheFopWorker.java


注:本文中的org.apache.fop.apps.FopFactory類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。