1 17 18 19 20 package org.apache.fop.threading; 21 22 import java.io.InputStream ; 23 import java.io.OutputStream ; 24 25 import javax.xml.transform.Result ; 26 import javax.xml.transform.Source ; 27 import javax.xml.transform.Templates ; 28 import javax.xml.transform.Transformer ; 29 import javax.xml.transform.TransformerException ; 30 import javax.xml.transform.TransformerFactory ; 31 import javax.xml.transform.stream.StreamSource ; 32 import javax.xml.transform.sax.SAXResult ; 33 34 import org.apache.avalon.framework.logger.AbstractLogEnabled; 35 import org.apache.avalon.framework.configuration.Configurable; 36 import org.apache.avalon.framework.configuration.Configuration; 37 import org.apache.avalon.framework.configuration.ConfigurationException; 38 39 import org.apache.fop.apps.FOUserAgent; 40 import org.apache.fop.apps.Fop; 41 import org.apache.fop.apps.FOPException; 42 import org.apache.fop.apps.FopFactory; 43 import org.apache.fop.apps.MimeConstants; 44 import org.apache.avalon.framework.activity.Initializable; 45 46 public class FOProcessorImpl extends AbstractLogEnabled 47 implements FOProcessor, Configurable, Initializable { 48 49 private FopFactory fopFactory = FopFactory.newInstance(); 50 private TransformerFactory factory = TransformerFactory.newInstance(); 51 private String baseDir; 52 private String fontBaseDir; 53 private String userconfig; 54 private boolean strokeSVGText; 55 56 public void configure(Configuration configuration) throws ConfigurationException { 57 this.baseDir = configuration.getChild("basedir").getValue(null); 58 this.fontBaseDir = configuration.getChild("fontbasedir").getValue(null); 59 this.userconfig = configuration.getChild("userconfig").getValue(null); 60 this.strokeSVGText = configuration.getChild("strokesvgtext").getValueAsBoolean(true); 61 } 62 63 64 public void initialize() throws Exception { 65 87 } 88 89 90 public void process(InputStream in, Templates templates, OutputStream out) 91 throws org.apache.fop.apps.FOPException, java.io.IOException { 92 FOUserAgent foUserAgent = fopFactory.newFOUserAgent(); 93 Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out); 94 95 try { 96 Transformer transformer; 97 if (templates == null) { 98 transformer = factory.newTransformer(); 99 } else { 100 transformer = templates.newTransformer(); 101 } 102 Source src = new StreamSource (in); 103 Result res = new SAXResult (fop.getDefaultHandler()); 104 transformer.transform(src, res); 105 } catch (TransformerException e) { 106 throw new FOPException(e); 107 } 108 } 109 110 } | Popular Tags |