KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > config > serverbeans > validation > SimpleTransform


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.config.serverbeans.validation;
25
26 import javax.xml.transform.TransformerFactory JavaDoc;
27 import javax.xml.transform.sax.SAXSource JavaDoc;
28 import javax.xml.transform.Source JavaDoc;
29 import javax.xml.transform.Transformer JavaDoc;
30 import org.xml.sax.InputSource JavaDoc;
31 import java.io.FileReader JavaDoc;
32 import javax.xml.transform.Result JavaDoc;
33 import javax.xml.transform.stream.StreamSource JavaDoc;
34 import javax.xml.transform.stream.StreamResult JavaDoc;
35 import java.io.File JavaDoc;
36
37
38
39 public class SimpleTransform
40 {
41     public static void main(String JavaDoc [] args) throws Exception JavaDoc {
42         String JavaDoc in = null;
43         String JavaDoc xsl = null;
44         String JavaDoc out = null;
45         
46         if (args.length != 6){
47             System.err.println("Insufficient args: SimpleTransform -in file -xsl file -out file");
48             System.exit(1);
49         }
50
51         for (int i = 0; i < args.length; i++){
52             if (args[i].equals("-in")){
53                 in = args[++i];
54             } else if (args[i].equals("-xsl")){
55                 xsl = args[++i];
56             } else if (args[i].equals("-out")){
57                 out = args[++i];
58             } else {
59                 System.err.println("Unrecognized arg: "+args[i]);
60                 System.exit(1);
61             }
62         }
63         
64
65         final TransformerFactory JavaDoc f = TransformerFactory.newInstance();
66         final Transformer JavaDoc t = f.newTransformer(new StreamSource JavaDoc(new File JavaDoc(xsl)));
67 // final Source src = new SAXSource(XMLReaderFactory.newInstance(System.err),
68
// new InputSource(in));
69
final Source JavaDoc src = new SAXSource JavaDoc(new VariableResolver(),
70                                    new InputSource JavaDoc(in));
71         final Result res = new StreamResult JavaDoc(out);
72         
73         t.transform(src, res);
74     }
75     
76
77 }
78
Popular Tags