本文整理汇总了Java中org.apache.fop.apps.FOUserAgent.setDocumentHandlerOverride方法的典型用法代码示例。如果您正苦于以下问题:Java FOUserAgent.setDocumentHandlerOverride方法的具体用法?Java FOUserAgent.setDocumentHandlerOverride怎么用?Java FOUserAgent.setDocumentHandlerOverride使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.fop.apps.FOUserAgent
的用法示例。
在下文中一共展示了FOUserAgent.setDocumentHandlerOverride方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testDocumentHandlerLevel
import org.apache.fop.apps.FOUserAgent; //导入方法依赖的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
}
}
示例2: testResourceOptimization
import org.apache.fop.apps.FOUserAgent; //导入方法依赖的package包/类
/**
* Tests resource optimization.
* @throws Exception if an error occurs
*/
@Test
public void testResourceOptimization() throws Exception {
FOUserAgent ua = fopFactory.newFOUserAgent();
PSDocumentHandler handler = new PSDocumentHandler();
handler.setContext(new IFContext(ua));
// This is the important part: we're enabling resource optimization
handler.getPSUtil().setOptimizeResources(true);
ua.setDocumentHandlerOverride(handler);
// Prepare output file
File outputFile = renderFile(ua, "ps-resources.fo",
"-if-l" + handler.getPSUtil().getLanguageLevel());
verifyPostScriptFile(outputFile);
}
示例3: innerTestJPEGImage
import org.apache.fop.apps.FOUserAgent; //导入方法依赖的package包/类
private void innerTestJPEGImage(int level) throws Exception {
FOUserAgent ua = fopFactory.newFOUserAgent();
PSDocumentHandler handler = new PSDocumentHandler();
handler.setContext(new IFContext(ua));
PSRenderingUtil psUtil = handler.getPSUtil();
psUtil.setLanguageLevel(level);
psUtil.setOptimizeResources(true);
ua.setDocumentHandlerOverride(handler);
// Prepare output file
File outputFile = renderFile(ua, "ps-jpeg-image.fo",
"-if-l" + psUtil.getLanguageLevel());
verifyPostScriptFile(outputFile, psUtil.getLanguageLevel());
}
示例4: testRendererLevel
import org.apache.fop.apps.FOUserAgent; //导入方法依赖的package包/类
@Test
public void testRendererLevel() throws Exception {
FopFactory fopFactory = FopFactory.newInstance();
RendererFactory factory = fopFactory.getRendererFactory();
FOUserAgent ua;
Renderer renderer;
ua = fopFactory.newFOUserAgent();
renderer = factory.createRenderer(ua, MimeConstants.MIME_PDF);
assertTrue(renderer instanceof IFRenderer);
ua = fopFactory.newFOUserAgent();
renderer = factory.createRenderer(ua, MimeConstants.MIME_FOP_IF);
assertTrue(renderer instanceof IFRenderer);
ua = fopFactory.newFOUserAgent();
IFDocumentHandler overrideHandler;
overrideHandler = new PDFDocumentHandler();
overrideHandler.setContext(new IFContext(ua));
ua.setDocumentHandlerOverride(overrideHandler);
renderer = factory.createRenderer(ua, null);
assertTrue(renderer instanceof IFRenderer);
ua = fopFactory.newFOUserAgent();
try {
renderer = factory.createRenderer(ua, "invalid/format");
fail("Expected UnsupportedOperationException");
} catch (UnsupportedOperationException uoe) {
//expected
}
}
示例5: doTestMimicking
import org.apache.fop.apps.FOUserAgent; //导入方法依赖的package包/类
private void doTestMimicking(String mime) throws FOPException, IFException,
TransformerException {
//Set up XMLRenderer to render to a DOM
DOMResult domResult = new DOMResult();
FOUserAgent userAgent = fopFactory.newFOUserAgent();
userAgent.getEventBroadcaster().addEventListener(new EventListener() {
public void processEvent(Event event) {
if (event.getEventGroupID().equals(FontEventProducer.class.getName())) {
fail("There must be no font-related event! Got: "
+ EventFormatter.format(event));
}
}
});
//Create an instance of the target renderer so the XMLRenderer can use its font setup
IFDocumentHandler targetHandler = userAgent.getRendererFactory().createDocumentHandler(
userAgent, mime);
//Setup painter
IFSerializer serializer = new IFSerializer();
serializer.setContext(new IFContext(userAgent));
serializer.mimicDocumentHandler(targetHandler);
serializer.setResult(domResult);
userAgent.setDocumentHandlerOverride(serializer);
Fop fop = fopFactory.newFop(userAgent);
//minimal-pdf-a.fo uses the Gladiator font so is an ideal FO file for this test:
StreamSource src = new StreamSource(new File("test/xml/pdf-a/minimal-pdf-a.fo"));
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer();
setErrorListener(transformer);
transformer.transform(src, new SAXResult(fop.getDefaultHandler()));
}
示例6: buildIntermediateDocument
import org.apache.fop.apps.FOUserAgent; //导入方法依赖的package包/类
@Override
protected Document buildIntermediateDocument(Templates templates) throws Exception {
Transformer transformer = templates.newTransformer();
setErrorListener(transformer);
//Set up XMLRenderer to render to a DOM
DOMResult domResult = new DOMResult();
FOUserAgent userAgent = createUserAgent();
//Create an instance of the target renderer so the XMLRenderer can use its font setup
IFDocumentHandler targetHandler = userAgent.getRendererFactory().createDocumentHandler(
userAgent, getTargetMIME());
//Setup painter
IFSerializer serializer = new IFSerializer();
serializer.setContext(new IFContext(userAgent));
serializer.mimicDocumentHandler(targetHandler);
serializer.setResult(domResult);
userAgent.setDocumentHandlerOverride(serializer);
Fop fop = fopFactory.newFop(userAgent);
Result res = new SAXResult(fop.getDefaultHandler());
transformer.transform(new DOMSource(testDoc), res);
return (Document) domResult.getNode();
}
示例7: convertToIntermediate
import org.apache.fop.apps.FOUserAgent; //导入方法依赖的package包/类
/**
* Converts an XSL-FO document to an intermediate file.
* @param src the source file
* @param xslt the stylesheet file
* @param intermediate the target intermediate 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 convertToIntermediate(Source src, Source xslt, File intermediate)
throws IOException, FOPException, TransformerException {
//Create a user agent
FOUserAgent userAgent = fopFactory.newFOUserAgent();
//Create an instance of the target document handler so the IFSerializer
//can use its font setup
IFDocumentHandler targetHandler = userAgent.getRendererFactory().createDocumentHandler(
userAgent, MimeConstants.MIME_PDF);
//Create the IFSerializer to write the intermediate format
IFSerializer ifSerializer = new IFSerializer();
ifSerializer.setContext(new IFContext(userAgent));
//Tell the IFSerializer to mimic the target format
ifSerializer.mimicDocumentHandler(targetHandler);
//Make sure the prepared document handler is used
userAgent.setDocumentHandlerOverride(ifSerializer);
// Setup output
OutputStream out = new java.io.FileOutputStream(intermediate);
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();
}
}