/[Apache-SVN]/xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleObj2XML.java
ViewVC logotype

Contents of /xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleObj2XML.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 679326 - (show annotations)
Thu Jul 24 09:35:34 2008 UTC (16 months ago) by vhennebert
File size: 4143 byte(s)
Fed up with all those trailing whitespaces. Let's remove them all (once... and for all?)
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$ */
19
20 package embedding;
21
22 //Hava
23 import java.io.File;
24 import java.io.IOException;
25
26 //JAXP
27 import javax.xml.transform.Transformer;
28 import javax.xml.transform.TransformerFactory;
29 import javax.xml.transform.TransformerException;
30 import javax.xml.transform.Source;
31 import javax.xml.transform.Result;
32 import javax.xml.transform.stream.StreamResult;
33
34 import embedding.model.ProjectMember;
35 import embedding.model.ProjectTeam;
36
37
38 /**
39 * This class demonstrates the conversion of an arbitrary object file to an
40 * XML file.
41 */
42 public class ExampleObj2XML {
43
44 /**
45 * Converts a ProjectTeam object to XML.
46 * @param team the ProjectTeam object
47 * @param xml the target XML file
48 * @throws IOException In case of an I/O problem
49 * @throws TransformerException In case of a XSL transformation problem
50 */
51 public void convertProjectTeam2XML(ProjectTeam team, File xml)
52 throws IOException, TransformerException {
53
54 //Setup XSLT
55 TransformerFactory factory = TransformerFactory.newInstance();
56 Transformer transformer = factory.newTransformer();
57 /* Note:
58 We use the identity transformer, no XSL transformation is done.
59 The transformer is basically just used to serialize the
60 generated document to XML. */
61
62 //Setup input
63 Source src = team.getSourceForProjectTeam();
64
65 //Setup output
66 Result res = new StreamResult(xml);
67
68 //Start XSLT transformation
69 transformer.transform(src, res);
70 }
71
72
73 /**
74 * Creates a sample ProjectTeam instance for this demo.
75 * @return ProjectTeam the newly created ProjectTeam instance
76 */
77 public static ProjectTeam createSampleProjectTeam() {
78 ProjectTeam team = new ProjectTeam();
79 team.setProjectName("Rule the Galaxy");
80 team.addMember(new ProjectMember(
81 "Emperor Palpatine", "lead", "palpatine@empire.gxy"));
82 team.addMember(new ProjectMember(
83 "Lord Darth Vader", "Jedi-Killer", "vader@empire.gxy"));
84 team.addMember(new ProjectMember(
85 "Grand Moff Tarkin", "Planet-Killer", "tarkin@empire.gxy"));
86 team.addMember(new ProjectMember(
87 "Admiral Motti", "Death Star operations", "motti@empire.gxy"));
88 return team;
89 }
90
91
92 /**
93 * Main method.
94 * @param args command-line arguments
95 */
96 public static void main(String[] args) {
97 try {
98 System.out.println("FOP ExampleObj2XML\n");
99 System.out.println("Preparing...");
100
101 //Setup directories
102 File baseDir = new File(".");
103 File outDir = new File(baseDir, "out");
104 outDir.mkdirs();
105
106 //Setup input and output
107 File xmlfile = new File(outDir, "ResultObj2XML.xml");
108
109 System.out.println("Input: a ProjectTeam object");
110 System.out.println("Output: XML (" + xmlfile + ")");
111 System.out.println();
112 System.out.println("Serializing...");
113
114 ExampleObj2XML app = new ExampleObj2XML();
115 app.convertProjectTeam2XML(createSampleProjectTeam(), xmlfile);
116
117 System.out.println("Success!");
118 } catch (Exception e) {
119 e.printStackTrace(System.err);
120 System.exit(-1);
121 }
122 }
123 }

Properties

Name Value
svn:eol-style native
svn:keywords Id

apache@apache.org
ViewVC Help
Powered by ViewVC 1.1.2