| 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 as published by
5 * the Free Software Foundation. This program is distributed in the hope
6 * that it will be useful, but WITHOUT ANY WARRANTY; without even the
7 * 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 * Copyright: 2005
18 * The copyright to this program is held by it's authors.
19 *
20 * ID: $Id: XalanProcess.java 2090 2011-03-07 04:13:05Z dmsmith $
21 */
22 package org.crosswire.common.xml;
23
24 import java.lang.reflect.InvocationTargetException;
25 import java.lang.reflect.Method;
26
27 import org.crosswire.common.util.ClassUtil;
28
29 /**
30 * Allows xalan's xslt process class to be invoked as a command line
31 * application. Java 5 has renamed the main routine to _main. This class
32 * normalizes the difference between Java 1.4 and 1.5 (aka 5).
33 *
34 * @see gnu.lgpl.License for license details.<br>
35 * The copyright to this program is held by it's authors.
36 * @author DM Smith [dmsmith555 at yahoo dot com]
37 */
38 public class XalanProcess {
39 /**
40 * This is a utility class so the constructor is hidden.
41 */
42 private XalanProcess() {
43 }
44
45 /**
46 * Run xalan's xslt process main.
47 *
48 * @param args
49 */
50 public static void main(String[] args) {
51 Class<?> clazz = null;
52 Method main = null;
53 try {
54 // Try for 1.5.x
55 clazz = ClassUtil.forName("com.sun.org.apache.xalan.internal.xslt.Process");
56 main = clazz.getMethod("_main", new Class[] { String[].class});
57 } catch (ClassNotFoundException e) {
58 try {
59 // Try for 1.4.x
60 clazz = ClassUtil.forName("org.apache.xalan.xslt.Process");
61 main = clazz.getMethod("main", new Class[] { String[].class});
62 } catch (ClassNotFoundException e1) {
63 e1.printStackTrace(System.err);
64 } catch (SecurityException e1) {
65 e1.printStackTrace(System.err);
66 } catch (NoSuchMethodException e1) {
67 e1.printStackTrace(System.err);
68 }
69 } catch (SecurityException e1) {
70 e1.printStackTrace(System.err);
71 } catch (NoSuchMethodException e) {
72 e.printStackTrace(System.err);
73 return;
74 }
75
76 try {
77 if (main != null) {
78 main.invoke(null, (Object[]) args);
79 }
80 } catch (IllegalArgumentException e) {
81 e.printStackTrace(System.err);
82 } catch (IllegalAccessException e) {
83 e.printStackTrace(System.err);
84 } catch (InvocationTargetException e) {
85 e.printStackTrace(System.err);
86 }
87 }
88 }
89