From: Mike H. <he...@us...> - 2002-07-08 22:55:59
|
Update of /cvsroot/javadocbook/javadocbook/src/net/sf/javadocbook In directory usw-pr-cvs1:/tmp/cvs-serv25549/net/sf/javadocbook Modified Files: Main.java Log Message: Merged my changes with Devin's patch. Index: Main.java =================================================================== RCS file: /cvsroot/javadocbook/javadocbook/src/net/sf/javadocbook/Main.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** Main.java 8 Jul 2002 22:40:08 -0000 1.14 --- Main.java 8 Jul 2002 22:55:56 -0000 1.15 *************** *** 18,22 **** * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ! * Copyright 2002, Mike Heath * * Main.java --- 18,22 ---- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ! * Copyright 2002, Mike Heath, Devin Weaver * * Main.java *************** *** 39,42 **** --- 39,43 ---- import java.io.OutputStream; import java.net.URL; + import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; *************** *** 51,63 **** import org.w3c.dom.Document; import org.xml.sax.SAXException; ! import org.apache.commons.cli.Options; import org.apache.commons.cli.CommandLine; - import org.apache.commons.cli.ParseException; import org.apache.commons.cli.HelpFormatter; /** * Does a simple XSLT transform. * ! * @author he...@us... * @version $Revision$ */ --- 52,66 ---- import org.w3c.dom.Document; import org.xml.sax.SAXException; ! import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.HelpFormatter; + import org.apache.commons.cli.Options; + import org.apache.commons.cli.ParseException; /** * Does a simple XSLT transform. * ! * @author Mike Heath (heathm at users.sourceforge.net) ! * @author Devin Weaver (ktohg at users.sourceforge.net) * @version $Revision$ */ *************** *** 111,114 **** --- 114,123 ---- } + public static void showUsage(Options options) { + HelpFormatter help = new HelpFormatter(); + help.printHelp("java -jar javadocbook.jar [options] docbook_file", "Where options are:", options, + "For more information go to: http://sourceforge.net/projects/javadocbook/"); + } + private static void argumentError( String message, int error_code ) { System.out.println(message); *************** *** 117,220 **** } - private static void showUsage( Options opts ) { - HelpFormatter help = new HelpFormatter(); - help.printHelp("java -jar javadocbook.jar [options] xml_data", - "\nwhere options include:", opts, ""); - // This footer was easier to format manually then through HelpFormatter. - System.out.println(); - System.out.println("Known types:"); - System.out.println(PARAM_FO + "\t- Transforms Docbook XML to FO XML (for PDF converstion)"); - System.out.println(PARAM_HTML + "\t- Transforms Docbook XML to HTML"); - System.out.println(PARAM_XHTML + "\t- Transforms Docbook XML to XHTML"); - System.out.println(); - System.out.println("For more information visit the project homepage at:"); - // This really should be http://javadocbook.sourceforge.net/ when the site gets updated. - System.out.println("http://sourceforge.net/projects/javadocbook/"); - /* Old links - System.out.println("For more information go to: http://sourceforge.net/projects/javadocbook/"); - System.out.println("To log a bug, go to: http://sourceforge.net/tracker/?func=add&group_id=47837&atid=451047"); - System.out.println("To request a feature, go to: http://sourceforge.net/tracker/?func=add&group_id=47837&atid=451050"); - */ - } - public static void main(String args[]) { - String xmlData = null; - String output = null; - boolean force = false; - String styleSheet = HTML_STYLE_SHEET; - - Options options = new Options(); - options.addOption('t', "type", true, "Specifies the type of transform to be done."); - options.addOption('o', "output", true, "Specifies the output file to send the output to. " - + "If no file is specified standard output is used."); - options.addOption('f', "force", false, "Force recreation of output file. If the output file exists and is " - + "newer than the source XML file. Default is not to overwrite file."); - options.addOption('h', "help", false, "Displays this help message."); - // Option defaults are set above. try { ! CommandLine cmd = options.parse(args, true); ! // See what options we have ! if (cmd.hasOption('h')) { showUsage(options); ! System.exit(127); ! } ! if (cmd.hasOption('t')) { ! String type = cmd.getOptionValue('t'); ! if (type.equalsIgnoreCase(PARAM_FO)) { ! styleSheet = FO_STYLE_SHEET; ! } else if (type.equalsIgnoreCase(PARAM_HTML)) { ! styleSheet = HTML_STYLE_SHEET; ! } else if (type.equalsIgnoreCase(PARAM_XHTML)) { ! styleSheet = XHTML_STYLE_SHEET; ! } else { ! // User might need help here. ! argumentError("Unknown type '" + type + "'.", 2); ! } ! type = null; } ! if (cmd.hasOption('o')) { ! output = cmd.getOptionValue('o'); } ! if (cmd.hasOption('f')) { ! force = true; } ! if (cmd.getArgs().length == 1) { ! xmlData = cmd.getArgs()[0]; ! } else { ! argumentError("Incorrect number of arguments.", 2); } } catch (ParseException e) { argumentError(e.getMessage(), 2); - } - - InputStream in; - OutputStream out; - try { - File xmlFile = new File(xmlData); - in = new FileInputStream(xmlFile); - if (output == null) { - out = System.out; - } else { - File outFile = new File(output); - // Check to see if output file is newer than xml data and if so, do nothing. - if (!force && outFile.isFile() && outFile.lastModified() > xmlFile.lastModified()) - return; - out = new FileOutputStream(outFile); - } - } catch (FileNotFoundException e) { - System.err.println(e.getLocalizedMessage()); - return; - } - // Use a URL to get the stylesheet since the stylesheet will be stored in a .jar - URL styleSheetURL = new Object().getClass().getResource(styleSheet); - if (styleSheetURL == null) - throw new RuntimeException("Could not find style sheet: " + styleSheet); - - try { - transform(in, out, styleSheetURL); } catch (Exception e) { e.printStackTrace(); - System.err.println(); - System.err.println("Make sure you have JAXP installed and that it's in your class path."); } } --- 126,201 ---- } public static void main(String args[]) { try { ! Options options = new Options(); ! options.addOption('f', "force", false, "Force recreation of output file. If the output file exists and " + ! "is newer than the source XML file, nothing happens unless this " + ! "option is used."); ! options.addOption('h', "help", false, "Shows this help message."); ! options.addOption('o', "output", true, "File to write output to. If omitted, standard output is used."); ! options.addOption('t', "type", true, "Specifies type of output to be created. Possible values are: " + ! PARAM_FO + ", " + PARAM_HTML + " or " + PARAM_XHTML); ! ! CommandLine cmds = options.parse(args); ! ! boolean force = cmds.hasOption('f'); ! ! if (cmds.hasOption('h')) { showUsage(options); ! return; } ! ! String output = cmds.getOptionValue('o'); ! ! String styleSheet = null; ! String type = cmds.getOptionValue('t', PARAM_HTML); ! if (type.equalsIgnoreCase(PARAM_FO)) { ! styleSheet = FO_STYLE_SHEET; ! } else if (type.equalsIgnoreCase(PARAM_HTML)) { ! styleSheet = HTML_STYLE_SHEET; ! } else if (type.equalsIgnoreCase(PARAM_XHTML)) { ! styleSheet = XHTML_STYLE_SHEET; ! } else { ! argumentError("Unrecognized type: " + type, 2); } ! ! String docbookFile = null; ! try { ! docbookFile = cmds.getArgs()[0]; ! } catch (ArrayIndexOutOfBoundsException e) {} ! if (docbookFile == null) { ! argumentError("Incorreect number of arguments", 2); ! return; } ! ! InputStream in; ! OutputStream out; ! try { ! File xmlFile = new File(docbookFile); ! in = new FileInputStream(xmlFile); ! if (output == null) { ! out = System.out; ! } else { ! File outFile = new File(output); ! // Check to see if output file is newer than xml data and if so, do nothing. ! if (!force && outFile.isFile() && outFile.lastModified() > xmlFile.lastModified()) ! return; ! out = new FileOutputStream(outFile); ! } ! } catch (FileNotFoundException e) { ! System.err.println(e.getLocalizedMessage()); ! return; } + // Use a URL to get the stylesheet since the stylesheet will be stored in a .jar + URL styleSheetURL = new Object().getClass().getResource(styleSheet); + if (styleSheetURL == null) + throw new RuntimeException("Could not find style sheet: " + styleSheet); + + transform(in, out, styleSheetURL); } catch (ParseException e) { argumentError(e.getMessage(), 2); } catch (Exception e) { + System.err.println(e.getMessage()); e.printStackTrace(); } } *************** *** 223,226 **** --- 204,210 ---- /* * $Log$ + * Revision 1.15 2002/07/08 22:55:56 heathm + * Merged my changes with Devin's patch. + * * Revision 1.14 2002/07/08 22:40:08 heathm * Applied Main.java.diff patch from patch 578288. |