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.

IFInputHandler.java 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 javax.xml.transform.stream.StreamResult;
  25. import org.apache.fop.apps.FOPException;
  26. import org.apache.fop.apps.FOUserAgent;
  27. import org.apache.fop.render.intermediate.IFDocumentHandler;
  28. import org.apache.fop.render.intermediate.IFException;
  29. import org.apache.fop.render.intermediate.IFParser;
  30. import org.apache.fop.render.intermediate.IFUtil;
  31. /**
  32. * InputHandler for the intermediate format XML as input.
  33. */
  34. public class IFInputHandler extends InputHandler {
  35. /**
  36. * Constructor for XML->XSLT->intermediate 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 IFInputHandler(File xmlfile, File xsltfile, Vector params) {
  43. super(xmlfile, xsltfile, params);
  44. }
  45. /**
  46. * Constructor for intermediate input
  47. * @param iffile the file to read the intermediate format document from.
  48. */
  49. public IFInputHandler(File iffile) {
  50. super(iffile);
  51. }
  52. /** {@inheritDoc} */
  53. public void renderTo(FOUserAgent userAgent, String outputFormat, OutputStream out)
  54. throws FOPException {
  55. IFDocumentHandler documentHandler
  56. = userAgent.getRendererFactory().createDocumentHandler(
  57. userAgent, outputFormat);
  58. try {
  59. documentHandler.setResult(new StreamResult(out));
  60. IFUtil.setupFonts(documentHandler);
  61. //Create IF parser
  62. IFParser parser = new IFParser();
  63. // Resulting SAX events are sent to the parser
  64. Result res = new SAXResult(parser.getContentHandler(documentHandler, userAgent));
  65. transformTo(res);
  66. } catch (IFException ife) {
  67. throw new FOPException(ife);
  68. }
  69. }
  70. }