本文整理匯總了Java中org.apache.fop.apps.Fop.getDefaultHandler方法的典型用法代碼示例。如果您正苦於以下問題:Java Fop.getDefaultHandler方法的具體用法?Java Fop.getDefaultHandler怎麽用?Java Fop.getDefaultHandler使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.fop.apps.Fop
的用法示例。
在下文中一共展示了Fop.getDefaultHandler方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: render
import org.apache.fop.apps.Fop; //導入方法依賴的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);
}
示例2: export
import org.apache.fop.apps.Fop; //導入方法依賴的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: export
import org.apache.fop.apps.Fop; //導入方法依賴的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();
}
示例4: toPDF
import org.apache.fop.apps.Fop; //導入方法依賴的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()});
}
}
示例5: resolveView
import org.apache.fop.apps.Fop; //導入方法依賴的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);
}
示例6: testFO2RTFWithJAXP
import org.apache.fop.apps.Fop; //導入方法依賴的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);
}
示例7: render
import org.apache.fop.apps.Fop; //導入方法依賴的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);
}
示例8: transform
import org.apache.fop.apps.Fop; //導入方法依賴的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);
}
}
示例9: transform
import org.apache.fop.apps.Fop; //導入方法依賴的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();
}
}
示例10: createAreaTree
import org.apache.fop.apps.Fop; //導入方法依賴的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;
}
示例11: viewFO
import org.apache.fop.apps.Fop; //導入方法依賴的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);
}
}
示例12: convertFO
import org.apache.fop.apps.Fop; //導入方法依賴的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);
}
}
示例13: render
import org.apache.fop.apps.Fop; //導入方法依賴的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);
}
示例14: testFO2PSWithJAXP
import org.apache.fop.apps.Fop; //導入方法依賴的package包/類
/**
* Tests Fop with JAXP and OutputStream generating PostScript.
* @throws Exception if anything fails
*/
@Test
public void testFO2PSWithJAXP() 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_POSTSCRIPT, 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 PostScript has zero length", baout.size() > 0);
}
示例15: testFO2PDFWithJAXP
import org.apache.fop.apps.Fop; //導入方法依賴的package包/類
/**
* Tests Fop with JAXP and OutputStream generating PDF.
* @throws Exception if anything fails
*/
@Test
public void testFO2PDFWithJAXP() 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_PDF, 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 PDF has zero length", baout.size() > 0);
}