Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

Main.java 2.9KB

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