当前位置: 首页>>代码示例>>Java>>正文


Java FOUserAgent.setRendererOverride方法代码示例

本文整理汇总了Java中org.apache.fop.apps.FOUserAgent.setRendererOverride方法的典型用法代码示例。如果您正苦于以下问题:Java FOUserAgent.setRendererOverride方法的具体用法?Java FOUserAgent.setRendererOverride怎么用?Java FOUserAgent.setRendererOverride使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.fop.apps.FOUserAgent的用法示例。


在下文中一共展示了FOUserAgent.setRendererOverride方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createAreaTree

import org.apache.fop.apps.FOUserAgent; //导入方法依赖的package包/类
private Document createAreaTree(File fo, FOUserAgent ua)
            throws TransformerException, FOPException {
    DOMResult domres = new DOMResult();
    //Setup Transformer to convert the area tree to a DOM
    TransformerHandler athandler = tfactory.newTransformerHandler();
    athandler.setResult(domres);

    XMLRenderer atrenderer = new XMLRenderer(ua);
    atrenderer.setContentHandler(athandler);
    ua.setRendererOverride(atrenderer);

    Fop fop = fopFactory.newFop(ua);

    Transformer transformer = tfactory.newTransformer(); //Identity transf.
    Source src = new StreamSource(fo);
    Result res = new SAXResult(fop.getDefaultHandler());
    transformer.transform(src, res);

    Document doc = (Document)domres.getNode();
    saveAreaTreeXML(doc, new File(backupDir, fo.getName() + ".at.xml"));
    return doc;
}
 
开发者ID:pellcorp,项目名称:fop,代码行数:23,代码来源:URIResolutionTestCase.java

示例2: parseAndRenderToIntermediateFormat

import org.apache.fop.apps.FOUserAgent; //导入方法依赖的package包/类
/** {@inheritDoc} */
protected Document parseAndRenderToIntermediateFormat(Source src) throws Exception {
    AreaTreeParser parser = new AreaTreeParser();

    //Set up XMLRenderer to render to a DOM
    TransformerHandler handler = testAssistant.getTransformerFactory().newTransformerHandler();
    DOMResult domResult = new DOMResult();
    handler.setResult(domResult);
    FOUserAgent userAgent = createUserAgent();
    XMLRenderer renderer = new XMLRenderer(userAgent);
    userAgent.setRendererOverride(renderer);
    renderer.setContentHandler(handler);

    FontInfo fontInfo = new FontInfo();
    AreaTreeModel treeModel = new RenderPagesModel(userAgent,
            MimeConstants.MIME_FOP_AREA_TREE, fontInfo, null);
    parser.parse(src, treeModel, userAgent);
    treeModel.endDocument();

    return (Document)domResult.getNode();
}
 
开发者ID:pellcorp,项目名称:fop,代码行数:22,代码来源:AreaTreeParserTestCase.java

示例3: printFO

import org.apache.fop.apps.FOUserAgent; //导入方法依赖的package包/类
/**
 * Prints an FO file using JPS.
 * @param fo the FO file
 * @throws IOException In case of an I/O problem
 * @throws FOPException In case of a FOP problem
 * @throws TransformerException In case of a problem during XSLT processing
 * @throws PrintException If an error occurs while printing
 */
public void printFO(File fo)
        throws IOException, FOPException, TransformerException, PrintException {

    //Set up DocPrintJob instance
    DocPrintJob printJob = createDocPrintJob();

    //Set up a custom user agent so we can supply our own renderer instance
    FOUserAgent userAgent = fopFactory.newFOUserAgent();

    PageableRenderer renderer = new PageableRenderer(userAgent);
    userAgent.setRendererOverride(renderer);

    // Construct FOP with desired output format
    Fop fop = fopFactory.newFop(userAgent);

    // Setup JAXP using identity transformer
    TransformerFactory factory = TransformerFactory.newInstance();
    Transformer transformer = factory.newTransformer(); // identity transformer

    // Setup input stream
    Source src = new StreamSource(fo);

    // 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);

    Doc doc = new SimpleDoc(renderer, DocFlavor.SERVICE_FORMATTED.PAGEABLE, null);
    printJob.print(doc, null);
}
 
开发者ID:pellcorp,项目名称:fop,代码行数:40,代码来源:ExampleFO2JPSPrint.java

示例4: Java2DRenderer

