diff options
author | Keiron Liddle <keiron@apache.org> | 2001-08-20 11:19:24 +0000 |
---|---|---|
committer | Keiron Liddle <keiron@apache.org> | 2001-08-20 11:19:24 +0000 |
commit | 4daeb7896ffdcf2a1c3303d6b41103d05f1a9014 (patch) | |
tree | eead5682967b118e1e8b19bdb59d6d7c6e8f1e08 /src/org/apache/fop/apps | |
parent | c1c2792e38fe0a0567b4bcf1c3f782e757fa846e (diff) | |
download | xmlgraphics-fop-4daeb7896ffdcf2a1c3303d6b41103d05f1a9014.tar.gz xmlgraphics-fop-4daeb7896ffdcf2a1c3303d6b41103d05f1a9014.zip |
changed to logkit for logging only half done
fixed getContentHandler in driver
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@194430 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/org/apache/fop/apps')
-rw-r--r-- | src/org/apache/fop/apps/CommandLineOptions.java | 128 | ||||
-rw-r--r-- | src/org/apache/fop/apps/CommandLineStarter.java | 17 | ||||
-rw-r--r-- | src/org/apache/fop/apps/Driver.java | 50 | ||||
-rw-r--r-- | src/org/apache/fop/apps/PDFOutputHandler.java | 4 | ||||
-rw-r--r-- | src/org/apache/fop/apps/Starter.java | 7 | ||||
-rw-r--r-- | src/org/apache/fop/apps/StreamRenderer.java | 27 | ||||
-rw-r--r-- | src/org/apache/fop/apps/XTDriver.java | 5 |
7 files changed, 158 insertions, 80 deletions
diff --git a/src/org/apache/fop/apps/CommandLineOptions.java b/src/org/apache/fop/apps/CommandLineOptions.java index c13e65518..5bb0d700d 100644 --- a/src/org/apache/fop/apps/CommandLineOptions.java +++ b/src/org/apache/fop/apps/CommandLineOptions.java @@ -17,6 +17,13 @@ import org.apache.fop.messaging.MessageHandler; import org.apache.fop.configuration.Configuration; import org.apache.fop.apps.FOPException; +import org.apache.log.*; +import org.apache.log.format.*; +import org.apache.log.output.io.*; +import org.apache.log.output.*; + +import java.io.*; + /** * Options parses the commandline arguments */ @@ -80,8 +87,30 @@ public class CommandLineOptions { private java.util.Hashtable rendererOptions; + private Logger log; + public CommandLineOptions(String[] args) throws FOPException, FileNotFoundException { + + Hierarchy hierarchy = Hierarchy.getDefaultHierarchy(); + PatternFormatter formatter = new PatternFormatter( + "[%{priority}]: %{message}\n%{throwable}" ); + + LogTarget target = null; + boolean doConsoleLogging = true; + if (doConsoleLogging) { + target = new StreamTarget(System.out, formatter); + } else { + try { + File f = new File("fop.log"); + target = new FileTarget(f, false, formatter); + } catch (IOException e) {} + } + + hierarchy.setDefaultLogTarget(target); + log = hierarchy.getLoggerFor("fop"); + log.setPriority(Priority.INFO); + boolean optionsParsed = true; rendererOptions = new java.util.Hashtable(); try { @@ -232,12 +261,12 @@ public class CommandLineOptions { if (buffermode == NOT_SET) { buffermode = BUFFER_FILE; } else { - MessageHandler.errorln("ERROR: you can only set one buffer method"); + log.error("you can only set one buffer method"); printUsage(); } if ((i + 1 == args.length) || (args[i + 1].charAt(0) == '-')) { - MessageHandler.errorln("ERROR: you must specify the buffer output file"); + log.error("you must specify the buffer output file"); printUsage(); } else { bufferFile = new File(args[i + 1]); @@ -291,7 +320,7 @@ public class CommandLineOptions { // warning if fofile has been set in xslt mode if (fofile != null) { - MessageHandler.errorln("WARNING: Can't use fo file with transform mode! Ignoring.\n" + log.warn("Can't use fo file with transform mode! Ignoring.\n" + "Your input is " + "\n xmlfile: " + xmlfile.getAbsolutePath() + "\nxsltfile: " @@ -312,9 +341,9 @@ public class CommandLineOptions { } else if (inputmode == FO_INPUT) { if (xmlfile != null || xsltfile != null) { - MessageHandler.errorln("WARNING: fo input mode, but xmlfile or xslt file are set:"); - MessageHandler.errorln("xml file: " + xmlfile.toString()); - MessageHandler.errorln("xslt file: " + xsltfile.toString()); + log.warn("fo input mode, but xmlfile or xslt file are set:"); + log.error("xml file: " + xmlfile.toString()); + log.error("xslt file: " + xsltfile.toString()); } if (!fofile.exists()) { throw new FileNotFoundException("fo file " @@ -373,10 +402,11 @@ public class CommandLineOptions { } public Starter getStarter() throws FOPException { + Starter starter = null; switch (outputmode) { case AWT_OUTPUT: try { - return ((Starter)Class.forName("org.apache.fop.apps.AWTStarter").getConstructor(new Class[] { + starter = ((Starter)Class.forName("org.apache.fop.apps.AWTStarter").getConstructor(new Class[] { CommandLineOptions.class }).newInstance(new Object[] { this @@ -389,7 +419,7 @@ public class CommandLineOptions { } case PRINT_OUTPUT: try { - return ((Starter)Class.forName("org.apache.fop.apps.PrintStarter").getConstructor(new Class[] { + starter = ((Starter)Class.forName("org.apache.fop.apps.PrintStarter").getConstructor(new Class[] { CommandLineOptions.class }).newInstance(new Object[] { this @@ -403,8 +433,10 @@ public class CommandLineOptions { } default: - return new CommandLineStarter(this); + starter = new CommandLineStarter(this); } + starter.setLogger(log); + return starter; } public int getInputMode() { @@ -477,7 +509,7 @@ public class CommandLineOptions { * shows the commandline syntax including a summary of all available options and some examples */ public static void printUsage() { - MessageHandler.errorln("\nUSAGE\nFop [options] [-fo|-xml] infile [-xsl file] [-awt|-pdf|-mif|-pcl|-ps|-txt|-at|-print] <outfile>\n" + System.err.println("\nUSAGE\nFop [options] [-fo|-xml] infile [-xsl file] [-awt|-pdf|-mif|-pcl|-ps|-txt|-at|-print] <outfile>\n" + " [OPTIONS] \n" + " -d debug mode \n" + " -x dump configuration settings \n" @@ -513,7 +545,7 @@ public class CommandLineOptions { * shows the options for print output */ public void printUsagePrintOutput() { - MessageHandler.errorln("USAGE: -print [-Dstart=i] [-Dend=i] [-Dcopies=i] [-Deven=true|false] " + System.err.println("USAGE: -print [-Dstart=i] [-Dend=i] [-Dcopies=i] [-Deven=true|false] " + " org.apache.fop.apps.Fop (..) -print \n" + "Example:\n" + "java -Dstart=1 -Dend=2 org.apache.Fop.apps.Fop infile.fo -print "); @@ -524,88 +556,88 @@ public class CommandLineOptions { * debug mode. outputs all commandline settings */ private void debug() { - System.out.print("Input mode: "); + log.debug("Input mode: "); switch (inputmode) { case NOT_SET: - MessageHandler.logln("not set"); + log.debug("not set"); break; case FO_INPUT: - MessageHandler.logln("FO "); - MessageHandler.logln("fo input file: " + fofile.toString()); + log.debug("FO "); + log.debug("fo input file: " + fofile.toString()); break; case XSLT_INPUT: - MessageHandler.logln("xslt transformation"); - MessageHandler.logln("xml input file: " + xmlfile.toString()); - MessageHandler.logln("xslt stylesheet: " + xsltfile.toString()); + log.debug("xslt transformation"); + log.debug("xml input file: " + xmlfile.toString()); + log.debug("xslt stylesheet: " + xsltfile.toString()); break; default: - MessageHandler.logln("unknown input type"); + log.debug("unknown input type"); } - System.out.print("Output mode: "); + log.debug("Output mode: "); switch (outputmode) { case NOT_SET: - MessageHandler.logln("not set"); + log.debug("not set"); break; case PDF_OUTPUT: - MessageHandler.logln("pdf"); - MessageHandler.logln("output file: " + outfile.toString()); + log.debug("pdf"); + log.debug("output file: " + outfile.toString()); break; case AWT_OUTPUT: - MessageHandler.logln("awt on screen"); + log.debug("awt on screen"); if (outfile != null) { - MessageHandler.logln("ERROR: awt mode, but outfile is set:"); - MessageHandler.logln("out file: " + outfile.toString()); + log.error("awt mode, but outfile is set:"); + log.debug("out file: " + outfile.toString()); } break; case MIF_OUTPUT: - MessageHandler.logln("mif"); - MessageHandler.logln("output file: " + outfile.toString()); + log.debug("mif"); + log.debug("output file: " + outfile.toString()); break; case PRINT_OUTPUT: - MessageHandler.logln("print directly"); + log.debug("print directly"); if (outfile != null) { - MessageHandler.logln("ERROR: print mode, but outfile is set:"); - MessageHandler.logln("out file: " + outfile.toString()); + log.error("print mode, but outfile is set:"); + log.error("out file: " + outfile.toString()); } break; case PCL_OUTPUT: - MessageHandler.logln("pcl"); - MessageHandler.logln("output file: " + outfile.toString()); + log.debug("pcl"); + log.debug("output file: " + outfile.toString()); break; case PS_OUTPUT: - MessageHandler.logln("PostScript"); - MessageHandler.logln("output file: " + outfile.toString()); + log.debug("PostScript"); + log.debug("output file: " + outfile.toString()); break; case TXT_OUTPUT: - MessageHandler.logln("txt"); - MessageHandler.logln("output file: " + outfile.toString()); + log.debug("txt"); + log.debug("output file: " + outfile.toString()); break; default: - MessageHandler.logln("unknown input type"); + log.debug("unknown input type"); } - MessageHandler.logln("OPTIONS"); + log.debug("OPTIONS"); if (userConfigFile != null) { - MessageHandler.logln("user configuration file: " + log.debug("user configuration file: " + userConfigFile.toString()); } else { - MessageHandler.logln("no user configuration file is used [default]"); + log.debug("no user configuration file is used [default]"); } if (errorDump != null) { - MessageHandler.logln("debug mode on"); + log.debug("debug mode on"); } else { - MessageHandler.logln("debug mode off [default]"); + log.debug("debug mode off [default]"); } if (dumpConfiguration != null) { - MessageHandler.logln("dump configuration"); + log.debug("dump configuration"); } else { - MessageHandler.logln("don't dump configuration [default]"); + log.debug("don't dump configuration [default]"); } if (quiet != null) { - MessageHandler.logln("quiet mode on"); + log.debug("quiet mode on"); } else { - MessageHandler.logln("quiet mode off [default]"); + log.debug("quiet mode off [default]"); } } @@ -614,7 +646,7 @@ public class CommandLineOptions { public static void main(String args[]) { /* * for (int i = 0; i < args.length; i++) { - * MessageHandler.logln(">"+args[i]+"<"); + * log.debug(">"+args[i]+"<"); * } */ try { diff --git a/src/org/apache/fop/apps/CommandLineStarter.java b/src/org/apache/fop/apps/CommandLineStarter.java index 556be58ce..b516ee938 100644 --- a/src/org/apache/fop/apps/CommandLineStarter.java +++ b/src/org/apache/fop/apps/CommandLineStarter.java @@ -13,6 +13,8 @@ import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; +import org.apache.log.*; + // Java import java.io.*; import java.net.URL; @@ -37,7 +39,8 @@ public class CommandLineStarter extends Starter { throws FOPException { this.commandLineOptions = commandLineOptions; options.setCommandLineOptions(commandLineOptions); - errorDump = Configuration.getBooleanValue("debugMode").booleanValue(); + errorDump = + Configuration.getBooleanValue("debugMode").booleanValue(); super.setInputHandler(commandLineOptions.getInputHandler()); } @@ -47,12 +50,14 @@ public class CommandLineStarter extends Starter { */ public void run() throws FOPException { String version = Version.getVersion(); - MessageHandler.logln(version); + + log.info(version); XMLReader parser = inputHandler.getParser(); setParserFeatures(parser); Driver driver = new Driver(); + driver.setLogger(log); driver.setBufferFile(commandLineOptions.getBufferFile()); if (errorDump) { @@ -61,13 +66,15 @@ public class CommandLineStarter extends Starter { try { driver.setRenderer(commandLineOptions.getRenderer()); - driver.setOutputStream(new FileOutputStream(commandLineOptions.getOutputFile())); - driver.getRenderer().setOptions(commandLineOptions.getRendererOptions()); + driver.setOutputStream( new FileOutputStream( + commandLineOptions.getOutputFile())); + driver.getRenderer().setOptions( + commandLineOptions.getRendererOptions()); driver.render(parser, inputHandler.getInputSource()); System.exit(0); } catch (Exception e) { if (e instanceof FOPException) { - throw (FOPException)e; + throw (FOPException) e; } throw new FOPException(e); } diff --git a/src/org/apache/fop/apps/Driver.java b/src/org/apache/fop/apps/Driver.java index 0b593a56c..dbd4f7a0c 100644 --- a/src/org/apache/fop/apps/Driver.java +++ b/src/org/apache/fop/apps/Driver.java @@ -12,7 +12,6 @@ import org.apache.fop.fo.FOTreeBuilder; import org.apache.fop.fo.ElementMapping; import org.apache.fop.layout.AreaTree; import org.apache.fop.render.Renderer; -import org.apache.fop.messaging.MessageHandler; import org.apache.fop.configuration.ConfigurationReader; import org.apache.fop.configuration.Configuration; import org.apache.fop.tools.DocumentInputSource; @@ -22,6 +21,12 @@ import org.apache.fop.render.pdf.PDFRenderer; import org.apache.fop.system.BufferManager; +import org.apache.log.*; +import org.apache.log.format.*; +import org.apache.log.output.io.*; +import org.apache.log.output.*; +import org.apache.avalon.framework.logger.Loggable; + // DOM import org.w3c.dom.Document; import org.w3c.dom.Node; @@ -84,7 +89,7 @@ import java.util.*; * driver.render(parser, fileInputSource(args[0])); * </PRE> */ -public class Driver { +public class Driver implements Loggable { /** * Render to PDF. OutputStream must be set @@ -166,6 +171,8 @@ public class Driver { */ private BufferManager _bufferManager; + private Logger log; + public static final String getParserClassName() { String parserClassName = null; try { @@ -195,6 +202,11 @@ public class Driver { _stream = stream; } + public void setLogger(Logger logger) { + log = logger; + _treeBuilder.setLogger(log); + } + /** * Resets the Driver so it can be reused. Property and element * mappings are reset to defaults. @@ -408,6 +420,24 @@ public class Driver { * events but isn't a SAX Parser itself. */ public ContentHandler getContentHandler() { + if(log == null) { + Hierarchy hierarchy = Hierarchy.getDefaultHierarchy(); + PatternFormatter formatter = new PatternFormatter( + "[%{priority}]: %{message}\n%{throwable}" ); + + LogTarget target = null; + target = new StreamTarget(System.out, formatter); + + hierarchy.setDefaultLogTarget(target); + log = hierarchy.getLoggerFor("fop"); + log.setPriority(Priority.INFO); + log.error("Logger not set"); + } + + StreamRenderer streamRenderer = new StreamRenderer(_stream, _renderer); + streamRenderer.setLogger(log); + _treeBuilder.setStreamRenderer(streamRenderer); + return _treeBuilder; } @@ -417,9 +447,7 @@ public class Driver { */ public synchronized void render(XMLReader parser, InputSource source) throws FOPException { - StreamRenderer streamRenderer = new StreamRenderer(_stream, _renderer); - _treeBuilder.setStreamRenderer(streamRenderer); - parser.setContentHandler(_treeBuilder); + parser.setContentHandler(getContentHandler()); try { parser.parse(source); } catch (SAXException e) { @@ -439,13 +467,11 @@ public class Driver { */ public synchronized void render(Document document) throws FOPException { - StreamRenderer streamRenderer = new StreamRenderer(_stream, _renderer); - _treeBuilder.setStreamRenderer(streamRenderer); try { DocumentInputSource source = new DocumentInputSource(document); DocumentReader reader = new DocumentReader(); - reader.setContentHandler(_treeBuilder); + reader.setContentHandler(getContentHandler()); reader.parse(source); } catch (SAXException e) { throw new FOPException(e); @@ -462,17 +488,17 @@ public class Driver { public void dumpError(Exception e) { if (_errorDump) { if (e instanceof SAXException) { - e.printStackTrace(); + log.error("", e); if (((SAXException)e).getException() != null) { - ((SAXException)e).getException().printStackTrace(); + log.error("", ((SAXException)e).getException()); } } else if (e instanceof FOPException) { e.printStackTrace(); if (((FOPException)e).getException() != null) { - ((FOPException)e).getException().printStackTrace(); + log.error("", ((FOPException)e).getException()); } } else { - e.printStackTrace(); + log.error("", e); } } } diff --git a/src/org/apache/fop/apps/PDFOutputHandler.java b/src/org/apache/fop/apps/PDFOutputHandler.java index 0b39c67c8..d7b16043d 100644 --- a/src/org/apache/fop/apps/PDFOutputHandler.java +++ b/src/org/apache/fop/apps/PDFOutputHandler.java @@ -125,7 +125,7 @@ public class PDFOutputHandler extends XTFOTreeBuilder FontInfo fontInfo = new FontInfo(); this.renderer.setupFontInfo(fontInfo); - this.areaTree = new AreaTree(); +// this.areaTree = new AreaTree(); this.areaTree.setFontInfo(fontInfo); format(areaTree); @@ -137,7 +137,7 @@ public class PDFOutputHandler extends XTFOTreeBuilder * render the area tree to the output form */ public void doRender() throws IOException, FOPException { - this.renderer.render(areaTree, this.stream); + //this.renderer.render(areaTree, this.stream); } // //////////////////////////////////////////////////////////////////////////////////// diff --git a/src/org/apache/fop/apps/Starter.java b/src/org/apache/fop/apps/Starter.java index c0882e93f..29e620f33 100644 --- a/src/org/apache/fop/apps/Starter.java +++ b/src/org/apache/fop/apps/Starter.java @@ -7,6 +7,8 @@ package org.apache.fop.apps; +import org.apache.log.*; + // SAX import org.xml.sax.XMLReader; import org.xml.sax.SAXException; @@ -27,11 +29,16 @@ public abstract class Starter { Options options; InputHandler inputHandler; + protected Logger log; public Starter() throws FOPException { options = new Options(); } + public void setLogger(Logger logger) { + log = logger; + } + public void setInputHandler(InputHandler inputHandler) { this.inputHandler = inputHandler; } diff --git a/src/org/apache/fop/apps/StreamRenderer.java b/src/org/apache/fop/apps/StreamRenderer.java index 448ec0d66..d18ddd6cd 100644 --- a/src/org/apache/fop/apps/StreamRenderer.java +++ b/src/org/apache/fop/apps/StreamRenderer.java @@ -14,7 +14,8 @@ import org.apache.fop.layout.AreaTree; import org.apache.fop.datatypes.IDReferences; import org.apache.fop.extensions.ExtensionObj; import org.apache.fop.fo.pagination.PageSequence; -import org.apache.fop.messaging.MessageHandler; + +import org.apache.log.Logger; /** This class acts as a bridge between the XML:FO parser @@ -27,7 +28,7 @@ import org.apache.fop.messaging.MessageHandler; FOTreeBuilder when a PageSequence is created, and AreaTree when a Page is formatted.<P> */ -public class StreamRenderer extends Object { +public class StreamRenderer { private static final boolean MEM_PROFILE_WITH_GC = false; /** @@ -81,11 +82,17 @@ public class StreamRenderer extends Object { */ private IDReferences idReferences = new IDReferences(); + private Logger log; + public StreamRenderer(OutputStream outputStream, Renderer renderer) { this.outputStream = outputStream; this.renderer = renderer; } + public void setLogger(Logger logger) { + log = logger; + } + public IDReferences getIDReferences() { return idReferences; } @@ -130,20 +137,20 @@ public class StreamRenderer extends Object { long memoryNow = runtime.totalMemory() - runtime.freeMemory(); long memoryUsed = (memoryNow - initialMemory) / 1024L; - MessageHandler.logln("Initial heap size: " + (initialMemory/1024L) + "Kb"); - MessageHandler.logln("Current heap size: " + (memoryNow/1024L) + "Kb"); - MessageHandler.logln("Total memory used: " + memoryUsed + "Kb"); + log.info("Initial heap size: " + (initialMemory/1024L) + "Kb"); + log.info("Current heap size: " + (memoryNow/1024L) + "Kb"); + log.info("Total memory used: " + memoryUsed + "Kb"); if (!MEM_PROFILE_WITH_GC) { - MessageHandler.logln(" Memory use is indicative; no GC was performed"); - MessageHandler.logln(" These figures should not be used comparatively"); + log.info(" Memory use is indicative; no GC was performed"); + log.info(" These figures should not be used comparatively"); } long timeUsed = System.currentTimeMillis() - startTime; - MessageHandler.logln("Total time used: " + timeUsed + "ms"); - MessageHandler.logln("Pages rendererd: " + pageCount); - MessageHandler.logln("Avg render time: " + (timeUsed / pageCount) + "ms/page"); + log.info("Total time used: " + timeUsed + "ms"); + log.info("Pages rendererd: " + pageCount); + log.info("Avg render time: " + (timeUsed / pageCount) + "ms/page"); } /** diff --git a/src/org/apache/fop/apps/XTDriver.java b/src/org/apache/fop/apps/XTDriver.java index 5a0e5f1fb..1551760fa 100644 --- a/src/org/apache/fop/apps/XTDriver.java +++ b/src/org/apache/fop/apps/XTDriver.java @@ -10,7 +10,6 @@ package org.apache.fop.apps; // FOP import org.apache.fop.fo.XTFOTreeBuilder; import org.apache.fop.fo.ElementMapping; -import org.apache.fop.fo.PropertyListMapping; import org.apache.fop.layout.AreaTree; import org.apache.fop.layout.FontInfo; import org.apache.fop.render.Renderer; @@ -321,7 +320,7 @@ public class XTDriver { FontInfo fontInfo = new FontInfo(); this.renderer.setupFontInfo(fontInfo); - this.areaTree = new AreaTree(); + //this.areaTree = new AreaTree(); this.areaTree.setFontInfo(fontInfo); this.treeBuilder.format(areaTree); @@ -331,7 +330,7 @@ public class XTDriver { * render the area tree to the output form */ public void render() throws IOException, FOPException { - this.renderer.render(areaTree, this.stream); + //this.renderer.render(areaTree, this.stream); } } |