1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
|
Index: src/blocks/fop/java/org/apache/cocoon/serialization/FOPSerializer.java
===================================================================
RCS file: /home/cvspublic/xml-cocoon2/src/blocks/fop/java/org/apache/cocoon/serialization/FOPSerializer.java,v
retrieving revision 1.4
diff -u -r1.4 FOPSerializer.java
--- src/blocks/fop/java/org/apache/cocoon/serialization/FOPSerializer.java 21 Nov 2002 18:18:48 -0000 1.4
+++ src/blocks/fop/java/org/apache/cocoon/serialization/FOPSerializer.java 5 Dec 2002 09:21:13 -0000
@@ -63,18 +63,28 @@
import org.apache.cocoon.components.url.URLFactory;
import org.apache.cocoon.util.ClassUtils;
import org.apache.cocoon.environment.URLFactorySourceResolver;
-import org.apache.cocoon.environment.Source;
+import org.apache.cocoon.environment.Environment;
+import org.apache.excalibur.source.Source;
+import org.apache.excalibur.source.SourceResolver;
import org.apache.excalibur.source.SourceValidity;
import org.apache.excalibur.source.impl.validity.NOPValidity;
import org.apache.fop.apps.Driver;
-import org.apache.fop.apps.Options;
-import org.apache.fop.messaging.MessageHandler;
import org.apache.fop.render.Renderer;
-import org.apache.fop.configuration.ConfigurationParser;
+import org.apache.fop.fo.FOUserAgent;
+import org.apache.cocoon.components.RequestLifecycleComponent;
+import org.apache.avalon.framework.component.Component;
+import org.apache.cocoon.ProcessingException;
+import org.xml.sax.SAXException;
+import org.apache.cocoon.components.RequestLifecycleComponent;
+
+import java.io.IOException;
+import java.util.Map;
import java.io.OutputStream;
import java.io.File;
import java.io.Serializable;
+import java.io.InputStream;
+import java.net.URL;
import java.net.MalformedURLException;
/**
@@ -84,7 +94,7 @@
*/
public class FOPSerializer
extends AbstractSerializer
-implements Composable, Configurable, CacheableProcessingComponent {
+implements Composable, Configurable, CacheableProcessingComponent, RequestLifecycleComponent {
/**
* The Renderer Factory to use
@@ -97,6 +107,11 @@
protected Driver driver;
/**
+ * The current <code>FOUserAgent</code>.
+ */
+ protected FOUserAgent userAgent;
+
+ /**
* The current <code>Renderer</code>.
*/
protected Renderer renderer;
@@ -145,24 +160,6 @@
public void configure(Configuration conf) throws ConfigurationException {
this.logger = getLogger().getChildLogger("fop");
- MessageHandler.setScreenLogger(this.logger);
-
- // FIXME: VG: Initialize static FOP configuration with defaults, only once.
- // FOP has static config, but that's going to change in the near future.
- // Then this code should be reviewed.
- synchronized (FOPSerializer.class) {
- if (!configured) {
- try {
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("Loading default configuration");
- }
- new Options();
- } catch (Exception e) {
- getLogger().error("Cannot load default configuration. Proceeding.", e);
- }
- configured = true;
- }
- }
this.setContentLength = conf.getChild("set-content-length").getValueAsBoolean(true);
@@ -180,28 +177,6 @@
// New syntax: Element user-config contains URL
configUrl = conf.getChild("user-config").getValue(null);
}
- if(configUrl != null) {
- URLFactory urlFactory = null;
- Source configSource = null;
- try {
- // FIXME: How to do without URLFactory but relative to context?
- urlFactory = (URLFactory)manager.lookup(URLFactory.ROLE);
- URLFactorySourceResolver urlResolver = new URLFactorySourceResolver(urlFactory, manager);
- configSource = urlResolver.resolve(configUrl);
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("Loading configuration from " + configSource.getSystemId());
- }
- configSource.toSAX(new ConfigurationParser());
- } catch (Exception e) {
- getLogger().warn("Cannot load configuration from " + configUrl);
- throw new ConfigurationException("Cannot load configuration from " + configUrl, e);
- } finally {
- manager.release(urlFactory);
- if (configSource != null) {
- configSource.recycle();
- }
- }
- }
// Get the mime type.
this.mimetype = conf.getAttribute("mime-type");
@@ -233,6 +208,22 @@
+ "no renderer was specified in the sitemap configuration."
);
}
+ this.renderer.setCreator("Cocoon");
+
+ userAgent = new FOUserAgent();
+ userAgent.enableLogging(this.logger);
+ //userAgent.setBaseURL(source.getSystemId());
+
+ // load the fop driver
+ this.driver = new Driver();
+ driver.enableLogging(this.logger);
+ driver.setUserAgent(userAgent);
+
+ driver.setRenderer(this.renderer);
+
+ //driver.configure(conf);
+ driver.initialize();
+
}
/**
@@ -242,27 +233,39 @@
return mimetype;
}
+ public void setup(final org.apache.cocoon.environment.SourceResolver resolver, Map objectModel)
+ throws ProcessingException, SAXException, IOException {
+
+ userAgent = new FOUserAgent() {
+ public InputStream getStream(String uri) {
+ try {
+ Environment env = (Environment) resolver;
+ org.apache.cocoon.environment.Source source = null;
+ org.apache.cocoon.components.source.CocoonSourceFactory ccf;
+ ccf = new org.apache.cocoon.components.source.CocoonSourceFactory(null, manager);
+ ccf.enableLogging(logger);
+ source = ccf.getSource(env, "/" + uri);
+ getLogger().debug("Loading image from " + source.getSystemId());
+ InputStream is = source.getInputStream();
+ getLogger().debug("input stream: " + is + ":" + is.available());
+ return is;
+ } catch (Exception e) {
+ getLogger().error("Cannot load source", e);
+ }
+ return null;
+ }
+ };
+ userAgent.enableLogging(this.logger);
+ //userAgent.setBaseURL(source.getSystemId());
+
+ driver.setUserAgent(userAgent);
+ }
+
/**
* Create the FOP driver
* Set the <code>OutputStream</code> where the XML should be serialized.
*/
public void setOutputStream(OutputStream out) {
- // load the fop driver
- this.driver = new Driver();
- this.driver.setLogger(this.logger);
- if (this.rendererName == null) {
- this.renderer = factory.createRenderer(mimetype);
- } else {
- try {
- this.renderer = (Renderer)ClassUtils.newInstance(this.rendererName);
- } catch (Exception e) {
- if (getLogger().isWarnEnabled()) {
- getLogger().warn("Cannot load class " + this.rendererName, e);
- }
- throw new CascadingRuntimeException("Cannot load class " + this.rendererName, e);
- }
- }
- this.driver.setRenderer(this.renderer);
this.driver.setOutputStream(out);
setContentHandler(this.driver.getContentHandler());
}
@@ -296,8 +299,7 @@
*/
public void recycle() {
super.recycle();
- this.driver = null;
- this.renderer = null;
+ this.driver.reset();
}
/**
@@ -307,3 +309,4 @@
return this.setContentLength;
}
}
+
Index: src/java/org/apache/cocoon/components/pipeline/AbstractProcessingPipeline.java
===================================================================
RCS file: /home/cvspublic/xml-cocoon2/src/java/org/apache/cocoon/components/pipeline/AbstractProcessingPipeline.java,v
retrieving revision 1.24
diff -u -r1.24 AbstractProcessingPipeline.java
--- src/java/org/apache/cocoon/components/pipeline/AbstractProcessingPipeline.java 11 Oct 2002 08:36:30 -0000 1.24
+++ src/java/org/apache/cocoon/components/pipeline/AbstractProcessingPipeline.java 5 Dec 2002 09:21:13 -0000
@@ -62,6 +62,7 @@
import org.apache.cocoon.ConnectionResetException;
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.components.CocoonComponentManager;
+import org.apache.cocoon.components.RequestLifecycleComponent;
import org.apache.cocoon.components.treeprocessor.ProcessingNode;
import org.apache.cocoon.environment.Environment;
import org.apache.cocoon.environment.ObjectModelHelper;
@@ -392,6 +393,15 @@
environment.getObjectModel(),
(String)transformerSourceItt.next(),
(Parameters)transformerParamItt.next()
+ );
+ }
+
+ // WARNING: quick hack
+ // setup the serializer
+ if(this.serializer instanceof RequestLifecycleComponent) {
+ ((RequestLifecycleComponent)this.serializer).setup(
+ environment,
+ environment.getObjectModel()
);
}
|