import org.apache.fop.apps.FOUserAgent; //导入方法依赖的package包/类
/**
 * Default constructor
 *
 * @param userAgent the user agent that contains configuration details. This cannot be null.
 */
public Java2DRenderer(FOUserAgent userAgent) {
    super(userAgent);

    // MH: necessary? the caller has access to FOUserAgent
    userAgent.setRendererOverride(this); // for document regeneration

    String s = (String) userAgent.getRendererOptions().get(JAVA2D_TRANSPARENT_PAGE_BACKGROUND);
    if (s != null) {
        this.transparentPageBackground = "true".equalsIgnoreCase(s);
    }
}
 
开发者ID:pellcorp,项目名称:fop,代码行数:17,代码来源:Java2DRenderer.java

示例5: buildIntermediateDocument

import org.apache.fop.apps.FOUserAgent; //导入方法依赖的package包/类
/** {@inheritDoc} */
protected Document buildIntermediateDocument(Templates templates)
            throws Exception {
    Transformer transformer = templates.newTransformer();
    setErrorListener(transformer);

    //Set up XMLRenderer to render to a DOM
    TransformerHandler handler = testAssistant.getTransformerFactory().newTransformerHandler();
    DOMResult domResult = new DOMResult();
    handler.setResult(domResult);

    FOUserAgent userAgent = createUserAgent();

    //Create an instance of the target renderer so the XMLRenderer can use its font setup
    Renderer targetRenderer = userAgent.getRendererFactory().createRenderer(
            userAgent, getTargetMIME());

    XMLRenderer renderer = new XMLRenderer(userAgent);
    renderer.mimicRenderer(targetRenderer);
    renderer.setContentHandler(handler);

    userAgent.setRendererOverride(renderer);

    Fop fop = fopFactory.newFop(MimeConstants.MIME_FOP_AREA_TREE, userAgent);
    Result res = new SAXResult(fop.getDefaultHandler());
    transformer.transform(new DOMSource(testDoc), res);

    return (Document)domResult.getNode();
}
 
开发者ID:pellcorp,项目名称:fop,代码行数:30,代码来源:AreaTreeParserTestCase.java

示例6: convertToAreaTreeXML

import org.apache.fop.apps.FOUserAgent; //导入方法依赖的package包/类
/**
 * Converts an XSL-FO document to an area tree XML file.
 * @param src the source file
 * @param xslt the stylesheet file
 * @param areaTreeFile the target area tree XML file
 * @throws IOException In case of an I/O problem
 * @throws FOPException In case of a FOP problem
 * @throws TransformerException In case of a XSL transformation problem
 */
public void convertToAreaTreeXML(Source src, Source xslt, File areaTreeFile)
            throws IOException, FOPException, TransformerException {

    //Create a user agent
    FOUserAgent userAgent = fopFactory.newFOUserAgent();

    //Create an instance of the target renderer so the XMLRenderer can use its font setup
    Renderer targetRenderer = userAgent.getRendererFactory().createRenderer(
            userAgent, MimeConstants.MIME_PDF);

    //Create the XMLRenderer to create the area tree XML
    XMLRenderer xmlRenderer = new XMLRenderer(userAgent);

    //Tell the XMLRenderer to mimic the target renderer
    xmlRenderer.mimicRenderer(targetRenderer);

    //Make sure the prepared XMLRenderer is used
    userAgent.setRendererOverride(xmlRenderer);

    // Setup output
    OutputStream out = new java.io.FileOutputStream(areaTreeFile);
    out = new java.io.BufferedOutputStream(out);
    try {
        // Construct fop (the MIME type here is unimportant due to the override
        // on the user agent)
        Fop fop = fopFactory.newFop(null, userAgent, out);

        // Setup XSLT
        TransformerFactory factory = TransformerFactory.newInstance();
        Transformer transformer;
        if (xslt != null) {
            transformer = factory.newTransformer(xslt);
        } else {
            transformer = factory.newTransformer();
        }

        // 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);
    } finally {
        out.close();
    }
}
 
开发者ID:pellcorp,项目名称:fop,代码行数:55,代码来源:ExampleConcat.java

示例7: runTest

