01: /* Copyright 2001 The JA-SIG Collaborative. All rights reserved.
02: * See license distributed with this file and
03: * available online at http://www.uportal.org/license.html
04: */
05:
06: package org.jasig.portal.tools;
07:
08: import java.io.File;
09: import java.io.FileOutputStream;
10: import java.io.IOException;
11:
12: import org.jasig.portal.PortalException;
13: import org.jasig.portal.utils.XSLT;
14:
15: /**
16: * Title: Run XSLT
17: * Description: applies an xsl stylesheet to an xml file
18: * Company:
19: * @author Susan Bramhall
20: * $Revision: 34945 $
21: */
22:
23: public class RunXSLT {
24:
25: public static void main(String[] args) {
26:
27: File xmlSourceFile = null;
28: FileOutputStream ostream = null;
29: File XslOutputFile = null;
30: String xslUri = null;
31:
32: if (args.length < 3) {
33: System.err
34: .println("Usage \"runXSLT <xmlSource> <xslUri> <outFile>\"");
35: return;
36: }
37: for (int i = 0; i < args.length; i++) {
38: if (!args[i].startsWith("-")) {
39: xmlSourceFile = new File(args[i].trim());
40: System.out.println("xmlSourceFile is "
41: + xmlSourceFile.getAbsolutePath());
42: xslUri = args[++i].trim();
43: System.out.println("xslUri is " + xslUri);
44: XslOutputFile = new File(args[++i].trim());
45: System.out.println("XslOutputFile is "
46: + XslOutputFile.getAbsolutePath());
47: }
48: }
49: XSLT xslt = XSLT.getTransformer(RunXSLT.class);
50:
51: try {
52: ostream = new FileOutputStream(XslOutputFile);
53: } catch (IOException ioe) {
54: System.err.println("Unable to create output file "
55: + XslOutputFile.getName());
56: return;
57: }
58:
59: try {
60: xslt.setXML(xmlSourceFile);
61: xslt.setXSL(xslUri);
62: xslt.setTarget(ostream);
63: xslt.transform();
64: } catch (PortalException pe) {
65: System.err.println("RunXSLT: Error on transform");
66: pe.printStackTrace();
67: }
68:
69: }
70: }
|