~vcs-imports/xena/trunk

« back to all changes in this revision

Viewing changes to ext/src/xalan-j_2_7_1/samples/SimpleTransform/SimpleTransform.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: SimpleTransform.java,v 1.2 2009/12/10 03:18:50 matthewoliver Exp $
 
20
 */
 
21
 
 
22
import java.io.FileNotFoundException;
 
23
import java.io.FileOutputStream;
 
24
import java.io.IOException;
 
25
 
 
26
import javax.xml.transform.Transformer;
 
27
import javax.xml.transform.TransformerConfigurationException;
 
28
import javax.xml.transform.TransformerException;
 
29
import javax.xml.transform.TransformerFactory;
 
30
import javax.xml.transform.stream.StreamResult;
 
31
import javax.xml.transform.stream.StreamSource;
 
32
 
 
33
/**
 
34
 *  Use the TraX interface to perform a transformation in the simplest manner possible
 
35
 *  (3 statements).
 
36
 */
 
37
public class SimpleTransform
 
38
{
 
39
        public static void main(String[] args)
 
40
    throws TransformerException, TransformerConfigurationException, 
 
41
           FileNotFoundException, IOException
 
42
  {  
 
43
  // Use the static TransformerFactory.newInstance() method to instantiate 
 
44
  // a TransformerFactory. The javax.xml.transform.TransformerFactory 
 
45
  // system property setting determines the actual class to instantiate --
 
46
  // org.apache.xalan.transformer.TransformerImpl.
 
47
        TransformerFactory tFactory = TransformerFactory.newInstance();
 
48
        
 
49
        // Use the TransformerFactory to instantiate a Transformer that will work with  
 
50
        // the stylesheet you specify. This method call also processes the stylesheet
 
51
  // into a compiled Templates object.
 
52
        Transformer transformer = tFactory.newTransformer(new StreamSource("birds.xsl"));
 
53
 
 
54
        // Use the Transformer to apply the associated Templates object to an XML document
 
55
        // (foo.xml) and write the output to a file (foo.out).
 
56
        transformer.transform(new StreamSource("birds.xml"), new StreamResult(new FileOutputStream("birds.out")));
 
57
        
 
58
        System.out.println("************* The result is in birds.out *************");
 
59
  }
 
60
}