import org.apache.fop.apps.FOUserAgent; //导入方法依赖的package包/类
/**
 * Runs a single layout engine test case.
 * @throws TransformerException In case of an XSLT/JAXP problem
 * @throws IOException In case of an I/O problem
 * @throws SAXException In case of a problem during SAX processing
 * @throws ParserConfigurationException In case of a problem with the XML parser setup
 */
@Test
public void runTest() throws TransformerException, SAXException, IOException,
        ParserConfigurationException {

    DOMResult domres = new DOMResult();

    ElementListCollector elCollector = new ElementListCollector();
    ElementListObserver.addObserver(elCollector);

    Fop fop;
    FopFactory effFactory;
    try {
        Document testDoc = testAssistant.loadTestCase(testFile);
        effFactory = testAssistant.getFopFactory(testDoc);

        //Setup Transformer to convert the testcase XML to XSL-FO
        Transformer transformer = testAssistant.getTestcase2FOStylesheet().newTransformer();
        Source src = new DOMSource(testDoc);

        //Setup Transformer to convert the area tree to a DOM
        TransformerHandler athandler;
        athandler = testAssistant.getTransformerFactory().newTransformerHandler();
        athandler.setResult(domres);

        //Setup FOP for area tree rendering
        FOUserAgent ua = effFactory.newFOUserAgent();
        ua.setBaseURL(testFile.getParentFile().toURI().toURL().toString());
        ua.getEventBroadcaster().addEventListener(
                new ConsoleEventListenerForTests(testFile.getName(), EventSeverity.WARN));

        XMLRenderer atrenderer = new XMLRenderer(ua);
        atrenderer.setContentHandler(athandler);
        ua.setRendererOverride(atrenderer);
        fop = effFactory.newFop(ua);

        SAXResult fores = new SAXResult(fop.getDefaultHandler());
        transformer.transform(src, fores);
    } finally {
        ElementListObserver.removeObserver(elCollector);
    }

    Document doc = (Document)domres.getNode();
    if (areaTreeBackupDir != null) {
        testAssistant.saveDOM(doc,
                new File(areaTreeBackupDir, testFile.getName() + ".at.xml"));
    }
    FormattingResults results = fop.getResults();
    LayoutResult result = new LayoutResult(doc, elCollector, results);
    checkAll(effFactory, testFile, result);
}
 
开发者ID:pellcorp,项目名称:fop,代码行数:58,代码来源:LayoutEngineTestCase.java

示例8: createIF

import org.apache.fop.apps.FOUserAgent; //导入方法依赖的package包/类
private Document createIF(FopFactory fopFactory, File testFile, Document areaTreeXML)
        throws TransformerException {
    try {
        FOUserAgent ua = fopFactory.newFOUserAgent();
        ua.setBaseURL(testFile.getParentFile().toURI().toURL().toExternalForm());
        ua.getEventBroadcaster().addEventListener(
                new ConsoleEventListenerForTests(testFile.getName(), EventSeverity.WARN));

        IFRenderer ifRenderer = new IFRenderer(ua);

        IFSerializer serializer = new IFSerializer();
        serializer.setContext(new IFContext(ua));
        DOMResult result = new DOMResult();
        serializer.setResult(result);
        ifRenderer.setDocumentHandler(serializer);

        ua.setRendererOverride(ifRenderer);
        FontInfo fontInfo = new FontInfo();
        //Construct the AreaTreeModel that will received the individual pages
        final AreaTreeModel treeModel = new RenderPagesModel(ua,
                null, fontInfo, null);

        //Iterate over all intermediate files
        AreaTreeParser parser = new AreaTreeParser();
        ContentHandler handler = parser.getContentHandler(treeModel, ua);

        DelegatingContentHandler proxy = new DelegatingContentHandler() {

            public void endDocument() throws SAXException {
                super.endDocument();
                //Signal the end of the processing.
                //The renderer can finalize the target document.
                treeModel.endDocument();
            }

        };
        proxy.setDelegateContentHandler(handler);

        Transformer transformer = tfactory.newTransformer();
        transformer.transform(new DOMSource(areaTreeXML), new SAXResult(proxy));

        return (Document)result.getNode();
    } catch (Exception e) {
        throw new TransformerException(
                "Error while generating intermediate format file: " + e.getMessage(), e);
    }
}
 
开发者ID:pellcorp,项目名称:fop,代码行数:48,代码来源:LayoutEngineTestCase.java


注:本文中的org.apache.fop.apps.FOUserAgent.setRendererOverride方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。