From 1d750a74610958cfd33b5affcd1564cbb4626ae9 Mon Sep 17 00:00:00 2001 From: Jeremias Maerki Date: Wed, 7 Aug 2002 16:54:58 +0000 Subject: [PATCH] First batch of changes for preparation for adoption of Avalon patterns. Only changes on logging for now. Mostly usage of LogEnabled contract interface. Separate mail follows. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@195068 13f79535-47bb-0310-9956-ffa450edef68 --- src/org/apache/fop/apps/AWTStarter.java | 4 +- .../apache/fop/apps/CommandLineOptions.java | 2 +- .../apache/fop/apps/CommandLineStarter.java | 4 +- src/org/apache/fop/apps/Driver.java | 77 ++++--- src/org/apache/fop/apps/LayoutHandler.java | 26 ++- src/org/apache/fop/apps/Starter.java | 9 +- src/org/apache/fop/apps/StructureHandler.java | 12 +- src/org/apache/fop/extensions/Bookmarks.java | 2 +- src/org/apache/fop/extensions/Outline.java | 4 +- src/org/apache/fop/fo/ColorProfile.java | 4 +- src/org/apache/fop/fo/Declarations.java | 6 +- src/org/apache/fop/fo/FONode.java | 12 +- src/org/apache/fop/fo/FOTreeBuilder.java | 14 +- src/org/apache/fop/fo/FOUserAgent.java | 11 +- src/org/apache/fop/fo/FObj.java | 4 +- src/org/apache/fop/fo/FObjMixed.java | 12 +- src/org/apache/fop/fo/Property.java | 16 +- .../apache/fop/fo/ToBeImplementedElement.java | 2 +- src/org/apache/fop/fo/Unknown.java | 2 +- src/org/apache/fop/fo/XMLObj.java | 2 +- src/org/apache/fop/fo/flow/Block.java | 2 +- .../apache/fop/fo/flow/ExternalGraphic.java | 6 +- .../fop/fo/flow/InstreamForeignObject.java | 8 +- src/org/apache/fop/fo/flow/Marker.java | 2 +- .../ConditionalPageMasterReference.java | 4 +- .../fo/pagination/PageMasterReference.java | 2 +- .../fo/pagination/PageNumberGenerator.java | 14 +- .../fop/fo/pagination/PageSequence.java | 208 +++++++++--------- .../fop/fo/pagination/PageSequenceMaster.java | 2 +- .../apache/fop/fo/pagination/RegionBody.java | 58 ++--- .../fop/fo/pagination/SimplePageMaster.java | 73 +++--- .../apache/fop/render/AbstractRenderer.java | 23 +- src/org/apache/fop/render/Renderer.java | 11 +- .../apache/fop/render/pcl/PCLRenderer.java | 2 +- src/org/apache/fop/render/ps/PSRenderer.java | 8 +- .../apache/fop/render/svg/SVGRenderer.java | 2 +- .../apache/fop/render/txt/TXTRenderer.java | 6 +- .../apache/fop/render/xml/XMLRenderer.java | 24 +- src/org/apache/fop/svg/SVGElement.java | 6 +- src/org/apache/fop/tools/AreaTreeBuilder.java | 46 ++-- src/org/apache/fop/tools/TestConverter.java | 33 +-- src/org/apache/fop/tools/anttasks/Fop.java | 26 +-- 42 files changed, 379 insertions(+), 412 deletions(-) diff --git a/src/org/apache/fop/apps/AWTStarter.java b/src/org/apache/fop/apps/AWTStarter.java index 20b0d8456..6f2bc3c21 100644 --- a/src/org/apache/fop/apps/AWTStarter.java +++ b/src/org/apache/fop/apps/AWTStarter.java @@ -94,7 +94,7 @@ public class AWTStarter extends CommandLineStarter { public void run() throws FOPException { Driver driver = new Driver(); - driver.setLogger(log); + setupLogger(driver); if (errorDump) { driver.setErrorDump(true); } @@ -160,7 +160,7 @@ public class AWTStarter extends CommandLineStarter { URL url = getClass().getResource(path); in = url.openStream(); } catch (Exception ex) { - log.error("Can't find URL to: <" + path + "> " + getLogger().error("Can't find URL to: <" + path + "> " + ex.getMessage(), ex); } return new SecureResourceBundle(in); diff --git a/src/org/apache/fop/apps/CommandLineOptions.java b/src/org/apache/fop/apps/CommandLineOptions.java index b2721ccab..0dc4d3990 100644 --- a/src/org/apache/fop/apps/CommandLineOptions.java +++ b/src/org/apache/fop/apps/CommandLineOptions.java @@ -408,7 +408,7 @@ public class CommandLineOptions { default: starter = new CommandLineStarter(this); } - starter.setLogger(log); + starter.enableLogging(log); return starter; } diff --git a/src/org/apache/fop/apps/CommandLineStarter.java b/src/org/apache/fop/apps/CommandLineStarter.java index 03c1eb0a4..9a2543842 100644 --- a/src/org/apache/fop/apps/CommandLineStarter.java +++ b/src/org/apache/fop/apps/CommandLineStarter.java @@ -47,13 +47,13 @@ public class CommandLineStarter extends Starter { public void run() throws FOPException { String version = Version.getVersion(); - log.info(version); + getLogger().info(version); XMLReader parser = inputHandler.getParser(); setParserFeatures(parser); Driver driver = new Driver(); - driver.setLogger(log); + setupLogger(driver); driver.initialize(); if (errorDump) { diff --git a/src/org/apache/fop/apps/Driver.java b/src/org/apache/fop/apps/Driver.java index 730ad1bf0..dd2707cd4 100644 --- a/src/org/apache/fop/apps/Driver.java +++ b/src/org/apache/fop/apps/Driver.java @@ -22,6 +22,8 @@ import org.apache.fop.render.pdf.PDFRenderer; // Avalon import org.apache.avalon.framework.logger.ConsoleLogger; import org.apache.avalon.framework.logger.Logger; +import org.apache.avalon.framework.logger.LogEnabled; +import org.apache.avalon.framework.logger.AbstractLogEnabled; // DOM import org.w3c.dom.Document; @@ -52,6 +54,7 @@ import java.util.*; *
  * Driver driver = new Driver(new InputSource (args[0]),
  * new FileOutputStream(args[1]));
+ * driver.enableLogging(myLogger); //optional
  * driver.setRenderer(RENDER_PDF);
  * driver.run();
  * 
@@ -81,11 +84,12 @@ import java.util.*; * *
  * Driver driver = new Driver();
+ * driver.enableLogging(myLogger); //optional
  * driver.setRenderer(new org.apache.fop.render.awt.AWTRenderer(translator));
  * driver.render(parser, fileInputSource(args[0]));
  * 
*/ -public class Driver { +public class Driver implements LogEnabled { /** * Render to PDF. OutputStream must be set @@ -144,7 +148,7 @@ public class Driver { /** * the structure handler - */ + */ private StructureHandler structHandler; /** @@ -170,11 +174,11 @@ public class Driver { /** * the system resources that FOP will use */ - private Logger log; + private Logger log = null; private FOUserAgent userAgent = null; public static final String getParserClassName() { - try { + try { return javax.xml.parsers.SAXParserFactory.newInstance().newSAXParser().getXMLReader().getClass().getName(); } catch (javax.xml.parsers.ParserConfigurationException e) { return null; @@ -198,7 +202,7 @@ public class Driver { public void initialize() { _stream = null; - _treeBuilder = new FOTreeBuilder(); + _treeBuilder = new FOTreeBuilder(); _treeBuilder.setUserAgent(getUserAgent()); setupDefaultMappings(); } @@ -210,24 +214,29 @@ public class Driver { private FOUserAgent getUserAgent() { if(userAgent == null) { userAgent = new FOUserAgent(); - userAgent.setLogger(getLogger()); + userAgent.enableLogging(getLogger()); String base = org.apache.fop.configuration.Configuration.getStringValue("baseDir"); userAgent.setBaseURL(base); } return userAgent; } - public void setLogger(Logger logger) { - log = logger; + public void enableLogging(Logger log) { + if (this.log == null) { + this.log = log; + } else { + getLogger().warn("Logger is already set! Won't use the new logger."); + } } - private Logger getLogger() { - if(log == null) { - log = new ConsoleLogger(ConsoleLogger.LEVEL_INFO); - log.error("Logger not set"); - } - return log; + protected Logger getLogger() { + if(this.log == null) { + this.log = new ConsoleLogger(ConsoleLogger.LEVEL_INFO); + this.log.error("Logger not set. Using ConsoleLogger as default."); + } + + return this.log; } /** @@ -321,42 +330,40 @@ public class Driver { public void setRenderer(int renderer) throws IllegalArgumentException { switch (renderer) { case RENDER_PDF: - setRenderer(new org.apache.fop.render.pdf.PDFRenderer()); + setRenderer("org.apache.fop.render.pdf.PDFRenderer"); break; case RENDER_AWT: throw new IllegalArgumentException("Use renderer form of setRenderer() for AWT"); case RENDER_PRINT: throw new IllegalArgumentException("Use renderer form of setRenderer() for PRINT"); case RENDER_PCL: - setRenderer(new org.apache.fop.render.pcl.PCLRenderer()); + setRenderer("org.apache.fop.render.pcl.PCLRenderer"); break; case RENDER_PS: - setRenderer(new org.apache.fop.render.ps.PSRenderer()); + setRenderer("org.apache.fop.render.ps.PSRenderer"); break; case RENDER_TXT: - setRenderer(new org.apache.fop.render.txt.TXTRenderer()); + setRenderer("org.apache.fop.render.txt.TXTRenderer()"); break; case RENDER_MIF: //structHandler = new org.apache.fop.mif.MIFHandler(_stream); break; case RENDER_XML: - setRenderer(new org.apache.fop.render.xml.XMLRenderer()); + setRenderer("org.apache.fop.render.xml.XMLRenderer"); break; case RENDER_SVG: - setRenderer(new org.apache.fop.render.svg.SVGRenderer()); + setRenderer("org.apache.fop.render.svg.SVGRenderer"); break; default: throw new IllegalArgumentException("Unknown renderer type"); } - } /** - * Set the Renderer to use - * @param renderer the renderer instance to use + * Set the Renderer to use. + * @param renderer the renderer instance to use (Note: Logger must be set at this point) */ public void setRenderer(Renderer renderer) { - renderer.setLogger(getLogger()); renderer.setUserAgent(getUserAgent()); _renderer = renderer; } @@ -387,6 +394,9 @@ public class Driver { try { _renderer = (Renderer)Class.forName(rendererClassName).newInstance(); + if (_renderer instanceof LogEnabled) { + ((LogEnabled)_renderer).enableLogging(getLogger()); + } _renderer.setProducer(Version.getVersion()); } catch (ClassNotFoundException e) { throw new IllegalArgumentException("Could not find " @@ -457,8 +467,8 @@ public class Driver { } else { structHandler = new org.apache.fop.mif.MIFHandler(_stream); } - structHandler.setLogger(getLogger()); - _treeBuilder.setLogger(getLogger()); + structHandler.enableLogging(getLogger()); + _treeBuilder.setUserAgent(getUserAgent()); _treeBuilder.setStructHandler(structHandler); @@ -511,19 +521,18 @@ public class Driver { */ public void dumpError(Exception e) { if (_errorDump) { - Logger log = getLogger(); if (e instanceof SAXException) { - log.error("", e); + getLogger().error("", e); if (((SAXException)e).getException() != null) { - log.error("", ((SAXException)e).getException()); + getLogger().error("", ((SAXException)e).getException()); } } else if (e instanceof FOPException) { e.printStackTrace(); if (((FOPException)e).getException() != null) { - log.error("", ((FOPException)e).getException()); + getLogger().error("", ((FOPException)e).getException()); } } else { - log.error("", e); + getLogger().error("", e); } } } @@ -575,7 +584,7 @@ class Service { } String serviceFile = "META-INF/services/" + cls.getName(); - // System.out.println("File: " + serviceFile); + // getLogger().debug("File: " + serviceFile); Vector v = (Vector)providerMap.get(serviceFile); if (v != null) @@ -594,7 +603,7 @@ class Service { while (e.hasMoreElements()) { try { java.net.URL u = (java.net.URL)e.nextElement(); - // System.out.println("URL: " + u); + //getLogger().debug("URL: " + u); InputStream is = u.openStream(); Reader r = new InputStreamReader(is, "UTF-8"); @@ -616,7 +625,7 @@ class Service { line = br.readLine(); continue; } - // System.out.println("Line: " + line); + // getLogger().debug("Line: " + line); // Try and load the class // Object obj = cl.loadClass(line).newInstance(); diff --git a/src/org/apache/fop/apps/LayoutHandler.java b/src/org/apache/fop/apps/LayoutHandler.java index aae36e2ea..e5d359a7b 100644 --- a/src/org/apache/fop/apps/LayoutHandler.java +++ b/src/org/apache/fop/apps/LayoutHandler.java @@ -132,20 +132,26 @@ public class LayoutHandler extends StructureHandler { long memoryNow = runtime.totalMemory() - runtime.freeMemory(); long memoryUsed = (memoryNow - initialMemory) / 1024L; - log.debug("Initial heap size: " + (initialMemory / 1024L) + "Kb"); - log.debug("Current heap size: " + (memoryNow / 1024L) + "Kb"); - log.debug("Total memory used: " + memoryUsed + "Kb"); - - if (!MEM_PROFILE_WITH_GC) { - log.debug(" Memory use is indicative; no GC was performed"); - log.debug(" These figures should not be used comparatively"); + if (getLogger().isDebugEnabled()) { + getLogger().debug("Initial heap size: " + (initialMemory / 1024L) + "Kb"); + getLogger().debug("Current heap size: " + (memoryNow / 1024L) + "Kb"); + getLogger().debug("Total memory used: " + memoryUsed + "Kb"); + + if (!MEM_PROFILE_WITH_GC) { + getLogger().debug(" Memory use is indicative; no GC was performed"); + getLogger().debug(" These figures should not be used comparatively"); + } } long timeUsed = System.currentTimeMillis() - startTime; - log.debug("Total time used: " + timeUsed + "ms"); - log.debug("Pages rendered: " + pageCount); - //log.debug("Avg render time: " + (timeUsed / pageCount) + "ms/page"); + if (getLogger().isDebugEnabled()) { + getLogger().debug("Total time used: " + timeUsed + "ms"); + getLogger().debug("Pages rendered: " + pageCount); + if (pageCount > 0) { + getLogger().debug("Avg render time: " + (timeUsed / pageCount) + "ms/page"); + } + } } public void startPageSequence(PageSequence pageSeq, org.apache.fop.fo.Title seqTitle, LayoutMasterSet lms) { diff --git a/src/org/apache/fop/apps/Starter.java b/src/org/apache/fop/apps/Starter.java index a3dc669fe..3c280b274 100644 --- a/src/org/apache/fop/apps/Starter.java +++ b/src/org/apache/fop/apps/Starter.java @@ -8,7 +8,7 @@ package org.apache.fop.apps; // Avalon -import org.apache.avalon.framework.logger.Logger; +import org.apache.avalon.framework.logger.AbstractLogEnabled; // SAX import org.xml.sax.XMLReader; @@ -23,20 +23,15 @@ import java.net.URL; * Creates a SAX Parser (defaulting to Xerces). * */ -public abstract class Starter { +public abstract class Starter extends AbstractLogEnabled { 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/StructureHandler.java b/src/org/apache/fop/apps/StructureHandler.java index 74f858396..cdbed0b22 100644 --- a/src/org/apache/fop/apps/StructureHandler.java +++ b/src/org/apache/fop/apps/StructureHandler.java @@ -10,7 +10,10 @@ package org.apache.fop.apps; // Java import java.util.HashSet; -import org.apache.avalon.framework.logger.Logger; +// Avalon +import org.apache.avalon.framework.logger.AbstractLogEnabled; + +// FOP import org.apache.fop.fo.pagination.*; import org.apache.fop.fo.flow.*; import org.apache.fop.fo.*; @@ -23,21 +26,16 @@ import org.xml.sax.SAXException; * Sub-classes can then implement various methods to handle * the FO Tree when the SAX events occur. */ -public class StructureHandler { +public class StructureHandler extends AbstractLogEnabled { /** The current set of id's in the FO tree This is used so we know if the FO tree contains duplicates */ private HashSet idReferences = new HashSet(); - protected Logger log; public StructureHandler() { } - public void setLogger(Logger logger) { - log = logger; - } - public HashSet getIDReferences() { return idReferences; } diff --git a/src/org/apache/fop/extensions/Bookmarks.java b/src/org/apache/fop/extensions/Bookmarks.java index 4a4415ea0..21a43dc67 100644 --- a/src/org/apache/fop/extensions/Bookmarks.java +++ b/src/org/apache/fop/extensions/Bookmarks.java @@ -34,7 +34,7 @@ public class Bookmarks extends ExtensionObj { } public void end() { - log.debug("adding bookmarks to area tree"); + getLogger().debug("adding bookmarks to area tree"); data = new BookmarkData(); for(int count = 0; count < outlines.size(); count++) { Outline out = (Outline)outlines.get(count); diff --git a/src/org/apache/fop/extensions/Outline.java b/src/org/apache/fop/extensions/Outline.java index 4f8236c3e..1803f857c 100644 --- a/src/org/apache/fop/extensions/Outline.java +++ b/src/org/apache/fop/extensions/Outline.java @@ -31,11 +31,11 @@ public class Outline extends ExtensionObj { externalDestination = attlist.getValue("external-destination"); if (externalDestination != null &&!externalDestination.equals("")) { - log.warn("fox:outline external-destination not supported currently."); + getLogger().warn("fox:outline external-destination not supported currently."); } if (internalDestination == null || internalDestination.equals("")) { - log.warn("fox:outline requires an internal-destination."); + getLogger().warn("fox:outline requires an internal-destination."); } } diff --git a/src/org/apache/fop/fo/ColorProfile.java b/src/org/apache/fop/fo/ColorProfile.java index 012361d07..1f6010c9b 100644 --- a/src/org/apache/fop/fo/ColorProfile.java +++ b/src/org/apache/fop/fo/ColorProfile.java @@ -65,9 +65,9 @@ public class ColorProfile extends FObj { ICC_Profile iccProfile = ICC_Profile.getInstance(is); colorSpace = new ICC_ColorSpace(iccProfile); } catch(IOException ioe) { - log.error("Could not read Color Profile src", ioe); + getLogger().error("Could not read Color Profile src", ioe); } catch(IllegalArgumentException iae) { - log.error("Color Profile src not an ICC Profile", iae); + getLogger().error("Color Profile src not an ICC Profile", iae); } } } diff --git a/src/org/apache/fop/fo/Declarations.java b/src/org/apache/fop/fo/Declarations.java index ec52363a2..6e2304423 100644 --- a/src/org/apache/fop/fo/Declarations.java +++ b/src/org/apache/fop/fo/Declarations.java @@ -45,11 +45,11 @@ public class Declarations extends FObj { } if(colorProfiles.get(cp.getProfileName()) != null) { // duplicate names - log.warn("Duplicate fo:color-profile profile name : " + cp.getProfileName()); + getLogger().warn("Duplicate fo:color-profile profile name : " + cp.getProfileName()); } colorProfiles.put(cp.getProfileName(), cp); } else { - log.warn("color-profile-name required for color profile"); + getLogger().warn("color-profile-name required for color profile"); } } else if(node instanceof XMLObj) { if(external == null) { @@ -57,7 +57,7 @@ public class Declarations extends FObj { } external.add(node); } else { - log.warn("invalid element " + node.getName() + "inside declarations"); + getLogger().warn("invalid element " + node.getName() + "inside declarations"); } } children = null; diff --git a/src/org/apache/fop/fo/FONode.java b/src/org/apache/fop/fo/FONode.java index aa4b601fa..4b0a532d9 100644 --- a/src/org/apache/fop/fo/FONode.java +++ b/src/org/apache/fop/fo/FONode.java @@ -29,8 +29,6 @@ abstract public class FONode { protected FONode parent; protected String name; - protected Logger log; - protected FONode(FONode parent) { this.parent = parent; } @@ -39,8 +37,8 @@ abstract public class FONode { name = str; } - public void setLogger(Logger logger) { - log = logger; + public Logger getLogger() { + return userAgent.getLogger(); } public void setUserAgent(FOUserAgent ua) { @@ -97,7 +95,7 @@ abstract public class FONode { * @return A ListIterator. */ public ListIterator getChildren() { - return null; + return null; } /** @@ -108,11 +106,11 @@ abstract public class FONode { * this FObj. */ public ListIterator getChildren(FONode childNode) { - return null; + return null; } public CharIterator charIterator() { - return new OneCharIterator(CharUtilities.CODE_EOT); + return new OneCharIterator(CharUtilities.CODE_EOT); } } diff --git a/src/org/apache/fop/fo/FOTreeBuilder.java b/src/org/apache/fop/fo/FOTreeBuilder.java index cb8e3ecca..7a7c259fe 100644 --- a/src/org/apache/fop/fo/FOTreeBuilder.java +++ b/src/org/apache/fop/fo/FOTreeBuilder.java @@ -30,7 +30,7 @@ import java.io.IOException; /** * SAX Handler that builds the formatting object tree. - * + * * Modified by Mark Lillywhite mark-fop@inomial.com. Now uses * StreamRenderer to automagically render the document as * soon as it receives a page-sequence end-tag. Also, @@ -70,13 +70,12 @@ public class FOTreeBuilder extends DefaultHandler { * (mark-fop@inomial.com) */ private StructureHandler structHandler; - private Logger log; private FOUserAgent userAgent; public FOTreeBuilder() {} - public void setLogger(Logger logger) { - log = logger; + public Logger getLogger() { + return userAgent.getLogger(); } public void setUserAgent(FOUserAgent ua) { @@ -129,13 +128,13 @@ public class FOTreeBuilder extends DefaultHandler { public void startDocument() throws SAXException { rootFObj = null; // allows FOTreeBuilder to be reused - log.info("building formatting object tree"); + getLogger().info("building formatting object tree"); structHandler.startDocument(); } public void endDocument() throws SAXException { - log.info("Parsing of document complete, stopping renderer"); + getLogger().info("Parsing of document complete, stopping renderer"); structHandler.endDocument(); } @@ -164,7 +163,7 @@ public class FOTreeBuilder extends DefaultHandler { String fullName = uri + "^" + localName; if (!this.unknownFOs.containsKey(fullName)) { this.unknownFOs.put(fullName, ""); - log.warn("Unknown formatting object " + getLogger().warn("Unknown formatting object " + fullName); } if(namespaces.contains(uri.intern())) { @@ -179,7 +178,6 @@ public class FOTreeBuilder extends DefaultHandler { try { fobj = fobjMaker.make(currentFObj); fobj.setName(localName); - fobj.setLogger(log); // set the user agent for resolving user agent values fobj.setUserAgent(userAgent); // set the stream renderer so that appropriate diff --git a/src/org/apache/fop/fo/FOUserAgent.java b/src/org/apache/fop/fo/FOUserAgent.java index f81753d83..e5823180f 100644 --- a/src/org/apache/fop/fo/FOUserAgent.java +++ b/src/org/apache/fop/fo/FOUserAgent.java @@ -10,6 +10,7 @@ package org.apache.fop.fo; import org.apache.fop.render.XMLHandler; import org.apache.fop.render.RendererContext; +import org.apache.avalon.framework.logger.LogEnabled; import org.apache.avalon.framework.logger.Logger; import org.w3c.dom.*; @@ -31,13 +32,13 @@ import java.util.HashMap; * These areas may contain resolveable areas that will be processed * with other resolveable areas */ -public class FOUserAgent { +public class FOUserAgent implements LogEnabled { HashMap defaults = new HashMap(); HashMap handlers = new HashMap(); Logger log; String base; - public void setLogger(Logger logger) { + public void enableLogging(Logger logger) { log = logger; } @@ -83,7 +84,7 @@ public class FOUserAgent { mh.put(ns, handler); } - /** + /** * Render the xml document with the given xml namespace. * The Render Context is by the handle to render into the current * rendering target. @@ -104,11 +105,11 @@ public class FOUserAgent { handler.handleXML(ctx, doc, namespace); } catch (Throwable t) { // could not handle document - log.error("Could not render XML", t); + getLogger().error("Could not render XML", t); } } else { // no handler found for document - log.debug("No handler defined for XML: " + namespace); + getLogger().debug("No handler defined for XML: " + namespace); } } } diff --git a/src/org/apache/fop/fo/FObj.java b/src/org/apache/fop/fo/FObj.java index 223db278e..fc29ef8a2 100644 --- a/src/org/apache/fop/fo/FObj.java +++ b/src/org/apache/fop/fo/FObj.java @@ -153,7 +153,7 @@ public class FObj extends FONode { id = str; idrefs.add(id); } else { - log.warn("duplicate id:" + str + " ignored"); + getLogger().warn("duplicate id:" + str + " ignored"); } } } @@ -348,7 +348,7 @@ public class FObj extends FONode { if (!markers.containsKey(mcname) && children.isEmpty()) { markers.put(mcname, marker); } else { - log.error("fo:marker must be an initial child," + "and 'marker-class-name' must be unique for same parent"); + getLogger().error("fo:marker must be an initial child," + "and 'marker-class-name' must be unique for same parent"); throw new FOPException( "fo:marker must be an initial child," + "and 'marker-class-name' must be unique for same parent"); } diff --git a/src/org/apache/fop/fo/FObjMixed.java b/src/org/apache/fop/fo/FObjMixed.java index 79fc437ef..94d572fab 100644 --- a/src/org/apache/fop/fo/FObjMixed.java +++ b/src/org/apache/fop/fo/FObjMixed.java @@ -36,7 +36,7 @@ public class FObjMixed extends FObj { public void addLayoutManager(List lms) { lms.add(new InlineStackingBPLayoutManager(this, - new LMiter(children.listIterator()))); + new LMiter(children.listIterator()))); // set start and end properties for this element, id, etc. // int numChildren = this.children.size(); // for (int i = 0; i < numChildren; i++) { @@ -50,14 +50,14 @@ public class FObjMixed extends FObj { protected void addCharacters(char data[], int start, int length) { if(textInfo == null) { - // Really only need one of these, but need to get fontInfo - // stored in propMgr for later use. - propMgr.setFontInfo(fontInfo); - textInfo = propMgr.getTextLayoutProps(fontInfo); + // Really only need one of these, but need to get fontInfo + // stored in propMgr for later use. + propMgr.setFontInfo(fontInfo); + textInfo = propMgr.getTextLayoutProps(fontInfo); } FOText ft = new FOText(data, start, length, textInfo); - ft.setLogger(log); + ft.setUserAgent(userAgent); ft.setStructHandler(structHandler); addChild(ft); } diff --git a/src/org/apache/fop/fo/Property.java b/src/org/apache/fop/fo/Property.java index 116c1daeb..3f038de80 100644 --- a/src/org/apache/fop/fo/Property.java +++ b/src/org/apache/fop/fo/Property.java @@ -15,8 +15,6 @@ import org.apache.fop.fo.expr.PropertyException; import org.apache.fop.apps.FOPException; import java.util.Vector; -import org.apache.avalon.framework.logger.Logger; - public class Property { public static class Maker { @@ -132,7 +130,7 @@ public class Property { return setSubprop(baseProp, partName, p); } } else { - //log.error("compound property component " + //getLogger().error("compound property component " // + partName + " unknown."); } return baseProp; @@ -223,10 +221,10 @@ public class Property { } } catch (FOPException e) { - //log.error("convertShorthandProperty caught FOPException " + //getLogger().error("convertShorthandProperty caught FOPException " // + e); } catch (org.apache.fop.fo.expr.PropertyException propEx) { - //log.error("convertShorthandProperty caught PropertyException " + //getLogger().error("convertShorthandProperty caught PropertyException " // + propEx); } if (pret != null) { @@ -332,7 +330,7 @@ public class Property { return make(propertyList, specVal, propertyList.getParentFObj()); } catch (FOPException e) { - //log.error("Error computing property value for " + //getLogger()error("Error computing property value for " // + propName + " from " // + specVal); return null; @@ -359,12 +357,6 @@ public class Property { */ private String specVal; - protected Logger log; - - public void setLogger(Logger logger) { - log = logger; - } - /** * Set the original value specified for the property attribute. * @param specVal The specified value. diff --git a/src/org/apache/fop/fo/ToBeImplementedElement.java b/src/org/apache/fop/fo/ToBeImplementedElement.java index 12d83a969..049e8c1ca 100644 --- a/src/org/apache/fop/fo/ToBeImplementedElement.java +++ b/src/org/apache/fop/fo/ToBeImplementedElement.java @@ -22,7 +22,7 @@ public class ToBeImplementedElement extends FObj { } public void setup() { - log.debug("This element \"" + this.name + getLogger().debug("This element \"" + this.name + "\" is not yet implemented."); } diff --git a/src/org/apache/fop/fo/Unknown.java b/src/org/apache/fop/fo/Unknown.java index edaf630a5..b7dd97ecd 100644 --- a/src/org/apache/fop/fo/Unknown.java +++ b/src/org/apache/fop/fo/Unknown.java @@ -33,6 +33,6 @@ public class Unknown extends FONode { } public void setup() { - log.debug("Layout Unknown element"); + getLogger().debug("Layout Unknown element"); } } diff --git a/src/org/apache/fop/fo/XMLObj.java b/src/org/apache/fop/fo/XMLObj.java index f0ac6fcb3..e536b68ac 100644 --- a/src/org/apache/fop/fo/XMLObj.java +++ b/src/org/apache/fop/fo/XMLObj.java @@ -138,7 +138,7 @@ public abstract class XMLObj extends FONode { // in theory someone might want to embed some defined // xml (eg. fo) inside the foreign xml // they could use a different namespace - log.debug("Invalid element: " + child.getName() + " inside foreign xml markup"); + getLogger().debug("Invalid element: " + child.getName() + " inside foreign xml markup"); } } diff --git a/src/org/apache/fop/fo/flow/Block.java b/src/org/apache/fop/fo/flow/Block.java index 208b0f6d8..3a2908de7 100644 --- a/src/org/apache/fop/fo/flow/Block.java +++ b/src/org/apache/fop/fo/flow/Block.java @@ -221,7 +221,7 @@ public class Block extends FObjMixed { } private void handleWhiteSpace() { - log.debug("fo:block: handleWhiteSpace"); + getLogger().debug("fo:block: handleWhiteSpace"); if (firstInlineChild != null) { boolean bInWS = false; boolean bPrevWasLF = false; diff --git a/src/org/apache/fop/fo/flow/ExternalGraphic.java b/src/org/apache/fop/fo/flow/ExternalGraphic.java index 614c6953d..561f95ac9 100644 --- a/src/org/apache/fop/fo/flow/ExternalGraphic.java +++ b/src/org/apache/fop/fo/flow/ExternalGraphic.java @@ -143,7 +143,7 @@ public class ExternalGraphic extends FObj { cheight = (int)(fopimage.getHeight() * 1000); } if(scaling == Scaling.UNIFORM) { - // adjust the larger + // adjust the larger double rat1 = cwidth / (fopimage.getWidth() * 1000f); double rat2 = cheight / (fopimage.getHeight() * 1000f); if(rat1 < rat2) { @@ -167,7 +167,7 @@ public class ExternalGraphic extends FObj { if(overflow == Overflow.HIDDEN) { clip = true; } else if(overflow == Overflow.ERROR_IF_OVERFLOW) { - log.error("Image: " + url + " overflows the viewport"); + getLogger().error("Image: " + url + " overflows the viewport"); clip = true; } } @@ -208,7 +208,7 @@ public class ExternalGraphic extends FObj { // Common Accessibility Properties AccessibilityProps mAccProps = propMgr.getAccessibilityProps(); - // Common Aural Properties + // Common Aural Properties AuralProps mAurProps = propMgr.getAuralProps(); // Common Border, Padding, and Background Properties diff --git a/src/org/apache/fop/fo/flow/InstreamForeignObject.java b/src/org/apache/fop/fo/flow/InstreamForeignObject.java index 6657524ec..398293f43 100644 --- a/src/org/apache/fop/fo/flow/InstreamForeignObject.java +++ b/src/org/apache/fop/fo/flow/InstreamForeignObject.java @@ -157,7 +157,7 @@ public class InstreamForeignObject extends FObj { } } else {*/ cheight = len.mvalue(); - } + } Point2D csize = new Point2D.Float(cwidth == -1 ? -1 : cwidth / 1000f, cheight == -1 ? -1 : cheight / 1000f); Point2D size = child.getDimension(csize); @@ -197,7 +197,7 @@ public class InstreamForeignObject extends FObj { if(overflow == Overflow.HIDDEN) { clip = true; } else if(overflow == Overflow.ERROR_IF_OVERFLOW) { - log.error("Instream foreign object overflows the viewport"); + getLogger().error("Instream foreign object overflows the viewport"); clip = true; } } @@ -262,7 +262,7 @@ public class InstreamForeignObject extends FObj { // Common Accessibility Properties AccessibilityProps mAccProps = propMgr.getAccessibilityProps(); - + // Common Aural Properties AuralProps mAurProps = propMgr.getAuralProps(); @@ -285,7 +285,7 @@ public class InstreamForeignObject extends FObj { // this.properties.get("content-width"); // this.properties.get("display-align"); // this.properties.get("dominant-baseline"); - // this.properties.get("height"); + // this.properties.get("height"); setupID(); // this.properties.get("inline-progression-dimension"); // this.properties.get("keep-with-next"); diff --git a/src/org/apache/fop/fo/flow/Marker.java b/src/org/apache/fop/fo/flow/Marker.java index 5119d4c9a..a9ef5aebc 100644 --- a/src/org/apache/fop/fo/flow/Marker.java +++ b/src/org/apache/fop/fo/flow/Marker.java @@ -36,7 +36,7 @@ public class Marker extends FObjMixed { try { ((FObj)parent).addMarker(this); } catch (FOPException fopex) { - log.error("marker cannot be added to '" + parent + getLogger().error("marker cannot be added to '" + parent + "'"); } } diff --git a/src/org/apache/fop/fo/pagination/ConditionalPageMasterReference.java b/src/org/apache/fop/fo/pagination/ConditionalPageMasterReference.java index e09f0e310..dcaf01180 100644 --- a/src/org/apache/fop/fo/pagination/ConditionalPageMasterReference.java +++ b/src/org/apache/fop/fo/pagination/ConditionalPageMasterReference.java @@ -75,7 +75,7 @@ public class ConditionalPageMasterReference extends FObj { break; case PagePosition.LAST: // how the hell do you know at this point? - log.debug("LAST PagePosition NYI"); + getLogger().warn("LAST PagePosition NYI"); okOnPagePosition = true; break; case PagePosition.REST: @@ -147,7 +147,7 @@ public class ConditionalPageMasterReference extends FObj { (RepeatablePageMasterAlternatives)parent; if (getMasterName() == null) { - log.warn("single-page-master-reference" + getLogger().warn("single-page-master-reference" + "does not have a master-name and so is being ignored"); } else { this.repeatablePageMasterAlternatives.addConditionalPageMasterReference(this); diff --git a/src/org/apache/fop/fo/pagination/PageMasterReference.java b/src/org/apache/fop/fo/pagination/PageMasterReference.java index 5f9674a49..e13e517ff 100644 --- a/src/org/apache/fop/fo/pagination/PageMasterReference.java +++ b/src/org/apache/fop/fo/pagination/PageMasterReference.java @@ -68,7 +68,7 @@ public abstract class PageMasterReference extends FObj _pageSequenceMaster = (PageSequenceMaster)parent; if (getMasterName() == null) { - log.warn("" + getName() + getLogger().warn("" + getName() + " does not have a master-reference and so is being ignored"); } else { _pageSequenceMaster.addSubsequenceSpecifier(this); diff --git a/src/org/apache/fop/fo/pagination/PageNumberGenerator.java b/src/org/apache/fop/fo/pagination/PageNumberGenerator.java index facb47f48..e025b4597 100644 --- a/src/org/apache/fop/fo/pagination/PageNumberGenerator.java +++ b/src/org/apache/fop/fo/pagination/PageNumberGenerator.java @@ -11,7 +11,7 @@ package org.apache.fop.fo.pagination; import org.apache.fop.fo.properties.*; // Avalon -import org.apache.avalon.framework.logger.Logger; +import org.apache.avalon.framework.logger.AbstractLogEnabled; // Java import java.util.*; @@ -21,7 +21,7 @@ import java.util.*; * and 'letterValue' properties on fo:page-sequence to return a String * corresponding to the supplied integer page number. */ -public class PageNumberGenerator { +public class PageNumberGenerator extends AbstractLogEnabled { private String format; private char groupingSeparator; @@ -44,8 +44,6 @@ public class PageNumberGenerator { "", "0", "00", "000", "0000", "00000" }; - private Logger log; - public PageNumberGenerator(String format, char groupingSeparator, int groupingSize, int letterValue) { this.format = format; @@ -70,7 +68,7 @@ public class PageNumberGenerator { formatType = UPPERROMAN; } else { // token not handled - //log.debug("'format' token not recognized; using '1'"); + //getLogger().debug("'format' token not recognized; using '1'"); formatType = DECIMAL; minPadding = 0; } @@ -80,7 +78,7 @@ public class PageNumberGenerator { // loop for (int i = 0; i < fmtLen - 1; i++) { if (format.charAt(i) != '0') { - //log.debug("'format' token not recognized; using '1'"); + //getLogger().debug("'format' token not recognized; using '1'"); formatType = DECIMAL; minPadding = 0; } else { @@ -90,10 +88,6 @@ public class PageNumberGenerator { } } - public void setLogger(Logger logger) { - log = logger; - } - public String makeFormattedPageNumber(int number) { String pn = null; if (formatType == DECIMAL) { diff --git a/src/org/apache/fop/fo/pagination/PageSequence.java b/src/org/apache/fop/fo/pagination/PageSequence.java index e9c36a1f4..af0d043f1 100644 --- a/src/org/apache/fop/fo/pagination/PageSequence.java +++ b/src/org/apache/fop/fo/pagination/PageSequence.java @@ -180,9 +180,9 @@ public class PageSequence extends FObj { masterName = this.properties.get("master-reference").getString(); - // TODO: Add code here to set a reference to the PageSequenceMaster - // if the masterName names a page-sequence-master, else get a - // reference to the SimplePageMaster. Throw an exception if neither? + // TODO: Add code here to set a reference to the PageSequenceMaster + // if the masterName names a page-sequence-master, else get a + // reference to the SimplePageMaster. Throw an exception if neither? // get the 'format' properties this.pageNumberGenerator = @@ -190,6 +190,7 @@ public class PageSequence extends FObj { this.properties.get("grouping-separator").getCharacter(), this.properties.get("grouping-size").getNumber().intValue(), this.properties.get("letter-value").getEnum()); + this.pageNumberGenerator.enableLogging(getLogger()); this.forcePageCount = this.properties.get("force-page-count").getEnum(); @@ -211,7 +212,7 @@ public class PageSequence extends FObj { throw new FOPException("flow-names must be unique within an fo:page-sequence"); } if (!this.layoutMasterSet.regionNameExists(flow.getFlowName())) { - log.error("region-name '" + getLogger().error("region-name '" + flow.getFlowName() + "' doesn't exist in the layout-master-set."); } @@ -228,64 +229,59 @@ public class PageSequence extends FObj { * @param child The flow object child to be added to the PageSequence. */ public void addChild(FONode child) { - try { - String childName = child.getName(); - if (childName.equals("fo:title")) { - if (this._flowMap.size()>0) { - log.warn("fo:title should be first in page-sequence"); - } else { - this.titleFO = (Title)child; - structHandler.startPageSequence(this, titleFO, layoutMasterSet); - sequenceStarted = true; - } - } - else if (childName.equals("fo:flow")) { - if (this.mainFlow != null) { - throw new FOPException("Only a single fo:flow permitted" - + " per fo:page-sequence"); - } - else { - if(!sequenceStarted) { + try { + String childName = child.getName(); + if (childName.equals("fo:title")) { + if (this._flowMap.size()>0) { + getLogger().warn("fo:title should be first in page-sequence"); + } else { + this.titleFO = (Title)child; + structHandler.startPageSequence(this, titleFO, layoutMasterSet); + sequenceStarted = true; + } + } else if (childName.equals("fo:flow")) { + if (this.mainFlow != null) { + throw new FOPException("Only a single fo:flow permitted" + + " per fo:page-sequence"); + } else { + if(!sequenceStarted) { structHandler.startPageSequence(this, titleFO, layoutMasterSet); sequenceStarted = true; } - this.mainFlow = (Flow)child; - addFlow(mainFlow); - super.addChild(child); // For getChildren - } - } - else if (childName.equals("fo:static-content")) { - if (this.mainFlow != null) { - throw new FOPException(childName + - " must precede fo:flow; ignoring"); - } - else { + this.mainFlow = (Flow)child; + addFlow(mainFlow); + super.addChild(child); // For getChildren + } + } else if (childName.equals("fo:static-content")) { + if (this.mainFlow != null) { + throw new FOPException(childName + + " must precede fo:flow; ignoring"); + } else { if(!sequenceStarted) { structHandler.startPageSequence(this, titleFO, layoutMasterSet); sequenceStarted = true; } - addFlow((Flow)child); - } - } - else { - // Ignore it! - log.warn("FO '" + childName + - "' not a legal page-sequence child."); - return; - } - } catch (FOPException fopex) { - log.error("Error in PageSequence.addChild(): " + - fopex.getMessage()); - } + addFlow((Flow)child); + } + } else { + // Ignore it! + getLogger().warn("FO '" + childName + + "' not a legal page-sequence child."); + return; + } + } catch (FOPException fopex) { + getLogger().error("Error in PageSequence.addChild(): " + + fopex.getMessage(), fopex); + } } public void end() { - try { - this.structHandler.endPageSequence(this); - } catch (FOPException fopex) { - log.error("Error in PageSequence.end(): " + - fopex.getMessage()); - } + try { + this.structHandler.endPageSequence(this); + } catch (FOPException fopex) { + getLogger().error("Error in PageSequence.end(): " + + fopex.getMessage(), fopex); + } } @@ -315,22 +311,22 @@ public class PageSequence extends FObj { * Runs the formatting of this page sequence into the given area tree */ public void format(AreaTree areaTree) throws FOPException { - // Make a new PageLayoutManager and a FlowLayoutManager - // Run the PLM in a thread - // Wait for them to finish. - - // If no main flow, nothing to layout! - if (this.mainFlow == null) return; - - // Initialize if already used? + // Make a new PageLayoutManager and a FlowLayoutManager + // Run the PLM in a thread + // Wait for them to finish. + + // If no main flow, nothing to layout! + if (this.mainFlow == null) return; + + // Initialize if already used? this.layoutMasterSet.resetPageMasters(); int firstAvailPageNumber = 0; - // This will layout pages and add them to the area tree - PageLayoutManager pageLM = new PageLayoutManager(areaTree, this); - // For now, skip the threading and just call run directly. - pageLM.run(); + // This will layout pages and add them to the area tree + PageLayoutManager pageLM = new PageLayoutManager(areaTree, this); + // For now, skip the threading and just call run directly. + pageLM.run(); // Thread layoutThread = new Thread(pageLM); // layoutThread.start(); @@ -343,30 +339,30 @@ public class PageSequence extends FObj { // } catch (InterruptedException ie) { // log.error("PageSequence.format() interrupted waiting on layout"); // } - // Tell the root the last page number we created. - this.root.setRunningPageNumberCounter(this.currentPageNumber); + // Tell the root the last page number we created. + this.root.setRunningPageNumberCounter(this.currentPageNumber); } private void initPageNumber() { - this.currentPageNumber = this.root.getRunningPageNumberCounter() + 1; - - if (this.pageNumberType == AUTO_ODD) { - // Next page but force odd. May force empty page creation! - // Whose master is used for this??? Assume no. - // Use force-page-count=auto - // on preceding page-sequence to make sure that there is no gap! - if (currentPageNumber % 2 == 0) { - this.currentPageNumber++; - } - } else if (pageNumberType == AUTO_EVEN) { - if (currentPageNumber % 2 == 1) { - this.currentPageNumber++; - } - } - else if (pageNumberType == EXPLICIT) { - this.currentPageNumber = this.explicitFirstNumber; - } - this.firstPageNumber = this.currentPageNumber; + this.currentPageNumber = this.root.getRunningPageNumberCounter() + 1; + + if (this.pageNumberType == AUTO_ODD) { + // Next page but force odd. May force empty page creation! + // Whose master is used for this??? Assume no. + // Use force-page-count=auto + // on preceding page-sequence to make sure that there is no gap! + if (currentPageNumber % 2 == 0) { + this.currentPageNumber++; + } + } else if (pageNumberType == AUTO_EVEN) { + if (currentPageNumber % 2 == 1) { + this.currentPageNumber++; + } + } + else if (pageNumberType == EXPLICIT) { + this.currentPageNumber = this.explicitFirstNumber; + } + this.firstPageNumber = this.currentPageNumber; } /** @@ -376,22 +372,22 @@ public class PageSequence extends FObj { * @param bIsBlank If true, use a master for a blank page. * @param bIsLast If true, use the master for the last page in the sequence. */ - public PageViewport createPage(boolean bIsBlank, boolean bIsLast) - throws FOPException + public PageViewport createPage(boolean bIsBlank, boolean bIsLast) + throws FOPException { - // Set even/odd flag and first flag based on current state - // Should do it this way, but fix it later.... - /*boolean bEvenPage = ((this.currentPageNumber %2)==0); - currentPage = makePage(bEvenPage, */ - currentPage = makePage(this.currentPageNumber, - this.currentPageNumber==this.firstPageNumber, - bIsLast, bIsBlank); - return currentPage; - // The page will have a viewport/reference area pair defined - // for each region in the master. - // Set up the page itself - // currentPage.setNumber(this.currentPageNumber); + // Set even/odd flag and first flag based on current state + // Should do it this way, but fix it later.... + /*boolean bEvenPage = ((this.currentPageNumber %2)==0); + currentPage = makePage(bEvenPage, */ + currentPage = makePage(this.currentPageNumber, + this.currentPageNumber==this.firstPageNumber, + bIsLast, bIsBlank); + return currentPage; + // The page will have a viewport/reference area pair defined + // for each region in the master. + // Set up the page itself + // currentPage.setNumber(this.currentPageNumber); // SKIP ALL THIS FOR NOW!!! // String formattedPageNumber = // pageNumberGenerator.makeFormattedPageNumber(this.currentPageNumber); @@ -412,7 +408,7 @@ public class PageSequence extends FObj { // this.pageCount++; // used for 'force-page-count' calculations // handle the 'force-page-count' - //forcePage(areaTree, firstAvailPageNumber); + //forcePage(areaTree, firstAvailPageNumber); } /** @@ -422,13 +418,13 @@ public class PageSequence extends FObj { * @param isFirstPage true when this is the first page in the sequence * @param isEmptyPage true if this page will be empty * (e.g. forced even or odd break) - * @return a Page layout object based on the page master selected + * @return a Page layout object based on the page master selected * from the params * TODO: modify the other methods to use even/odd flag and bIsLast */ private PageViewport makePage(int firstAvailPageNumber, - boolean isFirstPage, boolean bIsLast, - boolean isEmptyPage) throws FOPException { + boolean isFirstPage, boolean bIsLast, + boolean isEmptyPage) throws FOPException { // layout this page sequence // while there is still stuff in the flow, ask the @@ -441,7 +437,7 @@ public class PageSequence extends FObj { // a legal alternative is to use the last sub-sequence // specification which should be handled in getNextSubsequence. - // That's not done here. + // That's not done here. if (pageMaster == null) { throw new FOPException("page masters exhausted. Cannot recover."); } @@ -587,7 +583,7 @@ public class PageSequence extends FObj { SubSequenceSpecifier nextSubsequence = getNextSubsequence(sequenceMaster); if (nextSubsequence == null) { - log.error("Page subsequences exhausted. Using previous subsequence."); + getLogger().error("Page subsequences exhausted. Using previous subsequence."); thisIsFirstPage = true; // this becomes the first page in the new (old really) page master currentSubsequence.reset(); @@ -679,7 +675,7 @@ public class PageSequence extends FObj { // } else { -// System.out.println("flow is null. regionClass = '" + regionClass +// getLogger().error("flow is null. regionClass = '" + regionClass // + "' currentSPM = " // + getCurrentSimplePageMaster()); diff --git a/src/org/apache/fop/fo/pagination/PageSequenceMaster.java b/src/org/apache/fop/fo/pagination/PageSequenceMaster.java index 0054cb226..e32819ba7 100644 --- a/src/org/apache/fop/fo/pagination/PageSequenceMaster.java +++ b/src/org/apache/fop/fo/pagination/PageSequenceMaster.java @@ -47,7 +47,7 @@ public class PageSequenceMaster extends FObj { this.layoutMasterSet = (LayoutMasterSet)parent; String pm = this.properties.get("master-name").getString(); if (pm == null) { - log.warn("page-sequence-master does not have " + getLogger().warn("page-sequence-master does not have " + "a master-name and so is being ignored"); } else { this.layoutMasterSet.addPageSequenceMaster(pm, this); diff --git a/src/org/apache/fop/fo/pagination/RegionBody.java b/src/org/apache/fop/fo/pagination/RegionBody.java index b2132c330..f8dadc4f4 100644 --- a/src/org/apache/fop/fo/pagination/RegionBody.java +++ b/src/org/apache/fop/fo/pagination/RegionBody.java @@ -34,20 +34,20 @@ public class RegionBody extends Region { protected Rectangle getViewportRectangle (FODimension reldims) { - /* - * Use space-before and space-after which will use corresponding - * absolute margin properties if specified. For indents: - * try to get corresponding absolute margin property using the - * writing-mode on the page (not on the region-body!). If that's not - * set but indent is explicitly set, it will return that. - */ + /* + * Use space-before and space-after which will use corresponding + * absolute margin properties if specified. For indents: + * try to get corresponding absolute margin property using the + * writing-mode on the page (not on the region-body!). If that's not + * set but indent is explicitly set, it will return that. + */ MarginProps mProps = propMgr.getMarginProps(); - int start = getRelMargin(PropertyList.START, "start-indent"); - return new Rectangle( start, mProps.spaceBefore, - reldims.ipd - start - - getRelMargin(PropertyList.END, "end-indent"), - reldims.bpd - mProps.spaceBefore - - mProps.spaceAfter); + int start = getRelMargin(PropertyList.START, "start-indent"); + return new Rectangle( start, mProps.spaceBefore, + reldims.ipd - start - + getRelMargin(PropertyList.END, "end-indent"), + reldims.bpd - mProps.spaceBefore - + mProps.spaceAfter); } /** @@ -55,18 +55,18 @@ public class RegionBody extends Region { * writing mode. */ private int getRelMargin(int reldir, String sRelPropName) { - FObj parent = (FObj) getParent(); - String sPropName = "margin-" + - parent.properties.wmRelToAbs(reldir); - Property prop = properties.getExplicitBaseProp(sPropName); - if (prop == null) { - prop = properties.getExplicitBaseProp(sRelPropName); - } - return ((prop != null)? prop.getLength().mvalue() : 0); + FObj parent = (FObj) getParent(); + String sPropName = "margin-" + + parent.properties.wmRelToAbs(reldir); + Property prop = properties.getExplicitBaseProp(sPropName); + if (prop == null) { + prop = properties.getExplicitBaseProp(sRelPropName); + } + return ((prop != null)? prop.getLength().mvalue() : 0); } protected void setRegionTraits(RegionReference r, Rectangle2D absRegVPRect) { - super.setRegionTraits(r, absRegVPRect); + super.setRegionTraits(r, absRegVPRect); // r.setBackgroundColor(backgroundColor); } @@ -88,24 +88,24 @@ public class RegionBody extends Region { * Override the inherited method. */ public RegionReference makeRegionReferenceArea(Rectangle2D absRegVPRect) { - // Should set some column stuff here I think, or put it elsewhere - BodyRegion body = new BodyRegion(); - setRegionTraits(body, absRegVPRect); + // Should set some column stuff here I think, or put it elsewhere + BodyRegion body = new BodyRegion(); + setRegionTraits(body, absRegVPRect); int columnCount= this.properties.get("column-count").getNumber().intValue(); if ((columnCount > 1) && (overflow == Overflow.SCROLL)) { // recover by setting 'column-count' to 1. This is allowed but // not required by the spec. - log.error("Setting 'column-count' to 1 because " + getLogger().error("Setting 'column-count' to 1 because " + "'overflow' is set to 'scroll'"); columnCount = 1; } - body.setColumnCount(columnCount); + body.setColumnCount(columnCount); int columnGap = this.properties.get("column-gap").getLength().mvalue(); - body.setColumnGap(columnGap); - return body; + body.setColumnGap(columnGap); + return body; } } diff --git a/src/org/apache/fop/fo/pagination/SimplePageMaster.java b/src/org/apache/fop/fo/pagination/SimplePageMaster.java index 73be3f0e2..e08c34de1 100644 --- a/src/org/apache/fop/fo/pagination/SimplePageMaster.java +++ b/src/org/apache/fop/fo/pagination/SimplePageMaster.java @@ -51,7 +51,7 @@ public class SimplePageMaster extends FObj { LayoutMasterSet layoutMasterSet = (LayoutMasterSet)parent; masterName = this.properties.get("master-name").getString(); if (masterName == null) { - log.warn("simple-page-master does not have " + getLogger().warn("simple-page-master does not have " + "a master-name and so is being ignored"); } else { layoutMasterSet.addSimplePageMaster(this); @@ -79,48 +79,48 @@ public class SimplePageMaster extends FObj { // Get absolute margin properties (top, left, bottom, right) MarginProps mProps = propMgr.getMarginProps(); - /* Create the page reference area rectangle in first quadrant coordinates - * (ie, 0,0 is at bottom,left of the "page media" and y increases - * when moving towards the top of the page. - * The media rectangle itself is (0,0,pageWidth,pageHeight). - */ - Rectangle pageRefRect = - new Rectangle(mProps.marginLeft, mProps.marginTop, - pageWidth - mProps.marginLeft - mProps.marginRight, - pageHeight - mProps.marginTop - mProps.marginBottom); + /* Create the page reference area rectangle in first quadrant coordinates + * (ie, 0,0 is at bottom,left of the "page media" and y increases + * when moving towards the top of the page. + * The media rectangle itself is (0,0,pageWidth,pageHeight). + */ + Rectangle pageRefRect = + new Rectangle(mProps.marginLeft, mProps.marginTop, + pageWidth - mProps.marginLeft - mProps.marginRight, + pageHeight - mProps.marginTop - mProps.marginBottom); - // ??? KL shouldn't this take the viewport too??? - Page page = new Page(); // page reference area + // ??? KL shouldn't this take the viewport too??? + Page page = new Page(); // page reference area // Set up the CTM on the page reference area based on writing-mode // and reference-orientation - FODimension reldims=new FODimension(0,0); - CTM pageCTM = propMgr.getCTMandRelDims(pageRefRect, reldims); + FODimension reldims=new FODimension(0,0); + CTM pageCTM = propMgr.getCTMandRelDims(pageRefRect, reldims); - // Create a RegionViewport/ reference area pair for each page region + // Create a RegionViewport/ reference area pair for each page region - boolean bHasBody=false; + boolean bHasBody=false; for (Iterator regenum = _regions.values().iterator(); regenum.hasNext(); ) { Region r = (Region)regenum.next(); - RegionViewport rvp = r.makeRegionViewport(reldims, pageCTM); - rvp.setRegion(r.makeRegionReferenceArea(rvp.getViewArea())); - page.setRegion(r.getRegionAreaClass(), rvp); - if (r.getRegionAreaClass() == RegionReference.BODY) { - bHasBody = true; - } + RegionViewport rvp = r.makeRegionViewport(reldims, pageCTM); + rvp.setRegion(r.makeRegionReferenceArea(rvp.getViewArea())); + page.setRegion(r.getRegionAreaClass(), rvp); + if (r.getRegionAreaClass() == RegionReference.BODY) { + bHasBody = true; + } } - if (!bHasBody) { - log.error("simple-page-master has no region-body"); + if (!bHasBody) { + getLogger().error("simple-page-master has no region-body"); } - this.pageMaster = new PageMaster(new PageViewport(page, - new Rectangle(0,0, - pageWidth,pageHeight))); + this.pageMaster = new PageMaster(new PageViewport(page, + new Rectangle(0,0, + pageWidth,pageHeight))); - // _regions = null; // PageSequence access SimplePageMaster.... + // _regions = null; // PageSequence access SimplePageMaster.... children = null; properties = null; } @@ -142,19 +142,18 @@ public class SimplePageMaster extends FObj { } protected void addChild(FONode child) { - if (child instanceof Region) { - addRegion((Region)child); - } - else { - log.error("SimplePageMaster cannot have child of type " + - child.getName()); - } + if (child instanceof Region) { + addRegion((Region)child); + } else { + getLogger().error("SimplePageMaster cannot have child of type " + + child.getName()); + } } protected void addRegion(Region region) { - String key = region.getRegionClass(); + String key = region.getRegionClass(); if (_regions.containsKey(key)) { - log.error("Only one region of class " + getLogger().error("Only one region of class " + key + " allowed within a simple-page-master."); // throw new FOPException("Only one region of class " diff --git a/src/org/apache/fop/render/AbstractRenderer.java b/src/org/apache/fop/render/AbstractRenderer.java index 9b0712d43..e6cd863cc 100644 --- a/src/org/apache/fop/render/AbstractRenderer.java +++ b/src/org/apache/fop/render/AbstractRenderer.java @@ -15,7 +15,7 @@ import org.apache.fop.area.inline.Character; import org.apache.fop.fo.FOUserAgent; // Avalon -import org.apache.avalon.framework.logger.Logger; +import org.apache.avalon.framework.logger.AbstractLogEnabled; // Java import java.awt.geom.Rectangle2D; @@ -32,8 +32,7 @@ import java.util.Iterator; * viewports. This keeps track of the current block and inline * position. */ -public abstract class AbstractRenderer implements Renderer { - protected Logger log; +public abstract class AbstractRenderer extends AbstractLogEnabled implements Renderer { protected FOUserAgent userAgent; protected HashMap options; @@ -45,10 +44,6 @@ public abstract class AbstractRenderer implements Renderer { protected int currentBlockIPPosition = 0; - public void setLogger(Logger logger) { - log = logger; - } - public void setUserAgent(FOUserAgent agent) { userAgent = agent; } @@ -133,21 +128,21 @@ public abstract class AbstractRenderer implements Renderer { protected void renderRegionViewport(RegionViewport port) { if (port != null) { Rectangle2D view = port.getViewArea(); - // The CTM will transform coordinates relative to - // this region-reference area into page coords, so - // set origin for the region to 0,0. + // The CTM will transform coordinates relative to + // this region-reference area into page coords, so + // set origin for the region to 0,0. currentBPPosition = 0; // (int) (view.getY() / 1000); currentIPPosition = 0; // (int) (view.getX() / 1000); currentBlockIPPosition = currentIPPosition; RegionReference region = port.getRegion(); - startVParea(region.getCTM()); + startVParea(region.getCTM()); if (region.getRegionClass() == RegionReference.BODY) { renderBodyRegion((BodyRegion) region); } else { renderRegion(region); } - endVParea(); + endVParea(); } } @@ -310,8 +305,8 @@ public abstract class AbstractRenderer implements Renderer { public void renderInlineParent(InlineParent ip) { // currentBlockIPPosition += ip.getWidth(); - Iterator iter = ip.getChildAreas().iterator(); - while (iter.hasNext()) { + Iterator iter = ip.getChildAreas().iterator(); + while (iter.hasNext()) { ((InlineArea)iter.next()).render(this); } } diff --git a/src/org/apache/fop/render/Renderer.java b/src/org/apache/fop/render/Renderer.java index 488c4aad2..49603fb87 100644 --- a/src/org/apache/fop/render/Renderer.java +++ b/src/org/apache/fop/render/Renderer.java @@ -13,9 +13,6 @@ import org.apache.fop.area.inline.*; import org.apache.fop.layout.FontInfo; import org.apache.fop.fo.FOUserAgent; -// Avalon -import org.apache.avalon.framework.logger.Logger; - // Java import java.io.OutputStream; import java.io.IOException; @@ -32,15 +29,13 @@ import java.util.HashMap; */ public interface Renderer { + public static final String ROLE = Renderer.class.getName(); + + public void startRenderer(OutputStream outputStream) throws IOException; public void stopRenderer() throws IOException; - /** - * Set the logger - */ - public void setLogger(Logger logger); - /** * Set the User Agent */ diff --git a/src/org/apache/fop/render/pcl/PCLRenderer.java b/src/org/apache/fop/render/pcl/PCLRenderer.java index d1e21d241..d3f0ebf1f 100755 --- a/src/org/apache/fop/render/pcl/PCLRenderer.java +++ b/src/org/apache/fop/render/pcl/PCLRenderer.java @@ -162,7 +162,7 @@ public class PCLRenderer extends PrintRenderer { public void startRenderer(OutputStream outputStream) throws IOException { - log.info("rendering areas to PCL"); + getLogger().info("rendering areas to PCL"); currentStream = new PCLStream(outputStream); // Set orientation. diff --git a/src/org/apache/fop/render/ps/PSRenderer.java b/src/org/apache/fop/render/ps/PSRenderer.java index c40af92b9..0fbc27347 100644 --- a/src/org/apache/fop/render/ps/PSRenderer.java +++ b/src/org/apache/fop/render/ps/PSRenderer.java @@ -289,7 +289,7 @@ public class PSRenderer extends AbstractRenderer { */ public void startRenderer(OutputStream outputStream) throws IOException { - log.debug("rendering areas to PostScript"); + getLogger().debug("rendering areas to PostScript"); this.out = new PSStream(outputStream); write("%!PS-Adobe-3.0"); @@ -307,7 +307,7 @@ public class PSRenderer extends AbstractRenderer { /* Write proc for including EPS */ write("%%BeginResource: procset EPSprocs"); write("%%Title: EPS encapsulation procs"); - + write("/BeginEPSF { %def"); write("/b4_Inc_state save def % Save state for cleanup"); write("/dict_count countdictstack def % Count objects on dict stack"); @@ -324,14 +324,14 @@ public class PSRenderer extends AbstractRenderer { write("} if"); write("} if"); write("} bind def"); - + write("/EndEPSF { %def"); write("count op_count sub {pop} repeat % Clean up stacks"); write("countdictstack dict_count sub {end} repeat"); write("b4_Inc_state restore"); write("} bind def"); write("%%EndResource"); - + write("%%EndSetup"); write("FOPFonts begin"); } diff --git a/src/org/apache/fop/render/svg/SVGRenderer.java b/src/org/apache/fop/render/svg/SVGRenderer.java index d6c6dbc7d..597cf8282 100644 --- a/src/org/apache/fop/render/svg/SVGRenderer.java +++ b/src/org/apache/fop/render/svg/SVGRenderer.java @@ -161,7 +161,7 @@ public class SVGRenderer extends AbstractRenderer implements XMLHandler { try { svgT.transcode(input, output); } catch (TranscoderException e) { - log.error("could not write svg file :" + e.getMessage(), e); + getLogger().error("could not write svg file :" + e.getMessage(), e); } ostream.flush(); ostream = null; diff --git a/src/org/apache/fop/render/txt/TXTRenderer.java b/src/org/apache/fop/render/txt/TXTRenderer.java index 57536ada3..d2a768d5a 100755 --- a/src/org/apache/fop/render/txt/TXTRenderer.java +++ b/src/org/apache/fop/render/txt/TXTRenderer.java @@ -81,7 +81,7 @@ public class TXTRenderer extends PrintRenderer { void addStr(int row, int col, String str, boolean ischar) { if (debug) - System.out.println("TXTRenderer.addStr(" + row + ", " + col + getLogger().debug("TXTRenderer.addStr(" + row + ", " + col + ", \"" + str + "\", " + ischar + ")"); if (suppressGraphics &&!ischar) return; @@ -105,14 +105,14 @@ public class TXTRenderer extends PrintRenderer { for (int countr = sb.length(); countr < col; countr++) sb.append(' '); if (debug) - System.out.println("TXTRenderer.addStr() sb.length()=" + getLogger().debug("TXTRenderer.addStr() sb.length()=" + sb.length()); for (int countr = col; countr < (col + str.length()); countr++) { if (countr >= sb.length()) sb.append(str.charAt(countr - col)); else { if (debug) - System.out.println("TXTRenderer.addStr() sb.length()=" + getLogger().debug("TXTRenderer.addStr() sb.length()=" + sb.length() + " countr=" + countr); sb.setCharAt(countr, str.charAt(countr - col)); } diff --git a/src/org/apache/fop/render/xml/XMLRenderer.java b/src/org/apache/fop/render/xml/XMLRenderer.java index 8dfa8ee5f..896698110 100644 --- a/src/org/apache/fop/render/xml/XMLRenderer.java +++ b/src/org/apache/fop/render/xml/XMLRenderer.java @@ -159,7 +159,7 @@ public class XMLRenderer extends AbstractRenderer { */ public void startRenderer(OutputStream outputStream) throws IOException { - log.debug("rendering areas to XML"); + getLogger().debug("rendering areas to XML"); this.writer = new PrintWriter(outputStream); this.writer.write( "\n\n"); @@ -172,7 +172,7 @@ public class XMLRenderer extends AbstractRenderer { writeEndTag(""); writeEndTag(""); this.writer.flush(); - log.debug("written out XML"); + getLogger().debug("written out XML"); } public void renderPage(PageViewport page) throws IOException, @@ -346,7 +346,7 @@ public class XMLRenderer extends AbstractRenderer { prop = " props=\"" + getPropString(map) + "\""; } writeElement("" + word.getWord() + ""); + prop + ">" + word.getWord() + ""); super.renderWord(word); } @@ -358,7 +358,7 @@ public class XMLRenderer extends AbstractRenderer { } writeStartTag(""); super.renderInlineParent(ip); - writeEndTag(""); + writeEndTag(""); } public void renderLeader(Leader area) { @@ -389,15 +389,15 @@ public class XMLRenderer extends AbstractRenderer { protected String getPropString(Map traitMap) { StringBuffer strbuf = new StringBuffer(); - Iterator iter = traitMap.entrySet().iterator(); - while (iter.hasNext()) { + Iterator iter = traitMap.entrySet().iterator(); + while (iter.hasNext()) { Map.Entry traitEntry = (Map.Entry) iter.next(); - strbuf.append(Trait.getTraitName(traitEntry.getKey())); - strbuf.append(':'); - strbuf.append(traitEntry.getValue().toString()); - strbuf.append(';'); - } - return strbuf.toString(); + strbuf.append(Trait.getTraitName(traitEntry.getKey())); + strbuf.append(':'); + strbuf.append(traitEntry.getValue().toString()); + strbuf.append(';'); + } + return strbuf.toString(); } } diff --git a/src/org/apache/fop/svg/SVGElement.java b/src/org/apache/fop/svg/SVGElement.java index 8c5a97abf..47703ead7 100644 --- a/src/org/apache/fop/svg/SVGElement.java +++ b/src/org/apache/fop/svg/SVGElement.java @@ -76,7 +76,7 @@ public class SVGElement extends SVGObj { ((SVGOMDocument)doc).setURLObject(new URL(baseDir)); } } catch (Exception e) { - log.error("Could not set base URL for svg", e); + getLogger().error("Could not set base URL for svg", e); } Element e = ((SVGDocument)doc).getRootElement(); @@ -142,7 +142,7 @@ public class SVGElement extends SVGObj { str = svgRoot.getAttributeNS(null, SVGConstants.SVG_WIDTH_ATTRIBUTE); if (str.length() == 0) str = "100%"; float width = UnitProcessor.svgHorizontalLengthToUserSpace - (str, SVGConstants.SVG_WIDTH_ATTRIBUTE, ctx); + (str, SVGConstants.SVG_WIDTH_ATTRIBUTE, ctx); str = svgRoot.getAttributeNS(null, SVGConstants.SVG_HEIGHT_ATTRIBUTE); if (str.length() == 0) str = "100%"; @@ -163,7 +163,7 @@ public class SVGElement extends SVGObj { protected int fontSize; float pixeltoMM; - public PDFUnitContext(int size, Element e, float ptmm) { + public PDFUnitContext(int size, Element e, float ptmm) { this.e = e; this.fontSize = size; } diff --git a/src/org/apache/fop/tools/AreaTreeBuilder.java b/src/org/apache/fop/tools/AreaTreeBuilder.java index afd212c24..212e7b55b 100644 --- a/src/org/apache/fop/tools/AreaTreeBuilder.java +++ b/src/org/apache/fop/tools/AreaTreeBuilder.java @@ -22,7 +22,7 @@ import org.apache.fop.layout.FontMetric; import org.apache.fop.fo.FOUserAgent; import org.apache.avalon.framework.logger.ConsoleLogger; -import org.apache.avalon.framework.logger.Logger; +import org.apache.avalon.framework.logger.AbstractLogEnabled; import java.io.*; import java.util.*; @@ -49,13 +49,13 @@ import org.apache.batik.dom.util.DOMUtilities; * Tests: different renderers, saving and loading pages with serialization * out of order rendering */ -public class AreaTreeBuilder { - private Logger log = new ConsoleLogger(ConsoleLogger.LEVEL_DEBUG); +public class AreaTreeBuilder extends AbstractLogEnabled { /** */ public static void main(String[] args) { AreaTreeBuilder atb = new AreaTreeBuilder(); + atb.enableLogging(new ConsoleLogger(ConsoleLogger.LEVEL_DEBUG)); atb.runTests(args[0], args[1], args[2]); System.exit(0); @@ -65,9 +65,9 @@ public class AreaTreeBuilder { * */ protected void runTests(String in, String type, String out) { - log.debug("Starting tests"); + getLogger().debug("Starting tests"); runTest(in, type, out); - log.debug("Finished"); + getLogger().debug("Finished"); } /** @@ -81,9 +81,12 @@ public class AreaTreeBuilder { } else if ("svg".equals(type)) { rend = new SVGRenderer(); } + setupLogger(rend); FontInfo fi = new FontInfo(); rend.setupFontInfo(fi); - rend.setUserAgent(new FOUserAgent()); + FOUserAgent ua = new FOUserAgent(); + setupLogger(ua); + rend.setUserAgent(ua); AreaTree.StorePagesModel sm = AreaTree.createStorePagesModel(); TreeLoader tl = new TreeLoader(fi); @@ -94,7 +97,7 @@ public class AreaTreeBuilder { tl.buildAreaTree(is); renderAreaTree(sm, rend, out); } catch (IOException e) { - log.error("error reading file" + e.getMessage(), e); + getLogger().error("error reading file" + e.getMessage(), e); } } @@ -104,7 +107,6 @@ public class AreaTreeBuilder { OutputStream os = new BufferedOutputStream(new FileOutputStream(out)); - rend.setLogger(log); rend.startRenderer(os); int count = 0; @@ -124,7 +126,7 @@ public class AreaTreeBuilder { page.savePage(tempstream); tempstream.close(); File temp = new File("temp.ser"); - log.debug("page serialized to: " + temp.length()); + getLogger().debug("page serialized to: " + temp.length()); temp = null; ObjectInputStream in = new ObjectInputStream( new BufferedInputStream( @@ -140,7 +142,7 @@ public class AreaTreeBuilder { rend.stopRenderer(); os.close(); } catch (Exception e) { - log.error("error rendering output", e); + getLogger().error("error rendering output", e); } } @@ -410,7 +412,7 @@ class TreeLoader { Node obj = childs.item(i); if (obj.getNodeName().equals("block")) { Block block = new Block(); - addTraits((Element)obj, block); + addTraits((Element)obj, block); addBlockChildren(block, (Element) obj); list.add(block); } @@ -436,7 +438,7 @@ class TreeLoader { // error } LineArea line = new LineArea(); - addTraits((Element) obj, line); + addTraits((Element) obj, line); String height = ((Element) obj).getAttribute("height"); int h = Integer.parseInt(height); line.setHeight(h); @@ -549,7 +551,7 @@ class TreeLoader { for (int i = 0; i < childs.getLength(); i++) { Node obj = childs.item(i); if (obj instanceof Element) { - //System.out.println(obj.getNodeName()); + //getLogger().debug(obj.getNodeName()); Element rootEle = (Element) obj; String space = rootEle.getAttribute("xmlns"); if (svgNS.equals(space)) { @@ -649,15 +651,15 @@ class TreeLoader { String tok = st.nextToken(); int index = tok.indexOf(":"); String id = tok.substring(0, index); - Object traitCode = Trait.getTraitCode(id); - if (traitCode != null) { - area.addTrait(traitCode, - Trait.makeTraitValue(traitCode, - tok.substring(index + 1))); - } - else { - System.err.println("Unknown trait: " + id ); - } + Object traitCode = Trait.getTraitCode(id); + if (traitCode != null) { + area.addTrait(traitCode, + Trait.makeTraitValue(traitCode, + tok.substring(index + 1))); + } + else { + System.err.println("Unknown trait: " + id ); + } } } diff --git a/src/org/apache/fop/tools/TestConverter.java b/src/org/apache/fop/tools/TestConverter.java index 094353fc3..792f1bfd2 100644 --- a/src/org/apache/fop/tools/TestConverter.java +++ b/src/org/apache/fop/tools/TestConverter.java @@ -11,7 +11,7 @@ import org.apache.fop.apps.*; import org.apache.fop.configuration.*; import org.apache.avalon.framework.logger.ConsoleLogger; -import org.apache.avalon.framework.logger.Logger; +import org.apache.avalon.framework.logger.AbstractLogEnabled; import java.io.*; import java.util.*; @@ -37,14 +37,13 @@ import org.xml.sax.SAXParseException; * Modified by Mark Lillywhite mark-fop@inomial.com to use the new Driver * interface. */ -public class TestConverter { +public class TestConverter extends AbstractLogEnabled { boolean failOnly = false; boolean outputPDF = false; File destdir; File compare = null; String baseDir = "./"; HashMap differ = new HashMap(); - private Logger log; /** * This main method can be used to run the test converter from @@ -61,6 +60,7 @@ public class TestConverter { System.out.println("test suite file name required"); } TestConverter tc = new TestConverter(); + tc.enableLogging(new ConsoleLogger(ConsoleLogger.LEVEL_ERROR)); String testFile = null; for (int count = 0; count < args.length; count++) { @@ -81,14 +81,6 @@ public class TestConverter { tc.runTests(testFile, "results", null); } - public TestConverter() { - setupLogging(); - } - - private void setupLogging() { - log = new ConsoleLogger(ConsoleLogger.LEVEL_ERROR); - } - public void setOutputPDF(boolean pdf) { outputPDF = pdf; } @@ -107,7 +99,7 @@ public class TestConverter { * The document is read as a dom and each testcase is covered. */ public HashMap runTests(String fname, String dest, String compDir) { - log.debug("running tests in file:" + fname); + getLogger().debug("running tests in file:" + fname); try { if (compDir != null) { compare = new File(baseDir + "/" + compDir); @@ -131,7 +123,7 @@ public class TestConverter { if (testsuite.hasAttributes()) { String profile = testsuite.getAttributes().getNamedItem("profile").getNodeValue(); - log.debug("testing test suite:" + profile); + getLogger().debug("testing test suite:" + profile); } NodeList testcases = testsuite.getChildNodes(); @@ -142,7 +134,7 @@ public class TestConverter { } } } catch (Exception e) { - e.printStackTrace(); + getLogger().error("Error while running tests", e); } return differ; } @@ -157,7 +149,7 @@ public class TestConverter { if (tcase.hasAttributes()) { String profile = tcase.getAttributes().getNamedItem("profile").getNodeValue(); - log.debug("testing profile:" + profile); + getLogger().debug("testing profile:" + profile); } NodeList cases = tcase.getChildNodes(); @@ -201,7 +193,7 @@ public class TestConverter { if (xslNode != null) { xsl = xslNode.getNodeValue(); } - log.debug("converting xml:" + xml + " and xsl:" + + getLogger().debug("converting xml:" + xml + " and xsl:" + xsl + " to area tree"); try { @@ -211,7 +203,7 @@ public class TestConverter { Configuration.put("baseDir", xmlFile.getParentFile().toURL().toExternalForm()); } catch (Exception e) { - log.error("Error setting base directory"); + getLogger().error("Error setting base directory"); } InputHandler inputHandler = null; @@ -226,9 +218,8 @@ public class TestConverter { XMLReader parser = inputHandler.getParser(); setParserFeatures(parser); - Logger logger = log.getChildLogger("fop"); Driver driver = new Driver(); - driver.setLogger(logger); + setupLogger(driver, "fop"); driver.initialize(); if (outputPDF) { driver.setRenderer(Driver.RENDER_PDF); @@ -249,7 +240,7 @@ public class TestConverter { driver.setOutputStream(new BufferedOutputStream( new FileOutputStream(new File(destdir, outname + (outputPDF ? ".pdf" : ".at.xml"))))); - log.debug("ddir:" + destdir + " on:" + outname + ".pdf"); + getLogger().debug("ddir:" + destdir + " on:" + outname + ".pdf"); driver.render(parser, inputHandler.getInputSource()); // check difference @@ -261,7 +252,7 @@ public class TestConverter { } } } catch (Exception e) { - e.printStackTrace(); + getLogger().error("Error while running tests", e); } } diff --git a/src/org/apache/fop/tools/anttasks/Fop.java b/src/org/apache/fop/tools/anttasks/Fop.java index 62a68f2d1..09ccbbb90 100644 --- a/src/org/apache/fop/tools/anttasks/Fop.java +++ b/src/org/apache/fop/tools/anttasks/Fop.java @@ -177,6 +177,7 @@ public class Fop extends Task { public void execute() throws BuildException { try { Starter starter = new FOPTaskStarter(this); + starter.enableLogging(new ConsoleLogger(ConsoleLogger.LEVEL_INFO)); starter.run(); } catch (FOPException ex) { throw new BuildException(ex); @@ -188,12 +189,9 @@ public class Fop extends Task { class FOPTaskStarter extends Starter { Fop task; - Logger log; FOPTaskStarter(Fop task) throws FOPException { this.task = task; - - log = new ConsoleLogger(ConsoleLogger.LEVEL_INFO); } private int determineRenderer(String format) { @@ -219,7 +217,7 @@ class FOPTaskStarter extends Starter { return Driver.RENDER_XML; } else { String err = "Couldn't determine renderer to use: "+format; - log.error(err); + getLogger().error(err); throw new BuildException(err); } } @@ -240,7 +238,7 @@ class FOPTaskStarter extends Starter { return ".xml"; default: String err = "Unknown renderer: "+renderer; - log.error(err); + getLogger().error(err); throw new BuildException(err); } } @@ -267,7 +265,7 @@ class FOPTaskStarter extends Starter { toExternalForm()); } } catch (Exception e) { - log.error("Error setting base directory",e); + getLogger().error("Error setting base directory", e); } task.log("Using base directory: " + @@ -337,7 +335,7 @@ class FOPTaskStarter extends Starter { try { out = new FileOutputStream(outFile); } catch (Exception ex) { - log.error("Failed to open " + outFile); + getLogger().error("Failed to open " + outFile); throw new BuildException(ex); } @@ -345,18 +343,18 @@ class FOPTaskStarter extends Starter { try { Driver driver = new Driver(inputHandler.getInputSource(), out); - driver.setLogger(log); + setupLogger(driver); driver.setRenderer(renderer); - if (renderer == Driver.RENDER_XML) { - HashMap rendererOptions = new HashMap(); - rendererOptions.put("fineDetail", new Boolean(true)); - driver.getRenderer().setOptions(rendererOptions); - } + if (renderer == Driver.RENDER_XML) { + HashMap rendererOptions = new HashMap(); + rendererOptions.put("fineDetail", new Boolean(true)); + driver.getRenderer().setOptions(rendererOptions); + } driver.setXMLReader(parser); driver.run(); out.close(); } catch (Exception ex) { - log.error("Couldn't render file: " + ex.getMessage()); + getLogger().error("Couldn't render file: " + ex.getMessage()); throw new BuildException(ex); } } -- 2.39.5