本文整理汇总了Java中org.apache.fop.apps.MimeConstants类的典型用法代码示例。如果您正苦于以下问题:Java MimeConstants类的具体用法?Java MimeConstants怎么用?Java MimeConstants使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MimeConstants类属于org.apache.fop.apps包,在下文中一共展示了MimeConstants类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createFopInstance
import org.apache.fop.apps.MimeConstants; //导入依赖的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;
}
示例2: export
import org.apache.fop.apps.MimeConstants; //导入依赖的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();
}
示例3: render
import org.apache.fop.apps.MimeConstants; //导入依赖的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);
}
}
示例4: export
import org.apache.fop.apps.MimeConstants; //导入依赖的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();
}
示例5: toPDF
import org.apache.fop.apps.MimeConstants; //导入依赖的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()});
}
}
示例6: resolveView
import org.apache.fop.apps.MimeConstants; //导入依赖的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);
}
示例7: testDocumentHandlerLevel
import org.apache.fop.apps.MimeConstants; //导入依赖的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
}
}
示例8: testFO2RTFWithJAXP
import org.apache.fop.apps.MimeConstants; //导入依赖的package包/类
/**
* Tests Fop with JAXP and OutputStream generating RTF.
* @throws Exception if anything fails
*/
@Test
public void testFO2RTFWithJAXP() throws Exception {
FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
File foFile = new File(getBaseDir(), "test/xml/bugtests/block.fo");
ByteArrayOutputStream baout = new ByteArrayOutputStream();
Fop fop = fopFactory.newFop(MimeConstants.MIME_RTF, foUserAgent, baout);
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(); //Identity transf.
Source src = new StreamSource(foFile);
Result res = new SAXResult(fop.getDefaultHandler());
transformer.transform(src, res);
assertTrue("Generated RTF has zero length", baout.size() > 0);
}
示例9: readInput
import org.apache.fop.apps.MimeConstants; //导入依赖的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);
}
}
示例10: render
import org.apache.fop.apps.MimeConstants; //导入依赖的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);
}
示例11: transform
import org.apache.fop.apps.MimeConstants; //导入依赖的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();
}
}
示例12: viewFO
import org.apache.fop.apps.MimeConstants; //导入依赖的package包/类
/**
* Display an FO file in the AWT Preview.
* @param fo the FO file
* @throws IOException In case of an I/O problem
* @throws FOPException In case of a problem during layout
* @throws TransformerException In case of a problem during XML processing
*/
public void viewFO(File fo)
throws IOException, FOPException, TransformerException {
//Setup FOP
Fop fop = fopFactory.newFop(MimeConstants.MIME_FOP_AWT_PREVIEW);
try {
//Load XSL-FO file (you can also do an XSL transformation here)
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer();
Source src = new StreamSource(fo);
Result res = new SAXResult(fop.getDefaultHandler());
transformer.transform(src, res);
} catch (Exception e) {
if (e instanceof FOPException) {
throw (FOPException)e;
}
throw new FOPException(e);
}
}
示例13: render
import org.apache.fop.apps.MimeConstants; //导入依赖的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);
}
示例14: render
import org.apache.fop.apps.MimeConstants; //导入依赖的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(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);
}
示例15: parsePDFOutputOption
import org.apache.fop.apps.MimeConstants; //导入依赖的package包/类
private int parsePDFOutputOption(String[] args, int i, String pdfAMode) throws FOPException {
setOutputMode(MimeConstants.MIME_PDF);
if ((i + 1 == args.length)
|| (isOption(args[i + 1]))) {
throw new FOPException("you must specify the PDF output file");
} else {
setOutputFile(args[i + 1]);
if (pdfAMode != null) {
if (renderingOptions.get("pdf-a-mode") != null) {
throw new FOPException("PDF/A mode already set");
}
renderingOptions.put("pdf-a-mode", pdfAMode);
}
return 1;
}
}