| XalanProcess.java |
1 /**
2 * Distribution License:
3 * JSword is free software; you can redistribute it and/or modify it under
4 * the terms of the GNU Lesser General Public License, version 2.1 or later
5 * as published by the Free Software Foundation. This program is distributed
6 * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
7 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
8 * See the GNU Lesser General Public License for more details.
9 *
10 * The License is available on the internet at:
11 * http://www.gnu.org/copyleft/lgpl.html
12 * or by writing to:
13 * Free Software Foundation, Inc.
14 * 59 Temple Place - Suite 330
15 * Boston, MA 02111-1307, USA
16 *
17 * © CrossWire Bible Society, 2005 - 2016
18 *
19 */
20 package org.crosswire.common.xml;
21
22 import java.lang.reflect.InvocationTargetException;
23 import java.lang.reflect.Method;
24
25 import org.crosswire.common.util.ClassUtil;
26
27 /**
28 * Allows xalan's xslt process class to be invoked as a command line
29 * application. Java 5 has renamed the main routine to _main. This class
30 * normalizes the difference between Java 1.4 and 1.5 (aka 5).
31 *
32 * @see gnu.lgpl.License The GNU Lesser General Public License for details.
33 * @author DM Smith
34 */
35 public final class XalanProcess {
36 /**
37 * This is a utility class so the constructor is hidden.
38 */
39 private XalanProcess() {
40 }
41
42 /**
43 * Run xalan's xslt process main.
44 *
45 * @param args the arguments for the xslt process
46 */
47 public static void main(String[] args) {
48 Class<?> clazz = null;
49 Method main = null;
50 try {
51 // Try for 1.5.x
52 clazz = ClassUtil.forName("com.sun.org.apache.xalan.internal.xslt.Process");
53 main = clazz.getMethod("_main", new Class[] { String[].class});
54 } catch (ClassNotFoundException e) {
55 try {
56 // Try for 1.4.x
57 clazz = ClassUtil.forName("org.apache.xalan.xslt.Process");
58 main = clazz.getMethod("main", new Class[] { String[].class});
59 } catch (ClassNotFoundException ex) {
60 ex.printStackTrace(System.err);
61 } catch (SecurityException ex) {
62 ex.printStackTrace(System.err);
63 } catch (NoSuchMethodException ex) {
64 ex.printStackTrace(System.err);
65 }
66 } catch (SecurityException ex) {
67 ex.printStackTrace(System.err);
68 } catch (NoSuchMethodException ex) {
69 ex.printStackTrace(System.err);
70 return;
71 }
72
73 try {
74 if (main != null) {
75 main.invoke(null, (Object[]) args);
76 }
77 } catch (IllegalArgumentException ex) {
78 ex.printStackTrace(System.err);
79 } catch (IllegalAccessException ex) {
80 ex.printStackTrace(System.err);
81 } catch (InvocationTargetException ex) {
82 ex.printStackTrace(System.err);
83 }
84 }
85 }
86