KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > threading > FOProcessorImpl


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 /* $Id: FOProcessorImpl.java 426576 2006-07-28 15:44:37Z jeremias $ */
19
20 package org.apache.fop.threading;
21
22 import java.io.InputStream JavaDoc;
23 import java.io.OutputStream JavaDoc;
24
25 import javax.xml.transform.Result JavaDoc;
26 import javax.xml.transform.Source JavaDoc;
27 import javax.xml.transform.Templates JavaDoc;
28 import javax.xml.transform.Transformer JavaDoc;
29 import javax.xml.transform.TransformerException JavaDoc;
30 import javax.xml.transform.TransformerFactory JavaDoc;
31 import javax.xml.transform.stream.StreamSource JavaDoc;
32 import javax.xml.transform.sax.SAXResult JavaDoc;
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 JavaDoc factory = TransformerFactory.newInstance();
51     private String JavaDoc baseDir;
52     private String JavaDoc fontBaseDir;
53     private String JavaDoc 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 JavaDoc {
65         /*
66         org.apache.fop.messaging.MessageHandler.setScreenLogger(getLogger());
67         if (userconfig != null) {
68             getLogger().info("Using user config: "+userconfig);
69             InputStream in = org.apache.fop.tools.URLBuilder.buildURL(userconfig).openStream();
70             try {
71                 new org.apache.fop.apps.Options(in);
72             } finally {
73                 in.close();
74             }
75         }
76         if (this.baseDir != null) {
77             getLogger().info("Setting base dir: "+baseDir);
78             org.apache.fop.configuration.Configuration.put("baseDir", this.baseDir);
79         }
80         if (this.fontBaseDir != null) {
81             getLogger().info("Setting font base dir: "+fontBaseDir);
82             org.apache.fop.configuration.Configuration.put("fontBaseDir", this.fontBaseDir);
83         }
84         String value = (this.strokeSVGText?"true":"false");
85         org.apache.fop.configuration.Configuration.put("strokeSVGText", value);
86         */

87     }
88
89
90     public void process(InputStream JavaDoc in, Templates JavaDoc templates, OutputStream JavaDoc out)
91                 throws org.apache.fop.apps.FOPException, java.io.IOException JavaDoc {
92         FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
93         Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out);
94
95         try {
96             Transformer JavaDoc transformer;
97             if (templates == null) {
98                 transformer = factory.newTransformer();
99             } else {
100                 transformer = templates.newTransformer();
101             }
102             Source JavaDoc src = new StreamSource JavaDoc(in);
103             Result JavaDoc res = new SAXResult JavaDoc(fop.getDefaultHandler());
104             transformer.transform(src, res);
105         } catch (TransformerException JavaDoc e) {
106             throw new FOPException(e);
107         }
108     }
109
110 }
Popular Tags