/* ***************************************************************************** * Main.java * ****************************************************************************/ /* J_LZ_COPYRIGHT_BEGIN ******************************************************* * Copyright 2006 Laszlo Systems, Inc. All Rights Reserved. * * Use is subject to license terms. * * J_LZ_COPYRIGHT_END *********************************************************/ package org.openlaszlo.es4doc; import org.openlaszlo.utils.FileUtils; import org.w3c.dom.Document; import org.apache.log4j.*; import org.apache.log4j.spi.*; import org.apache.log4j.varia.NullAppender; import java.io.*; import java.util.*; public class Main { private static String[] USAGE = { "Usage: js2doc [OPTION]... FILE...", "", "Options:", "-v", " Write progress information to standard output.", "--help", " Prints this message.", "", "Output options:", "--dir outputdir", " Output directory.", }; /** Compiles each file base.ext to the output file base.swf, * writing progress information to standard output. This method * is intended for testing the compiler. * *
See the usage string or execute lzc --help
* to see a list of options.
*
* @param args the command line arguments
*/
public static void main(String args[])
throws IOException
{
es4doc(args, null, null, null);
}
/** This method implements the behavior described in main
* but also returns an integer error code.
*/
public static int es4doc(String args[], String logFile,
String outFileName, String outDir)
throws IOException
{
Logger logger = Logger.getRootLogger();
// Configure logging
logger.setLevel(Level.ERROR);
PatternLayout layout = new PatternLayout("%m%n");
logger.removeAllAppenders();
if (logFile == null) {
logger.addAppender(new ConsoleAppender(layout));
} else {
logger.addAppender(new FileAppender(layout, logFile, false));
}
List files = new Vector();
for (int i = 0; i < args.length; i++) {
String arg = args[i].intern();
if (arg.startsWith("-")) {
if (arg == "-v") {
logger.setLevel(Level.ALL);
} else if (arg == "--help") {
for (int j = 0; j < USAGE.length; j++) {
System.err.println(USAGE[j]);
}
return 0;
} else {
System.err.println("Usage: lzc [OPTION]... file...");
System.err.println("Try `lzc --help' for more information.");
return 1;
}
continue;
}
String sourceName = args[i];
files.add(sourceName);
}
for (Iterator iter = files.iterator(); iter.hasNext(); ) {
String sourceName = (String) iter.next();
if (files.size() > 1)
System.err.println("Compiling " + sourceName);
process(logger, sourceName, outFileName, outDir);
}
return 0;
}
static private void process(Logger logger,
String sourceName,
String outFileName,
String outDir)
{
File sourceFile = new File(sourceName);
if (outFileName == null && outDir == null) {
outFileName = FileUtils.getBase(sourceName) + ".xml";
} else if (outFileName == null) {
outFileName = outDir + File.separator +
FileUtils.getBase(sourceFile.getName()) + ".xml";
}
File scriptFile = new File(outFileName);
try {
String script = "#file " + sourceName + "\n" +
"#line 1\n" + FileUtils.readFileString(scriptFile);
Document descr = ES4Doc.toXML(script);
} catch (IOException e) {
System.err.println("Couldn't read script file");
}
}
}