1 4 5 9 10 package org.openlaszlo.xml.internal; 11 12 import java.io.*; 13 import org.apache.log4j.*; 14 import org.apache.log4j.spi.*; 15 import org.apache.log4j.varia.NullAppender; 16 17 import org.jdom.input.SAXBuilder; 18 import org.jdom.Document; 19 import org.jdom.Element; 20 import org.jdom.JDOMException; 21 import org.openlaszlo.utils.FileUtils; 22 import org.openlaszlo.xml.*; 23 24 29 class ErrorChecker extends NullAppender { 30 public boolean hadError = false; 31 public void doAppend(LoggingEvent e) { 32 super.doAppend(e); 33 if (e.level == Level.WARN || 34 e.level == Level.FATAL || 35 e.level == Level.ERROR) { 36 hadError = true; 37 } 38 } 39 } 40 41 44 public class Main { 45 46 53 public static void main(String args[]) { 54 lzdc(args); 55 } 56 57 63 64 public static int lzdc(String [] args) { 65 66 int exitStatus = 0; 67 68 Logger logger = Logger.getRootLogger(); 70 logger.setLevel(Level.ERROR); 71 72 logger.addAppender(new ConsoleAppender( 73 new PatternLayout("%r msecs [%p] - %m%n" ))); 74 75 ErrorChecker errorChecker = new ErrorChecker(); 76 logger.addAppender(errorChecker); 77 78 int swfversionNum = 5; 79 80 try { 81 if (args.length < 2) { 82 System.err.println("Usage: lzdc [-v] [-i] from to"); 83 return -1; 84 } 85 86 for (int i = 0; i < args.length; i++) { 87 String arg = args[i].intern(); 88 if (arg == "-v") { 89 logger.setLevel(Level.ALL); 90 } else if (arg == "-i") { 91 logger.setLevel(Level.INFO); 92 } else if (arg == "-5") { 93 swfversionNum = 5; 94 } else if (arg == "-6") { 95 swfversionNum = 6; 96 } else if (arg == "-7") { 97 swfversionNum = 7; 98 } 99 } 100 101 String fromFileName = args[args.length-2]; 102 String toFileName = args[args.length-1]; 103 104 String xmlstring = FileUtils.readFileString(new File(fromFileName), "UTF-8"); 105 logger.info("Reading XML from " + fromFileName); 107 108 InputStream is = DataCompiler.compile(xmlstring, swfversionNum); 109 FileOutputStream w = new FileOutputStream(toFileName); 110 111 logger.info("Writing to " + toFileName); 112 113 FileUtils.send(is, w); 115 w.flush(); 116 117 logger.info("Done"); 118 119 } catch (DataCompilerException e) { 120 exitStatus = -1; 121 System.err.println("DataCompilerException: " + e.getMessage()); 122 e.printStackTrace(); 123 } catch (IOException e) { 124 exitStatus = -1; 125 System.err.println("IO exception: " + e.getMessage()); 126 e.printStackTrace(); 127 } 128 129 if (errorChecker.hadError) 130 exitStatus = -1; 131 132 return exitStatus; 133 } 134 } 135 | Popular Tags |