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.

AreaTreeInputHandler.java 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. /* $Id$ */
  18. package org.apache.fop.cli;
  19. import java.io.File;
  20. import java.io.OutputStream;
  21. import java.util.Vector;
  22. import javax.xml.transform.Result;
  23. import javax.xml.transform.sax.SAXResult;
  24. import org.xml.sax.SAXException;
  25. import org.apache.fop.apps.FOPException;
  26. import org.apache.fop.apps.FOUserAgent;
  27. import org.apache.fop.area.AreaTreeModel;
  28. import org.apache.fop.area.AreaTreeParser;
  29. import org.apache.fop.area.RenderPagesModel;
  30. import org.apache.fop.fonts.FontInfo;
  31. /**
  32. * InputHandler for the area tree XML (the old intermediate format) as input.
  33. */
  34. public class AreaTreeInputHandler extends InputHandler {
  35. /**
  36. * Constructor for XML->XSLT->area tree XML input
  37. * @param xmlfile XML file
  38. * @param xsltfile XSLT file
  39. * @param params Vector of command-line parameters (name, value,
  40. * name, value, ...) for XSL stylesheet, null if none
  41. */
  42. public AreaTreeInputHandler(File xmlfile, File xsltfile, Vector params) {
  43. super(xmlfile, xsltfile, params);
  44. }
  45. /**
  46. * Constructor for area tree XML input
  47. * @param atfile the file to read the area tree document.
  48. */
  49. public AreaTreeInputHandler(File atfile) {
  50. super(atfile);
  51. }
  52. /** {@inheritDoc} */
  53. public void renderTo(FOUserAgent userAgent, String outputFormat, OutputStream out)
  54. throws FOPException {
  55. FontInfo fontInfo = new FontInfo();
  56. AreaTreeModel treeModel = new RenderPagesModel(userAgent,
  57. outputFormat, fontInfo, out);
  58. //Iterate over all intermediate files
  59. AreaTreeParser parser = new AreaTreeParser();
  60. // Resulting SAX events (the generated FO) must be piped through to FOP
  61. Result res = new SAXResult(parser.getContentHandler(treeModel, userAgent));
  62. transformTo(res);
  63. try {
  64. treeModel.endDocument();
  65. } catch (SAXException e) {
  66. throw new FOPException(e);
  67. }
  68. }
  69. }