source: trunk/gli/src/org/greenstone/gatherer/util/ApplyXSLT.java@ 9045

Last change on this file since 9045 was 6585, checked in by mdewsnip, 20 years ago

Now outputs UTF-8 correctly.

  • Property svn:keywords set to Author Date Id Revision
File size: 3.3 KB
Line 
1/**
2 *#########################################################################
3 *
4 * A component of the Greenstone Librarian Interface (GLI) application,
5 * part of the Greenstone digital library software suite from the New
6 * Zealand Digital Library Project at the University of Waikato,
7 * New Zealand.
8 *
9 * Author: Michael Dewsnip
10 * Greenstone Project, New Zealand Digital Library
11 * University of Waikato
12 * http://www.nzdl.org
13 *
14 * Copyright (C) 2004 New Zealand Digital Library, University of Waikato
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 *########################################################################
30 */
31
32package org.greenstone.gatherer.util;
33
34import java.io.*;
35import javax.xml.transform.Transformer;
36import javax.xml.transform.TransformerFactory;
37import javax.xml.transform.TransformerConfigurationException;
38import javax.xml.transform.TransformerException;
39import javax.xml.transform.stream.StreamSource;
40import javax.xml.transform.stream.StreamResult;
41
42/** Any class that wants to act as the owner of an AppendLineOnlyFileDocument has to implement this.
43 * @author Michael Dewsnip, Greenstone Project, New Zealand Digital Library, University of Waikato
44 * @version 2.41 final
45 */
46public class ApplyXSLT
47{
48 static public void main(String[] args)
49 {
50 if (args.length < 2) {
51 System.err.println("Usage: ApplyXSLT <XSLfile> <XMLfile>");
52 System.exit(1);
53 }
54
55 System.setProperty("javax.xml.transform.TransformerFactory",
56 "org.apache.xalan.processor.TransformerFactoryImpl");
57 TransformerFactory t_factory = null;
58 try {
59 t_factory = org.apache.xalan.processor.TransformerFactoryImpl.newInstance();
60 }
61 catch (Exception ex) {
62 System.err.println("XMLTransformer() exception " + ex.getMessage());
63 System.exit(1);
64 }
65
66 String stylesheet = args[0];
67 String xml_in = args[1];
68 try {
69 // Use the TransformerFactory to process the stylesheet Source and generate a Transformer
70 Transformer transformer = t_factory.newTransformer(new StreamSource(stylesheet));
71
72 // Use the Transformer to transform an XML Source and send the output to a Result object
73 OutputStreamWriter output = new OutputStreamWriter(System.out, "UTF-8");
74 transformer.transform(new StreamSource(xml_in), new StreamResult(output));
75 }
76 catch (TransformerConfigurationException ex) {
77 System.err.println("XMLTransformer: couldn't create transformer object: " + ex.getMessageAndLocation());
78 System.err.println(ex.getLocationAsString());
79 System.exit(1);
80 }
81 catch (Exception ex) {
82 System.err.println("XMLTransformer: couldn't transform the source: " + ex.getMessage());
83 System.exit(1);
84 }
85 }
86}
Note: See TracBrowser for help on using the repository browser.