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.

FOProcessorImpl.java 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Copyright 2004 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /* $Id$ */
  17. package org.apache.fop.threading;
  18. import java.io.InputStream;
  19. import java.io.OutputStream;
  20. import java.net.URL;
  21. import javax.xml.transform.*;
  22. import javax.xml.transform.stream.StreamSource;
  23. import javax.xml.transform.stream.StreamResult;
  24. import javax.xml.transform.sax.SAXResult;
  25. import org.xml.sax.InputSource;
  26. import org.apache.avalon.framework.logger.AbstractLogEnabled;
  27. import org.apache.avalon.framework.configuration.*;
  28. import org.apache.fop.apps.Fop;
  29. import org.apache.fop.apps.FOPException;
  30. import org.apache.fop.fo.Constants;
  31. import org.apache.avalon.framework.activity.Initializable;
  32. public class FOProcessorImpl extends AbstractLogEnabled
  33. implements FOProcessor, Configurable, Initializable {
  34. private String baseDir;
  35. private String fontBaseDir;
  36. private String userconfig;
  37. private boolean strokeSVGText;
  38. public void configure(Configuration configuration) throws ConfigurationException {
  39. this.baseDir = configuration.getChild("basedir").getValue(null);
  40. this.fontBaseDir = configuration.getChild("fontbasedir").getValue(null);
  41. this.userconfig = configuration.getChild("userconfig").getValue(null);
  42. this.strokeSVGText = configuration.getChild("strokesvgtext").getValueAsBoolean(true);
  43. }
  44. public void initialize() throws Exception {
  45. /*
  46. org.apache.fop.messaging.MessageHandler.setScreenLogger(getLogger());
  47. if (userconfig != null) {
  48. getLogger().info("Using user config: "+userconfig);
  49. InputStream in = org.apache.fop.tools.URLBuilder.buildURL(userconfig).openStream();
  50. try {
  51. new org.apache.fop.apps.Options(in);
  52. } finally {
  53. in.close();
  54. }
  55. }
  56. if (this.baseDir != null) {
  57. getLogger().info("Setting base dir: "+baseDir);
  58. org.apache.fop.configuration.Configuration.put("baseDir", this.baseDir);
  59. }
  60. if (this.fontBaseDir != null) {
  61. getLogger().info("Setting font base dir: "+fontBaseDir);
  62. org.apache.fop.configuration.Configuration.put("fontBaseDir", this.fontBaseDir);
  63. }
  64. String value = (this.strokeSVGText?"true":"false");
  65. org.apache.fop.configuration.Configuration.put("strokeSVGText", value);
  66. */
  67. }
  68. public void process(InputStream in, Templates templates, OutputStream out)
  69. throws org.apache.fop.apps.FOPException, java.io.IOException {
  70. Fop fop = new Fop(Constants.RENDER_PDF);
  71. fop.setOutputStream(out);
  72. try {
  73. Transformer transformer;
  74. if (templates == null) {
  75. TransformerFactory factory = TransformerFactory.newInstance();
  76. transformer = factory.newTransformer();
  77. } else {
  78. transformer = templates.newTransformer();
  79. }
  80. Source src = new StreamSource(in);
  81. Result res = new SAXResult(fop.getDefaultHandler());
  82. transformer.transform(src, res);
  83. } catch (TransformerException e) {
  84. throw new FOPException(e);
  85. }
  86. }
  87. }