KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > plan > Main


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
18 /* $Id: Main.java 426576 2006-07-28 15:44:37Z jeremias $ */
19  
20 package org.apache.fop.plan;
21
22 import java.io.InputStream JavaDoc;
23 import java.io.Writer JavaDoc;
24
25 import org.w3c.dom.Document JavaDoc;
26 import org.w3c.dom.Element JavaDoc;
27
28 import org.apache.batik.transcoder.svg2svg.SVGTranscoder;
29 import org.apache.batik.transcoder.TranscoderInput;
30 import org.apache.batik.transcoder.TranscoderOutput;
31
32 /**
33  * Sample command-line application for converting plan XML to SVG.
34  */

35 public class Main {
36
37     /**
38      * Main method.
39      * @param args command-line arguments
40      */

41     public static void main(String JavaDoc[] args) {
42         Main main = new Main();
43         main.convert(args);
44         System.exit(0);
45     }
46
47     /**
48      * Runs the conversion
49      * @param params command-line arguments
50      */

51     public void convert(String JavaDoc[] params) {
52         if (params.length != 2) {
53             System.out.println("arguments: plan.xml output.svg");
54             return;
55         }
56         try {
57             InputStream JavaDoc is = new java.io.FileInputStream JavaDoc(params[0]);
58             Document JavaDoc doc = createSVGDocument(is);
59             SVGTranscoder svgT = new SVGTranscoder();
60             TranscoderInput input = new TranscoderInput(doc);
61             Writer JavaDoc ostream = new java.io.FileWriter JavaDoc(params[1]);
62             TranscoderOutput output = new TranscoderOutput(ostream);
63             svgT.transcode(input, output);
64             ostream.flush();
65             ostream.close();
66
67         } catch (Exception JavaDoc e) {
68             e.printStackTrace();
69         }
70     }
71
72     /**
73      * Helper method to create the SVG document from the plan InputStream.
74      * @param is InputStream
75      * @return Document a DOM containing the SVG
76      */

77     public Document JavaDoc createSVGDocument(InputStream JavaDoc is) {
78         Document JavaDoc doc = null;
79
80         Element JavaDoc root = null;
81         try {
82             doc = javax.xml.parsers.DocumentBuilderFactory.newInstance().
83                   newDocumentBuilder().parse(is);
84
85             root = doc.getDocumentElement();
86
87         } catch (Exception JavaDoc e) {
88             e.printStackTrace();
89         }
90         PlanRenderer gr = new PlanRenderer();
91         gr.setFontInfo("sansserif", 12);
92         Document JavaDoc svgdoc = gr.createSVGDocument(doc);
93         return svgdoc;
94     }
95 }
96
Popular Tags