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


Java FOPException类代码示例

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


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

示例1: render

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

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

示例7: toPDF

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

示例8: render

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

示例9: transform

import org.apache.fop.apps.FOPException; //导入依赖的package包/类
/** Transform an xsl-fo StreamSource to the specified output format.
 * @param src The xsl-fo StreamSource instance
 * @param stylesheet Optional stylesheet StreamSource instance
 * @param fop
 */
public static void transform(StreamSource src, StreamSource stylesheet, Fop fop) throws FOPException {
    Result res = new SAXResult(fop.getDefaultHandler());
    try {
        TransformerFactory factory = TransformerFactory.newInstance();
        Transformer transformer;
        if (stylesheet == null) {
            transformer = factory.newTransformer();
        } else {
            transformer = factory.newTransformer(stylesheet);
        }
        transformer.setURIResolver(new LocalResolver(transformer.getURIResolver()));
        transformer.transform(src, res);
    } catch (Exception e) {
        throw new FOPException(e);
    }
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:22,代码来源:ApacheFopWorker.java

示例10: transform

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

示例11: transform

import org.apache.fop.apps.FOPException; //导入依赖的package包/类
/** Transform an xsl-fo file to the specified file format.
 * @param srcFile The xsl-fo File instance
 * @param destFile The target (result) File instance
 * @param stylesheetFile Optional stylesheet File instance
 * @param outputFormat Optional output format, defaults to "application/pdf"
 */
public static void transform(File srcFile, File destFile, File stylesheetFile, String outputFormat) throws IOException, FOPException {
    StreamSource src = new StreamSource(srcFile);
    StreamSource stylesheet = stylesheetFile == null ? null : new StreamSource(stylesheetFile);
    BufferedOutputStream dest = new BufferedOutputStream(new FileOutputStream(destFile));
    Fop fop = createFopInstance(dest, outputFormat);
    if (fop.getUserAgent().getBaseURL() == null) {
        String baseURL = null;
        try {
            File parentFile = new File(srcFile.getAbsolutePath()).getParentFile();
            baseURL = parentFile.toURI().toURL().toExternalForm();
        } catch (Exception e) {
            baseURL = "";
        }
        fop.getUserAgent().setBaseURL(baseURL);
    }
    transform(src, stylesheet, fop);
    dest.close();
}
 
开发者ID:gildaslemoal,项目名称:elpi,代码行数:25,代码来源:ApacheFopWorker.java

示例12: parseCustomOutputOption

import org.apache.fop.apps.FOPException; //导入依赖的package包/类
private int parseCustomOutputOption(String[] args, int i) throws FOPException {
    String mime = null;
    if ((i + 1 < args.length)
            || (args[i + 1].charAt(0) != '-')) {
        mime = args[i + 1];
        if ("list".equals(mime)) {
            String[] mimes = factory.getRendererFactory().listSupportedMimeTypes();
            System.out.println("Supported MIME types:");
            for (int j = 0; j < mimes.length; j++) {
                System.out.println("  " + mimes[j]);
            }
            System.exit(0);
        }
    }
    if ((i + 2 >= args.length)
            || (isOption(args[i + 1]))
            || (isOption(args[i + 2]))) {
        throw new FOPException("you must specify the output format and the output file");
    } else {
        setOutputMode(mime);
        setOutputFile(args[i + 2]);
        return 2;
    }
}
 
开发者ID:pellcorp,项目名称:fop,代码行数:25,代码来源:CommandLineOptions.java

示例13: render

import org.apache.fop.apps.FOPException; //导入依赖的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
 */
protected void render(Source src, Transformer transformer, HttpServletResponse response)
            throws FOPException, TransformerException, IOException {

    FOUserAgent foUserAgent = getFOUserAgent();

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

    //Setup FOP
    Fop fop = fopFactory.newFop("application/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:bystrobank,项目名称:fopservlet,代码行数:36,代码来源:FopServlet.java

示例14: parseXMLInputOption

import org.apache.fop.apps.FOPException; //导入依赖的package包/类
private int parseXMLInputOption(String[] args, int i) throws FOPException {
    setInputFormat(XSLT_INPUT);
    if ((i + 1 == args.length)
            || (isOption(args[i + 1]))) {
        throw new FOPException("you must specify the input file "
                        + "for the '-xml' option");
    } else {
        String filename = args[i + 1];
        if (isSystemInOutFile(filename)) {
            this.useStdIn = true;
        } else {
            xmlfile = new File(filename);
        }
        return 1;
    }
}
 
开发者ID:pellcorp,项目名称:fop,代码行数:17,代码来源:CommandLineOptions.java

示例15: numberToTwips

import org.apache.fop.apps.FOPException; //导入依赖的package包/类
/** convert given value to twips according to given units */
private float numberToTwips(String number, String units)
        throws FOPException {
    float result = 0;

    // convert number to integer
    try {
        if (number != null && number.trim().length() > 0) {
            result = Float.valueOf(number).floatValue();
        }
    } catch (Exception e) {
        throw new FOPException("number format error: cannot convert '"
                               + number + "' to float value");
    }

    // find conversion factor
    if (units != null && units.trim().length() > 0) {
        final Float factor = (Float)TWIP_FACTORS.get(units.toLowerCase());
        if (factor == null) {
            throw new FOPException("conversion factor not found for '" + units + "' units");
        }
        result *= factor.floatValue();
    }

    return result;
}
 
开发者ID:pellcorp,项目名称:fop,代码行数:27,代码来源:FoUnitsConverter.java


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