You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cocoon.diff 9.3KB

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