本文整理匯總了Java中org.apache.fop.apps.FopFactory.newFOUserAgent方法的典型用法代碼示例。如果您正苦於以下問題:Java FopFactory.newFOUserAgent方法的具體用法?Java FopFactory.newFOUserAgent怎麽用?Java FopFactory.newFOUserAgent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.fop.apps.FopFactory
的用法示例。
在下文中一共展示了FopFactory.newFOUserAgent方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createFopInstance
import org.apache.fop.apps.FopFactory; //導入方法依賴的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: resolveView
import org.apache.fop.apps.FopFactory; //導入方法依賴的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);
}
示例3: testDocumentHandlerLevel
import org.apache.fop.apps.FopFactory; //導入方法依賴的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
}
}
示例4: readInput
import org.apache.fop.apps.FopFactory; //導入方法依賴的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);
}
}
示例5: getFOUserAgent
import org.apache.fop.apps.FopFactory; //導入方法依賴的package包/類
/**
* Allow user access to FOUserAgent, so they can setAccessibility(true). Access to other settings
* is possible but unsupported.
*
* @param wmlPackage
* @return
* @throws FOPException
*/
public static FOUserAgent getFOUserAgent(FOSettings settings) throws Docx4JException, FOPException {
FopFactory fopFactory = getFopFactory(
setupApacheFopConfiguration(settings)); // relies on the WordML package being there, for font info
settings.getSettings().put(FOP_FACTORY, fopFactory);
FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
settings.getSettings().put(FO_USER_AGENT, foUserAgent);
return foUserAgent;
}
示例6: writeOutputStream
import org.apache.fop.apps.FopFactory; //導入方法依賴的package包/類
public static InputStream writeOutputStream(String fo,String outputFormat, OutputStream pdfOUT)
throws TransformerFactoryConfigurationError, TransformerConfigurationException, TransformerException
{
try
{
FopFactory fopFactory = FopFactory.newInstance();
FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
// configure foUserAgent as desired
InputStream templateIS;
//out = new BufferedOutputStream(pdfOUT);
// Construct FOP with desired output format
//private FopFactory fopFactory = FopFactory.newInstance();
Fop fop = fopFactory.newFop(outputFormat, foUserAgent,pdfOUT );
// Setup JAXP using identity transformer
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(); // identity transformer
// Setup input stream
templateIS = Text.toInputStream(fo);
Source src = new StreamSource(templateIS);
// 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);
return templateIS;
}
catch(FOPException e)
{
throw new SystemException(e.getMessage(),e);
}
}
示例7: createFopInstance
import org.apache.fop.apps.FopFactory; //導入方法依賴的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"
* @return Fop instance
*/
public static Fop createFopInstance(OutputStream out, String outputFormat) throws FOPException {
if (UtilValidate.isEmpty(outputFormat)) {
outputFormat = MimeConstants.MIME_PDF;
}
FopFactory fopFactory = getFactoryInstance();
FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
Fop fop;
if (out != null) {
fop = fopFactory.newFop(outputFormat, foUserAgent, out);
} else {
fop = fopFactory.newFop(outputFormat, foUserAgent);
}
return fop;
}
示例8: setupFonts
import org.apache.fop.apps.FopFactory; //導入方法依賴的package包/類
private FontInfo setupFonts(FopFactory fopFactory, String mime, FontEventListener listener)
throws FOPException {
FOUserAgent userAgent = fopFactory.newFOUserAgent();
//The document handler is only instantiated to get access to its configurator!
IFDocumentHandler documentHandler
= fopFactory.getRendererFactory().createDocumentHandler(userAgent, mime);
IFDocumentHandlerConfigurator configurator = documentHandler.getConfigurator();
FontInfo fontInfo = new FontInfo();
configurator.setupFontInfo(documentHandler, fontInfo);
return fontInfo;
}
示例9: givenAConfigurationFile
import org.apache.fop.apps.FopFactory; //導入方法依賴的package包/類
private void givenAConfigurationFile(String filename, EventListener eventListener)
throws Exception {
FopFactory fopFactory = FopFactory.newInstance();
fopFactory.setUserConfig(new File("test/resources/org/apache/fop/render/pdf/"
+ filename + ".xconf"));
foUserAgent = fopFactory.newFOUserAgent();
foUserAgent.getEventBroadcaster().addEventListener(eventListener);
}
示例10: testRendererLevel
import org.apache.fop.apps.FopFactory; //導入方法依賴的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
}
}
示例11: testRGB
import org.apache.fop.apps.FopFactory; //導入方法依賴的package包/類
/**
* Tests the rgb() function.
* @throws Exception if an error occurs
*/
@Test
public void testRGB() throws Exception {
FopFactory fopFactory = FopFactory.newInstance();
FOUserAgent ua = fopFactory.newFOUserAgent();
Color colActual;
colActual = ColorUtil.parseColorString(ua, "rgb(255, 40, 0)");
assertEquals(255, colActual.getRed());
assertEquals(40, colActual.getGreen());
assertEquals(0, colActual.getBlue());
assertEquals(255, colActual.getAlpha());
assertEquals(ColorSpace.getInstance(ColorSpace.CS_sRGB), colActual.getColorSpace());
}
示例12: print
import org.apache.fop.apps.FopFactory; //導入方法依賴的package包/類
public String print(String location) throws IOException, EngineException, SAXException, TransformerConfigurationException, TransformerFactoryConfigurationError, TransformerException, ParserConfigurationException {
try {
//create the result repository
outputFolder = location + "/ConvertigoPrint";
File repository = new File(outputFolder);
if (!repository.exists()) {
repository.mkdir();
}
outputFileName = outputFolder + "\\" + projectName + extension;
outputFile = new File(outputFileName);
updateStatus("Setting up printing",20);
// Construct/Configure a FopFactory
FopFactory fopFactory = FopFactory.newInstance();
fopFactory.setBaseURL(Engine.TEMPLATES_PATH + "/doc/");
fopFactory.setStrictValidation(false);
// Configure foUserAgent as desired
FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
foUserAgent.setBaseURL(Engine.TEMPLATES_PATH + "/doc/");
foUserAgent.setAuthor("Convertigo EMS");
// Setup output
out = new FileOutputStream(outputFile);
out = new java.io.BufferedOutputStream(out);
// Construct fop with desired output format
Fop fop = fopFactory.newFop(outputMime, foUserAgent, out);
updateStatus("Analysing project",40);
//Transform the project into a source
Document document = XMLUtils.createDom("java");
Element convertigoElement = document.createElement("convertigo");
convertigoElement.setAttribute("exported", new Date().toString());
convertigoElement.setAttribute("studio", product);
convertigoElement.setAttribute("engine", com.twinsoft.convertigo.engine.Version.version);
convertigoElement.setAttribute("beans", com.twinsoft.convertigo.beans.Version.version);
//work around to let the external-graphics tag to read relative path
//TODO configure fopFactory or/and foUserAgent
convertigoElement.setAttribute("path", Engine.TEMPLATES_PATH+"/doc/");
document.appendChild(convertigoElement);
ProjectUtils.getFullProjectDOM(document, projectName, ExportOption.bIncludeDisplayName, ExportOption.bIncludeCompiledValue);
Source src=new DOMSource(document);
updateStatus("Printing in progress",60);
// Setup XSLT
String templateFileName = Engine.TEMPLATES_PATH + "/doc/doc.fo.xml";
File foFile = new File(templateFileName);
localizedDir = Engine.TEMPLATES_PATH+ "/doc/";
Source xsltSrc = new StreamSource(new FileInputStream(foFile), localizedDir);
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer(xsltSrc);
updateStatus(70);
// Resulting SAX events (the generated FO) must be piped through to FOP
DefaultHandler fopHandler=fop.getDefaultHandler();
Result res = new SAXResult(fopHandler);
// Start XSLT transformation and FOP processing
transformer.transform(src,res);
return outputFileName;
} finally {
if (out != null) {
out.close();
}
}
}
示例13: processFopSerializer
import org.apache.fop.apps.FopFactory; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
private void processFopSerializer(String uri, String localName, String qName, Attributes attributes) throws Exception {
try {
String path = attributes.getValue("", "path");
if (path == null) {
/* Write to HTTP response: */
if (resp == null) {
throw new SAXException("No attribute \"path\" specified on fop-serializer element");
}
} else {
/* Write to file: */
File outputFile = new File(path);
File parentDir = outputFile.getParentFile();
if (!parentDir.isDirectory()) {
if (!parentDir.mkdirs()) {
throw new SAXException("Could not create directory \"" + parentDir.getAbsolutePath() + "\"");
}
}
if (outputFile.exists()) {
if (outputFile.isDirectory()) {
throw new SAXException("File \"" + parentDir.getAbsolutePath() + "\" already exists as directory");
} else if (!outputFile.delete()) {
throw new SAXException("Could not delete output file \"" + outputFile.getAbsolutePath() + "\"");
}
}
this.os = new BufferedOutputStream(new FileOutputStream(outputFile));
}
String configName = attributes.getValue("config-name");
if (configName == null) {
throw new SAXException("No attribute \"config-name\" specified on fop-serializer element");
}
FopFactory fopFactory = webApp.getFopFactory(configName);
FOUserAgent userAgent = fopFactory.newFOUserAgent();
String mode = attributes.getValue("pdf-a-mode");
if (mode != null) {
userAgent.getRendererOptions().put("pdf-a-mode", mode);
}
String outputFormat = attributes.getValue("output-format");
boolean nonStreaming = StringUtils.equals(attributes.getValue("non-streaming"), "true");
nsos = (nonStreaming) ? new ByteArrayOutputStream() : null;
Fop fop = fopFactory.newFop(outputFormat == null ? MimeConstants.MIME_PDF : outputFormat,
userAgent, (nsos != null) ? nsos : os);
this.serializingHandler = fop.getDefaultHandler();
} catch (Exception e) {
exceptionThrown = true;
throw e;
}
}
示例14: generatePDFReport
import org.apache.fop.apps.FopFactory; //導入方法依賴的package包/類
@GET @Path("/{domain}/session/{sid}/report-pdf")
@Info("Generates a PDF report of the selected session")
public void generatePDFReport(
@PathParam("domain") @Info("The work domain") String domain,
@HeaderParam("token") @Info("The authentication token") String token,
@PathParam("sid") @Info("The session id") String sid) throws Exception {
RiscossDB db = null;
try {
db = DBConnector.openDB( domain, token );
RiskAnalysisSession ras = db.openRAS(sid);
List<String> modelsList = db.getModelsFromRiskCfg( ras.getRCName(), ras.getTarget() );
StringReader xml = new StringReader(getXMLReport(ras, modelsList));
FileInputStream xsl = new FileInputStream("resources/ras-stylesheet.xslt");;
StringWriter writer = new StringWriter();
Source xmlDoc = new StreamSource(xml);
Source xslDoc = new StreamSource(xsl);
Result result = new StreamResult(writer);
TransformerFactory factory = TransformerFactory.newInstance();
Transformer trans = factory.newTransformer(xslDoc);
trans.transform(xmlDoc, result);
String html = writer.toString();
html = html.replace("<META http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">", "");
html = html.replace("<br>", "<br/>");
html = html.replace("<hr style=\"color: #7EAC30;\">", "<hr style=\"color: #7EAC30;\"/>");
html = html.replace("“", "");
html = html.replace("”", "");
html = html.replace("\"logo\">", "\"logo\"></img>");
FopFactory fopFactory = FopFactory.newInstance(new File(".").toURI());
FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
OutputStream out = new FileOutputStream(new File("resources/report.pdf"));
out = new java.io.BufferedOutputStream(out);
Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out);
Source xslt = new StreamSource(new File("resources/ras-stylesheet-fo.xslt"));
Transformer transformer = factory.newTransformer(xslt);
transformer.setParameter("versionParam", "2.0");
Source src = new StreamSource(new StringReader(html));
Result res = new SAXResult(fop.getDefaultHandler());
transformer.transform(src, res);
out.close();
} catch( Exception ex ) {
throw ex;
}
finally {
DBConnector.closeDB( db );
}
}
示例15: generatePDF
import org.apache.fop.apps.FopFactory; //導入方法依賴的package包/類
/**
* Takes a DOM structure and renders a PDF
*
* @param doc
* DOM structure
* @param xslFileName
* XSL file to use to translate the DOM document to FOP
*/
@SuppressWarnings("unchecked")
protected void generatePDF(Document doc, OutputStream streamOut)
{
String xslFileName = "participants-all-attrs.xsl";
Locale currentLocale = rb.getLocale();
if (currentLocale!=null){
String fullLocale = currentLocale.toString();
xslFileName = "participants-all-attrs_" + fullLocale + ".xsl";
InputStream inputStream = getClass().getClassLoader().getResourceAsStream(xslFileName);
if (inputStream == null){
xslFileName = "participants-all-attrs_" + currentLocale.getCountry() + ".xsl";
inputStream = getClass().getClassLoader().getResourceAsStream(xslFileName);
if (inputStream == null){
//We use the default file
xslFileName = "participants-all-attrs.xsl";
}
}
IOUtils.closeQuietly(inputStream);
}
String configFileName = "userconfig.xml";
DefaultConfigurationBuilder cfgBuilder = new DefaultConfigurationBuilder();
InputStream configInputStream = null;
try
{
configInputStream = getClass().getClassLoader().getResourceAsStream(configFileName);
Configuration cfg = cfgBuilder.build(configInputStream);
FopFactory fopFactory = FopFactory.newInstance();
fopFactory.setUserConfig(cfg);
fopFactory.setStrictValidation(false);
FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
if (!StringUtils.isEmpty(ServerConfigurationService.getString("pdf.default.font"))) {
// this allows font substitution to support i18n chars in PDFs - SAK-21909
FontQualifier fromQualifier = new FontQualifier();
fromQualifier.setFontFamily("DEFAULT_FONT");
FontQualifier toQualifier = new FontQualifier();
toQualifier.setFontFamily(ServerConfigurationService.getString("pdf.default.font", "Helvetica"));
FontSubstitutions result = new FontSubstitutions();
result.add(new FontSubstitution(fromQualifier, toQualifier));
fopFactory.getFontManager().setFontSubstitutions(result);
}
Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, streamOut);
InputStream in = getClass().getClassLoader().getResourceAsStream(xslFileName);
Transformer transformer = transformerFactory.newTransformer(new StreamSource(in));
transformer.setParameter("titleName", rb.getString("sitegen.siteinfolist.title.name"));
transformer.setParameter("titleSection", rb.getString("sitegen.siteinfolist.title.section"));
transformer.setParameter("titleId", rb.getString("sitegen.siteinfolist.title.id"));
transformer.setParameter("titleCredit", rb.getString("sitegen.siteinfolist.title.credit"));
transformer.setParameter("titleRole", rb.getString("sitegen.siteinfolist.title.role"));
transformer.setParameter("titleStatus", rb.getString("sitegen.siteinfolist.title.status"));
Source src = new DOMSource(doc);
transformer.transform(src, new SAXResult(fop.getDefaultHandler()));
}
catch (Exception e)
{
log.warn(this+".generatePDF(): " + e);
return;
}
finally
{
IOUtils.closeQuietly(configInputStream);
}
}