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


Java FOUserAgent类代码示例

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


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

示例1: render

import org.apache.fop.apps.FOUserAgent; //导入依赖的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.FOUserAgent; //导入依赖的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: toPDF

import org.apache.fop.apps.FOUserAgent; //导入依赖的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

示例4: resolveView

import org.apache.fop.apps.FOUserAgent; //导入依赖的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

示例5: readInput

import org.apache.fop.apps.FOUserAgent; //导入依赖的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

示例6: render

import org.apache.fop.apps.FOUserAgent; //导入依赖的package包/类
/**
 * Renders an input file (XML or XSL-FO) into a PDF file. It uses the JAXP
 * transformer given to optionally transform the input document to XSL-FO.
 * The transformer may be an identity transformer in which case the input
 * must already be XSL-FO. The PDF is written to a byte array that is
 * returned as the method's result.
 * @param src Input XML or XSL-FO
 * @param transformer Transformer to use for optional transformation
 * @param response HTTP response object
 * @throws FOPException If an error occurs during the rendering of the
 * XSL-FO
 * @throws TransformerException If an error occurs during XSL
 * transformation
 * @throws IOException In case of an I/O problem
 */
public void render(Source src, Transformer transformer, HttpServletResponse response, String realpath)
            throws FOPException, TransformerException, IOException {

    FOUserAgent foUserAgent = getFOUserAgent(realpath);

    //Setup output
    ByteArrayOutputStream out = new ByteArrayOutputStream();

    //Setup FOP
    fopFactory.setBaseURL(realpath);
    Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out);


    //Make sure the XSL transformation's result is piped through to FOP
    Result res = new SAXResult(fop.getDefaultHandler());

    //Start the transformation and rendering process
    transformer.transform(src, res);

    //Return the result
    sendPDF(out.toByteArray(), response);
}
 
开发者ID:malglam,项目名称:Lester,代码行数:38,代码来源:CreatePDF.java

示例7: transform

import org.apache.fop.apps.FOUserAgent; //导入依赖的package包/类
@Override
public void transform(MCRContent input, OutputStream out) throws TransformerException, IOException {
    try {
        final FOUserAgent userAgent = fopFactory.newFOUserAgent();
        userAgent.setProducer(MessageFormat.format("MyCoRe {0} ({1})", MCRCoreVersion.getCompleteVersion(),
            userAgent.getProducer()));

        final Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, userAgent, out);
        final Source src = input.getSource();
        final Result res = new SAXResult(fop.getDefaultHandler());
        Transformer transformer = getTransformerFactory().newTransformer();
        transformer.transform(src, res);
    } catch (FOPException e) {
        throw new TransformerException(e);
    } finally {
        out.close();
    }
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:19,代码来源:MCRFoFormatterFOP.java

示例8: process

import org.apache.fop.apps.FOUserAgent; //导入依赖的package包/类
public void process(Exchange exchange) throws Exception {
    FOUserAgent userAgent = fopFactory.newFOUserAgent();
    Map<String, Object> headers = exchange.getIn().getHeaders();
    setRenderParameters(userAgent, headers);
    setEncryptionParameters(userAgent, headers);
    setUserAgentRendererOptions(userAgent, headers);

    String outputFormat = getOutputFormat(exchange);
    Source src = exchange.getIn().getBody(StreamSource.class);

    OutputStream out = transform(userAgent, outputFormat, src);
    exchange.getOut().setBody(out);

    // propagate headers
    exchange.getOut().setHeaders(headers);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:17,代码来源:FopProducer.java

示例9: 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

示例10: render

import org.apache.fop.apps.FOUserAgent; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
protected void render(Source src, Transformer transformer, HttpServletResponse response)
        throws FOPException, TransformerException, IOException {

    FOUserAgent foUserAgent = getFOUserAgent();

    //Setup FOP
    Fop fop = fopFactory.newFop(MimeConstants.MIME_FOP_PRINT, foUserAgent);

    //Make sure the XSL transformation's result is piped through to FOP
    Result res = new SAXResult(fop.getDefaultHandler());

    //Start the transformation and rendering process
    transformer.transform(src, res);

    //Return the result
    reportOK(response);
}
 
开发者ID:pellcorp,项目名称:fop,代码行数:21,代码来源:FopPrintServlet.java

示例11: convertFO

import org.apache.fop.apps.FOUserAgent; //导入依赖的package包/类
/**
 * Convert a test FO file to PDF
 * @param foFile the FO file
 * @param ua the preconfigured user agent
 * @param dumpPdfFile if true, dumps the generated PDF file to a file name (foFile).pdf
 * @return the generated PDF data
 * @throws Exception if the conversion fails
 */
protected byte[] convertFO(File foFile, FOUserAgent ua, boolean dumpPdfFile)
         throws Exception {
    ByteArrayOutputStream baout = new ByteArrayOutputStream();
    Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, ua, baout);
    Transformer transformer = tFactory.newTransformer();
    Source src = new StreamSource(foFile);
    SAXResult res = new SAXResult(fop.getDefaultHandler());
    try {
        transformer.transform(src, res);
        final byte[] result = baout.toByteArray();
        if (dumpPdfFile) {
            final File outFile = new File(foFile.getParentFile(), foFile.getName() + ".pdf");
            FileUtils.writeByteArrayToFile(outFile, result);
        }
        return result;
    } catch (TransformerException e) {
        throw extractOriginalException(e);
    }
}
 
