~vcs-imports/xena/trunk

« back to all changes in this revision

Viewing changes to ext/src/xalan-j_2_7_1/samples/translets/JAXPTransletOneTransformation.java

  • Committer: matthewoliver
  • Date: 2009-12-10 03:18:07 UTC
  • Revision ID: vcs-imports@canonical.com-20091210031807-l086qguzdlljtkl9
Merged Xena Testing into Xena Stable for the Xena 5 release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Licensed to the Apache Software Foundation (ASF) under one
 
3
 * or more contributor license agreements. See the NOTICE file
 
4
 * distributed with this work for additional information
 
5
 * regarding copyright ownership. The ASF licenses this file
 
6
 * to you under the Apache License, Version 2.0 (the  "License");
 
7
 * you may not use this file except in compliance with the License.
 
8
 * You may obtain a copy of the License at
 
9
 *
 
10
 *     http://www.apache.org/licenses/LICENSE-2.0
 
11
 *
 
12
 * Unless required by applicable law or agreed to in writing, software
 
13
 * distributed under the License is distributed on an "AS IS" BASIS,
 
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
15
 * See the License for the specific language governing permissions and
 
16
 * limitations under the License.
 
17
 */
 
18
/*
 
19
 * $Id: JAXPTransletOneTransformation.java,v 1.2 2009/12/10 03:18:41 matthewoliver Exp $
 
20
 */
 
21
import java.io.FileNotFoundException;
 
22
import java.io.FileOutputStream;
 
23
import java.io.IOException;
 
24
 
 
25
import java.util.Properties;
 
26
 
 
27
import javax.xml.parsers.ParserConfigurationException;
 
28
import javax.xml.transform.Transformer;
 
29
import javax.xml.transform.TransformerConfigurationException;
 
30
import javax.xml.transform.TransformerException;
 
31
import javax.xml.transform.TransformerFactory;
 
32
import javax.xml.transform.stream.StreamResult;
 
33
import javax.xml.transform.stream.StreamSource;
 
34
 
 
35
import org.xml.sax.SAXException;
 
36
 
 
37
 
 
38
/**
 
39
 * Using the TrAX/JAXP 1.1 interface to compile and run a translet. The translet
 
40
 * extends the abstract Transformer class and is used to perform a single
 
41
 * transformation. If you want to use the translet to perform multiple 
 
42
 * transformations, see JAXPTransletMultipleTransformations.java.
 
43
 * 
 
44
 * @author Donald Leslie
 
45
 */
 
46
public class JAXPTransletOneTransformation
 
47
{
 
48
  public static void main(String argv[])
 
49
          throws TransformerException, TransformerConfigurationException, IOException, SAXException,
 
50
                 ParserConfigurationException, FileNotFoundException
 
51
  { 
 
52
    // Set the TransformerFactory system property to generate and use a translet.
 
53
    // Note: To make this sample more flexible, load properties from a properties file.    
 
54
    // The setting for the Xalan Transformer is "org.apache.xalan.processor.TransformerFactoryImpl"
 
55
    String key = "javax.xml.transform.TransformerFactory";
 
56
    String value = "org.apache.xalan.xsltc.trax.TransformerFactoryImpl";
 
57
    Properties props = System.getProperties();
 
58
    props.put(key, value);
 
59
    System.setProperties(props);    
 
60
 
 
61
    String xslInURI = "todo.xsl";
 
62
    String xmlInURI = "todo.xml";
 
63
    String htmlOutURI = "todo.html";
 
64
    try
 
65
    {
 
66
      // Instantiate the TransformerFactory, and use it along with a SteamSource
 
67
      // XSL stylesheet to create a Transformer.
 
68
      TransformerFactory tFactory = TransformerFactory.newInstance();
 
69
      Transformer transformer = tFactory.newTransformer(new StreamSource(xslInURI));
 
70
      // Perform the transformation from a StreamSource to a StreamResult;
 
71
      transformer.transform(new StreamSource(xmlInURI),
 
72
                            new StreamResult(new FileOutputStream(htmlOutURI)));  
 
73
      System.out.println("Produced todo.html");  
 
74
    }
 
75
    catch (Exception e) 
 
76
    {
 
77
     System.out.println(e.toString());
 
78
     e.printStackTrace();
 
79
    }      
 
80
  }
 
81
}