1 16 19 20 package org.apache.xalan.xsltc.cmdline; 21 22 import java.io.File ; 23 import java.net.URL ; 24 import java.util.Vector ; 25 26 import org.apache.xalan.xsltc.cmdline.getopt.GetOpt; 27 import org.apache.xalan.xsltc.cmdline.getopt.GetOptsException; 28 import org.apache.xalan.xsltc.compiler.XSLTC; 29 import org.apache.xalan.xsltc.compiler.util.ErrorMsg; 30 31 37 public final class Compile { 38 39 private static int VERSION_MAJOR = 1; 41 private static int VERSION_MINOR = 4; 42 private static int VERSION_DELTA = 0; 43 44 45 private static boolean _allowExit = true; 50 51 public static void printUsage() { 52 StringBuffer vers = new StringBuffer ("XSLTC version " + 53 VERSION_MAJOR + "." + VERSION_MINOR + 54 ((VERSION_DELTA > 0) ? ("."+VERSION_DELTA) : (""))); 55 System.err.println(vers + "\n" + 56 new ErrorMsg(ErrorMsg.COMPILE_USAGE_STR)); 57 if (_allowExit) System.exit(-1); 58 } 59 60 67 public static void main(String [] args) { 68 try { 69 boolean inputIsURL = false; 70 boolean useStdIn = false; 71 boolean classNameSet = false; 72 final GetOpt getopt = new GetOpt(args, "o:d:j:p:uxhsinv"); 73 if (args.length < 1) printUsage(); 74 75 final XSLTC xsltc = new XSLTC(); 76 xsltc.init(); 77 78 int c; 79 while ((c = getopt.getNextOption()) != -1) { 80 switch(c) { 81 case 'i': 82 useStdIn = true; 83 break; 84 case 'o': 85 xsltc.setClassName(getopt.getOptionArg()); 86 classNameSet = true; 87 break; 88 case 'd': 89 xsltc.setDestDirectory(getopt.getOptionArg()); 90 break; 91 case 'p': 92 xsltc.setPackageName(getopt.getOptionArg()); 93 break; 94 case 'j': 95 xsltc.setJarFileName(getopt.getOptionArg()); 96 break; 97 case 'x': 98 xsltc.setDebug(true); 99 break; 100 case 'u': 101 inputIsURL = true; 102 break; 103 case 's': 104 _allowExit = false; 105 break; 106 case 'n': 107 xsltc.setTemplateInlining(true); break; 109 case 'v': 110 case 'h': 112 default: 113 printUsage(); 114 break; 115 } 116 } 117 118 boolean compileOK; 119 120 if (useStdIn) { 121 if (!classNameSet) { 122 System.err.println(new ErrorMsg(ErrorMsg.COMPILE_STDIN_ERR)); 123 if (_allowExit) System.exit(-1); 124 } 125 compileOK = xsltc.compile(System.in, xsltc.getClassName()); 126 } 127 else { 128 final String [] stylesheetNames = getopt.getCmdArgs(); 130 final Vector stylesheetVector = new Vector (); 131 for (int i = 0; i < stylesheetNames.length; i++) { 132 final String name = stylesheetNames[i]; 133 URL url; 134 if (inputIsURL) 135 url = new URL (name); 136 else 137 url = (new File (name)).toURL(); 138 stylesheetVector.addElement(url); 139 } 140 compileOK = xsltc.compile(stylesheetVector); 141 } 142 143 if (compileOK) { 145 xsltc.printWarnings(); 146 if (xsltc.getJarFileName() != null) xsltc.outputToJar(); 147 if (_allowExit) System.exit(0); 148 } 149 else { 150 xsltc.printWarnings(); 151 xsltc.printErrors(); 152 if (_allowExit) System.exit(-1); 153 } 154 } 155 catch (GetOptsException ex) { 156 System.err.println(ex); 157 printUsage(); } 159 catch (Exception e) { 160 e.printStackTrace(); 161 if (_allowExit) System.exit(-1); 162 } 163 } 164 165 } 166 | Popular Tags |