开发者ID:pellcorp,项目名称:fop,代码行数:28,代码来源:BasePDFTest.java

示例12: RenderPagesModel

import org.apache.fop.apps.FOUserAgent; //导入依赖的package包/类
/**
 * Create a new render pages model with the given renderer.
 * @param userAgent FOUserAgent object for process
 * @param outputFormat the MIME type of the output format to use (ex. "application/pdf").
 * @param fontInfo FontInfo object
 * @param stream OutputStream
 * @throws FOPException if the renderer cannot be properly initialized
 */
public RenderPagesModel (FOUserAgent userAgent, String outputFormat,
    FontInfo fontInfo, OutputStream stream) throws FOPException {

    super();
    this.renderer = userAgent.getRendererFactory().createRenderer(
            userAgent, outputFormat);

    try {
        renderer.setupFontInfo(fontInfo);
        // check that the "any,normal,400" font exists
        if (!fontInfo.isSetupValid()) {
            throw new FOPException(
                "No default font defined by OutputConverter");
        }
        renderer.startRenderer(stream);
    } catch (IOException e) {
        throw new FOPException(e);
    }
}
 
开发者ID:pellcorp,项目名称:fop,代码行数:28,代码来源:RenderPagesModel.java

示例13: renderTo

import org.apache.fop.apps.FOUserAgent; //导入依赖的package包/类
/** {@inheritDoc} */
public void renderTo(FOUserAgent userAgent, String outputFormat, OutputStream out)
            throws FOPException {
    IFDocumentHandler documentHandler
        = userAgent.getFactory().getRendererFactory().createDocumentHandler(
                userAgent, outputFormat);
    try {
        documentHandler.setResult(new StreamResult(out));
        IFUtil.setupFonts(documentHandler);

        //Create IF parser
        IFParser parser = new IFParser();

        // Resulting SAX events are sent to the parser
        Result res = new SAXResult(parser.getContentHandler(documentHandler, userAgent));

        transformTo(res);
    } catch (IFException ife) {
        throw new FOPException(ife);
    }
}
 
开发者ID:pellcorp,项目名称:fop,代码行数:22,代码来源:IFInputHandler.java

示例14: testSVGNoSize

import org.apache.fop.apps.FOUserAgent; //导入依赖的package包/类
@Test
public void testSVGNoSize() throws Exception {
    String uri = "test/resources/images/img.svg";
    FOUserAgent userAgent = fopFactory.newFOUserAgent();

    ImageManager manager = fopFactory.getImageManager();
    ImageInfo info = manager.preloadImage(uri, userAgent.getImageSessionContext());
    assertNotNull("ImageInfo must not be null", info);
    assertEquals(MimeConstants.MIME_SVG, info.getMimeType());
    assertEquals(uri, info.getOriginalURI());
    assertEquals(100, info.getSize().getWidthPx()); //100 = default viewport size
    assertEquals(100, info.getSize().getHeightPx());
    assertEquals(userAgent.getSourceResolution(), info.getSize().getDpiHorizontal(), 0.1);
    assertEquals(100000, info.getSize().getWidthMpt());
    assertEquals(100000, info.getSize().getHeightMpt());
}
 
开发者ID:pellcorp,项目名称:fop,代码行数:17,代码来源:ImagePreloaderTestCase.java

示例15: buildDefaultJava2DBasedFontInfo

import org.apache.fop.apps.FOUserAgent; //导入依赖的package包/类
/**
 * Builds a default {@link FontInfo} object for use with output formats using the Java2D
 * font setup.
 * @param fontInfo the font info object to populate
 * @param userAgent the user agent
 * @return the populated font information object
 */
public static FontInfo buildDefaultJava2DBasedFontInfo(
        FontInfo fontInfo, FOUserAgent userAgent) {
    Java2DFontMetrics java2DFontMetrics = new Java2DFontMetrics();

    FontManager fontManager = userAgent.getFactory().getFontManager();
    FontCollection[] fontCollections = new FontCollection[] {
            new org.apache.fop.render.java2d.Base14FontCollection(java2DFontMetrics),
            new InstalledFontCollection(java2DFontMetrics)
    };

    FontInfo fi = (fontInfo != null ? fontInfo : new FontInfo());
    fi.setEventListener(new FontEventAdapter(userAgent.getEventBroadcaster()));
    fontManager.setup(fi, fontCollections);
    return fi;
}
 
开发者ID:pellcorp,项目名称:fop,代码行数:23,代码来源:Java2DUtil.java


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