KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > Compile


1 /*
2  * Copyright 2001-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 /*
17  * $Id: Compile.java,v 1.5 2004/02/17 19:05:08 minchau Exp $
18  */

19
20 import javax.xml.transform.Templates JavaDoc;
21 import javax.xml.transform.TransformerFactory JavaDoc;
22 import javax.xml.transform.stream.StreamSource JavaDoc;
23
24 public class Compile {
25
26     public static void main(String JavaDoc[] args){
27         Compile app = new Compile();
28         app.run(args[0]);
29     }
30
31     /**
32      * Compiles an XSL stylesheet into a translet, wraps the translet
33      * inside a Templates object and dumps it to a file.
34      */

35     public void run(String JavaDoc xsl) {
36         try {
37             // Set XSLTC's TransformerFactory implementation as the default
38
System.setProperty("javax.xml.transform.TransformerFactory",
39                          "org.apache.xalan.xsltc.trax.TransformerFactoryImpl");
40
41         // Get an input stream for the XSL stylesheet
42
StreamSource JavaDoc stylesheet = new StreamSource JavaDoc(xsl);
43
44         // The TransformerFactory will compile the stylesheet and
45
// put the translet classes inside the Templates object
46
TransformerFactory JavaDoc factory = TransformerFactory.newInstance();
47             factory.setAttribute("generate-translet", Boolean.TRUE);
48         Templates JavaDoc templates = factory.newTemplates(stylesheet);
49         }
50     catch (Exception JavaDoc e) {
51             System.err.println("Exception: " + e);
52         e.printStackTrace();
53         }
54         System.exit(0);
55     }
56
57     private void usage() {
58         System.err.println("Usage: compile <xsl_file>");
59         System.exit(1);
60     }
61
62 }
63
Popular Tags