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.

Main.java 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Copyright 1999-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.plan;
  18. import java.io.InputStream;
  19. import java.io.Writer;
  20. import org.w3c.dom.Document;
  21. import org.w3c.dom.Element;
  22. import org.apache.batik.transcoder.svg2svg.SVGTranscoder;
  23. import org.apache.batik.transcoder.TranscoderInput;
  24. import org.apache.batik.transcoder.TranscoderOutput;
  25. /**
  26. * Sample command-line application for converting plan XML to SVG.
  27. */
  28. public class Main {
  29. /**
  30. * Main method.
  31. * @param args command-line arguments
  32. */
  33. public static void main(String[] args) {
  34. Main main = new Main();
  35. main.convert(args);
  36. System.exit(0);
  37. }
  38. /**
  39. * Runs the conversion
  40. * @param params command-line arguments
  41. */
  42. public void convert(String[] params) {
  43. if (params.length != 2) {
  44. System.out.println("arguments: plan.xml output.svg");
  45. return;
  46. }
  47. try {
  48. InputStream is = new java.io.FileInputStream(params[0]);
  49. Document doc = createSVGDocument(is);
  50. SVGTranscoder svgT = new SVGTranscoder();
  51. TranscoderInput input = new TranscoderInput(doc);
  52. Writer ostream = new java.io.FileWriter(params[1]);
  53. TranscoderOutput output = new TranscoderOutput(ostream);
  54. svgT.transcode(input, output);
  55. ostream.flush();
  56. ostream.close();
  57. } catch (Exception e) {
  58. e.printStackTrace();
  59. }
  60. }
  61. /**
  62. * Helper method to create the SVG document from the plan InputStream.
  63. * @param is InputStream
  64. * @return Document a DOM containing the SVG
  65. */
  66. public Document createSVGDocument(InputStream is) {
  67. Document doc = null;
  68. Element root = null;
  69. try {
  70. doc = javax.xml.parsers.DocumentBuilderFactory.newInstance().
  71. newDocumentBuilder().parse(is);
  72. root = doc.getDocumentElement();
  73. } catch (Exception e) {
  74. e.printStackTrace();
  75. }
  76. PlanRenderer gr = new PlanRenderer();
  77. gr.setFontInfo("sansserif", 12);
  78. Document svgdoc = gr.createSVGDocument(doc);
  79. return svgdoc;
  80. }
  81. }