diff options
19 files changed, 393 insertions, 94 deletions
diff --git a/examples/embedding/java/embedding/ExampleFO2OldStylePrint.java b/examples/embedding/java/embedding/ExampleFO2OldStylePrint.java index 588d2c5d7..d9bc1d11d 100644 --- a/examples/embedding/java/embedding/ExampleFO2OldStylePrint.java +++ b/examples/embedding/java/embedding/ExampleFO2OldStylePrint.java @@ -24,21 +24,18 @@ import java.awt.print.PrinterJob; import java.io.File; import java.io.IOException; -//JAXP +import javax.xml.transform.Result; +import javax.xml.transform.Source; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; -import javax.xml.transform.Source; -import javax.xml.transform.Result; -import javax.xml.transform.stream.StreamSource; import javax.xml.transform.sax.SAXResult; +import javax.xml.transform.stream.StreamSource; - -// FOP +import org.apache.fop.apps.FOPException; import org.apache.fop.apps.FOUserAgent; import org.apache.fop.apps.Fop; -import org.apache.fop.apps.FOPException; import org.apache.fop.apps.FopFactory; -import org.apache.fop.render.print.PrintRenderer; +import org.apache.fop.apps.MimeConstants; /** * This class demonstrates printing an FO file to a PrinterJob instance. @@ -63,15 +60,10 @@ public class ExampleFO2OldStylePrint { try { //Set up a custom user agent so we can supply our own renderer instance FOUserAgent userAgent = fopFactory.newFOUserAgent(); + userAgent.getRendererOptions().put("printerjob", printerJob); - //Set up our own PrintRenderer instance so we can supply a special PrinterJob instance. - PrintRenderer renderer = new PrintRenderer(printerJob); - renderer.setUserAgent(userAgent); - - userAgent.setRendererOverride(renderer); - - // Construct fop with desired output format (here, it is set through the user agent) - Fop fop = fopFactory.newFop(userAgent); + // Construct FOP with desired output format + Fop fop = fopFactory.newFop(MimeConstants.MIME_FOP_PRINT, userAgent); // Setup JAXP using identity transformer TransformerFactory factory = TransformerFactory.newInstance(); diff --git a/src/documentation/content/xdocs/trunk/embedding.xml b/src/documentation/content/xdocs/trunk/embedding.xml index 9ed42dd9d..95e96104b 100644 --- a/src/documentation/content/xdocs/trunk/embedding.xml +++ b/src/documentation/content/xdocs/trunk/embedding.xml @@ -183,7 +183,7 @@ try { how to configure alternative backends. </p> <p> - As a result of the above we differentiate between to kinds of "logging": + As a result of the above we differentiate between two kinds of "logging": </p> <ul> <li>(FOP-)Developer-oriented logging</li> diff --git a/src/java/org/apache/fop/Version.java b/src/java/org/apache/fop/Version.java index 4545d071e..7e421ad29 100644 --- a/src/java/org/apache/fop/Version.java +++ b/src/java/org/apache/fop/Version.java @@ -41,7 +41,7 @@ public final class Version { if (version == null) { //Fallback if FOP is used in a development environment String headURL - = "$HeadURL: http://svn.apache.org/repos/asf/xmlgraphics/fop/trunk/src/java/org/apache/fop/Version.java $"; + = "$HeadURL$"; version = headURL; final String pathPrefix = "/xmlgraphics/fop/"; int pos = version.indexOf(pathPrefix); diff --git a/src/java/org/apache/fop/cli/CommandLineOptions.java b/src/java/org/apache/fop/cli/CommandLineOptions.java index 3bb0aae7f..4e5c8ae44 100644 --- a/src/java/org/apache/fop/cli/CommandLineOptions.java +++ b/src/java/org/apache/fop/cli/CommandLineOptions.java @@ -46,6 +46,8 @@ import org.apache.fop.pdf.PDFXMode; import org.apache.fop.render.Renderer; import org.apache.fop.render.awt.AWTRenderer; import org.apache.fop.render.pdf.PDFRenderer; +import org.apache.fop.render.print.PagesMode; +import org.apache.fop.render.print.PrintRenderer; import org.apache.fop.render.xml.XMLRenderer; import org.apache.fop.util.CommandLineLogger; @@ -133,8 +135,9 @@ public class CommandLineOptions { * @throws FOPException for general errors * @throws FileNotFoundException if an input file wasn't found * @throws IOException if the the configuration file could not be loaded + * @return true if the processing can continue, false to abort */ - public void parse(String[] args) + public boolean parse(String[] args) throws FOPException, IOException { boolean optionsParsed = true; @@ -155,6 +158,8 @@ public class CommandLineOptions { } addXSLTParameter("fop-output-format", getOutputFormat()); addXSLTParameter("fop-version", Version.getVersion()); + } else { + return false; } } catch (FOPException e) { printUsage(); @@ -193,6 +198,7 @@ public class CommandLineOptions { //Make sure the prepared XMLRenderer is used foUserAgent.setRendererOverride(xmlRenderer); } + return true; } /** @@ -268,7 +274,6 @@ public class CommandLineOptions { } else if (args[i].equals("-png")) { i = i + parsePNGOutputOption(args, i); } else if (args[i].equals("-print")) { - i = i + parsePrintOutputOption(args, i); // show print help if (i + 1 < args.length) { if (args[i + 1].equals("help")) { @@ -276,6 +281,9 @@ public class CommandLineOptions { return false; } } + i = i + parsePrintOutputOption(args, i); + } else if (args[i].equals("-copies")) { + i = i + parseCopiesOption(args, i); } else if (args[i].equals("-pcl")) { i = i + parsePCLOutputOption(args, i); } else if (args[i].equals("-ps")) { @@ -302,7 +310,7 @@ public class CommandLineOptions { String expression = args[++i]; addXSLTParameter(name, expression); } else { - throw new FOPException("invalid param usage: use -param <name> <value>"); + throw new FOPException("invalid param usage: use -param <name> <value>"); } } else if (args[i].equals("-o")) { i = i + parsePDFOwnerPassword(args, i); @@ -461,7 +469,37 @@ public class CommandLineOptions { private int parsePrintOutputOption(String[] args, int i) throws FOPException { setOutputMode(MimeConstants.MIME_FOP_PRINT); - return 0; + if ((i + 1 <= args.length) + && (args[i + 1].charAt(0) != '-')) { + String arg = args[i + 1]; + String[] parts = arg.split(","); + for (int j = 0; j < parts.length; j++) { + String s = parts[j]; + if (s.matches("\\d+")) { + renderingOptions.put(PrintRenderer.START_PAGE, new Integer(s)); + } else if (s.matches("\\d+-\\d+")) { + String[] startend = s.split("-"); + renderingOptions.put(PrintRenderer.START_PAGE, new Integer(startend[0])); + renderingOptions.put(PrintRenderer.END_PAGE, new Integer(startend[1])); + } else { + PagesMode mode = PagesMode.byName(s); + renderingOptions.put(PrintRenderer.PAGES_MODE, mode); + } + } + return 1; + } else { + return 0; + } + } + + private int parseCopiesOption(String[] args, int i) throws FOPException { + if ((i + 1 == args.length) + || (args[i + 1].charAt(0) == '-')) { + throw new FOPException("you must specify the number of copies"); + } else { + renderingOptions.put(PrintRenderer.COPIES, new Integer(args[i + 1])); + return 1; + } } private int parsePCLOutputOption(String[] args, int i) throws FOPException { @@ -991,18 +1029,21 @@ public class CommandLineOptions { + " Fop -xml foo.xml -xsl foo.xsl -foout foo.fo\n" + " Fop foo.fo -mif foo.mif\n" + " Fop foo.fo -rtf foo.rtf\n" - + " Fop foo.fo -print or Fop -print foo.fo \n" - + " Fop foo.fo -awt \n"); + + " Fop foo.fo -print\n" + + " Fop foo.fo -awt\n"); } /** * shows the options for print output */ private void printUsagePrintOutput() { - 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 "); + System.err.println("USAGE: -print [from[-to][,even|odd]] [-copies numCopies]\n\n" + + "Example:\n" + + "all pages: Fop infile.fo -print\n" + + "all pages with two copies: Fop infile.fo -print -copies 2\n" + + "all pages starting with page 7: Fop infile.fo -print 7\n" + + "pages 2 to 3: Fop infile.fo -print 2-3\n" + + "only even page between 10 and 20: Fop infile.fo -print 10-20,even\n"); } /** diff --git a/src/java/org/apache/fop/cli/Main.java b/src/java/org/apache/fop/cli/Main.java index e2297380d..43da8d966 100644 --- a/src/java/org/apache/fop/cli/Main.java +++ b/src/java/org/apache/fop/cli/Main.java @@ -28,6 +28,7 @@ import java.net.URL; import java.util.List; import org.apache.commons.io.IOUtils; + import org.apache.fop.apps.FOUserAgent; import org.apache.fop.apps.MimeConstants; @@ -151,7 +152,9 @@ public class Main { try { options = new CommandLineOptions(); - options.parse(args); + if (!options.parse(args)) { + System.exit(1); + } foUserAgent = options.getFOUserAgent(); String outputFormat = options.getOutputFormat(); diff --git a/src/java/org/apache/fop/render/PrintRendererConfigurator.java b/src/java/org/apache/fop/render/PrintRendererConfigurator.java index ccff3baa1..674c357df 100644 --- a/src/java/org/apache/fop/render/PrintRendererConfigurator.java +++ b/src/java/org/apache/fop/render/PrintRendererConfigurator.java @@ -236,7 +236,7 @@ public class PrintRendererConfigurator extends AbstractRendererConfigurator EmbedFontInfo[] embedFontInfos = finder.find(fontUrl, resolver, fontCache); if (embedFontInfos == null) { - return; + continue; } for (int i = 0, c = embedFontInfos.length; i < c; i++) { diff --git a/src/java/org/apache/fop/render/awt/AWTRenderer.java b/src/java/org/apache/fop/render/awt/AWTRenderer.java index e646f9b9c..2f2631786 100644 --- a/src/java/org/apache/fop/render/awt/AWTRenderer.java +++ b/src/java/org/apache/fop/render/awt/AWTRenderer.java @@ -43,8 +43,8 @@ import org.apache.fop.apps.MimeConstants; import org.apache.fop.area.Area; import org.apache.fop.area.PageViewport; import org.apache.fop.render.awt.viewer.PreviewDialog; -import org.apache.fop.render.awt.viewer.StatusListener; import org.apache.fop.render.awt.viewer.Renderable; +import org.apache.fop.render.awt.viewer.StatusListener; import org.apache.fop.render.java2d.Java2DRenderer; /** @@ -202,7 +202,7 @@ public class AWTRenderer extends Java2DRenderer implements Pageable { /** {@inheritDoc} */ public boolean supportsOutOfOrder() { - return true; // TODO true? + return false; } /** {@inheritDoc} */ diff --git a/src/java/org/apache/fop/render/java2d/Java2DRenderer.java b/src/java/org/apache/fop/render/java2d/Java2DRenderer.java index 0ffe3307a..1f3194949 100644 --- a/src/java/org/apache/fop/render/java2d/Java2DRenderer.java +++ b/src/java/org/apache/fop/render/java2d/Java2DRenderer.java @@ -121,9 +121,6 @@ public abstract class Java2DRenderer extends AbstractPathOrientedRenderer implem /** The 0-based current page number */ private int currentPageNumber = 0; - /** The 0-based total number of rendered pages */ - private int numberOfPages; - /** true if antialiasing is set */ protected boolean antialiasing = true; @@ -208,7 +205,7 @@ public abstract class Java2DRenderer extends AbstractPathOrientedRenderer implem public void stopRenderer() throws IOException { log.debug("Java2DRenderer stopped"); renderingDone = true; - numberOfPages = currentPageNumber; + int numberOfPages = currentPageNumber; // TODO set all vars to null for gc if (numberOfPages == 0) { new FOPException("No page could be rendered"); @@ -238,7 +235,7 @@ public abstract class Java2DRenderer extends AbstractPathOrientedRenderer implem * @return The 0-based total number of rendered pages */ public int getNumberOfPages() { - return numberOfPages; + return pageViewportList.size(); } /** diff --git a/src/java/org/apache/fop/render/print/PagesMode.java b/src/java/org/apache/fop/render/print/PagesMode.java new file mode 100644 index 000000000..6879aa68d --- /dev/null +++ b/src/java/org/apache/fop/render/print/PagesMode.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* $Id$ */ + +package org.apache.fop.render.print; + +/** Enum class for pages mode (all, even, odd pages). */ +public final class PagesMode { + + /** the all pages mode */ + public static final PagesMode ALL = new PagesMode("all"); + /** the even pages mode */ + public static final PagesMode EVEN = new PagesMode("even"); + /** the odd pages mode */ + public static final PagesMode ODD = new PagesMode("odd"); + + private String name; + + /** + * Constructor to add a new named item. + * @param name Name of the item. + */ + private PagesMode(String name) { + this.name = name; + } + + /** @return the name of the enum */ + public String getName() { + return this.name; + } + + /** + * Returns a PagesMode instance by name. + * @param name the name of the pages mode + * @return the pages mode + */ + public static PagesMode byName(String name) { + if (PagesMode.ALL.getName().equalsIgnoreCase(name)) { + return PagesMode.ALL; + } else if (PagesMode.EVEN.getName().equalsIgnoreCase(name)) { + return PagesMode.EVEN; + } else if (PagesMode.ODD.getName().equalsIgnoreCase(name)) { + return PagesMode.ODD; + } else { + throw new IllegalArgumentException("Invalid value for PagesMode: " + name); + } + } + + /** {@inheritDoc} */ + public String toString() { + return "PagesMode:" + name; + } + +} diff --git a/src/java/org/apache/fop/render/print/PrintRenderer.java b/src/java/org/apache/fop/render/print/PrintRenderer.java index e4c159815..2774b5373 100644 --- a/src/java/org/apache/fop/render/print/PrintRenderer.java +++ b/src/java/org/apache/fop/render/print/PrintRenderer.java @@ -27,9 +27,11 @@ import java.awt.print.Printable; import java.awt.print.PrinterException; import java.awt.print.PrinterJob; import java.io.IOException; +import java.util.Map; import java.util.Vector; import org.apache.fop.apps.FOPException; +import org.apache.fop.apps.FOUserAgent; import org.apache.fop.render.java2d.Java2DRenderer; /** @@ -40,59 +42,155 @@ import org.apache.fop.render.java2d.Java2DRenderer; */ public class PrintRenderer extends Java2DRenderer implements Pageable { - private static final int EVEN_AND_ALL = 0; - - private static final int EVEN = 1; + /** + * Printing parameter: the preconfigured PrinterJob to use, + * datatype: java.awt.print.PrinterJob + */ + public static final String PRINTER_JOB = "printerjob"; + + /** + * Printing parameter: the pages to be printed (all, even or odd), + * datatype: the strings "all", "even" or "odd" or one of PagesMode.* + */ + public static final String PAGES_MODE = "even-odd"; - private static final int ODD = 2; + /** + * Printing parameter: the page number (1-based) of the first page to be printed, + * datatype: a positive Integer + */ + public static final String START_PAGE = "start-page"; + /** + * Printing parameter: the page number (1-based) of the last page to be printed, + * datatype: a positive Integer + */ + public static final String END_PAGE = "end-page"; + + /** + * Printing parameter: the number of copies of the document to be printed, + * datatype: a positive Integer + */ + public static final String COPIES = "copies"; + + private int startNumber = 0; - private int endNumber = -1; - private int mode = EVEN_AND_ALL; + private PagesMode mode = PagesMode.ALL; private int copies = 1; private PrinterJob printerJob; /** - * Creates a new PrintRenderer with the options set from system properties. + * Creates a new PrintRenderer with the options set from system properties if a custom + * PrinterJob is not given in FOUserAgent's renderer options. */ public PrintRenderer() { - initializePrinterJob(); + setupFromSystemProperties(); } - + /** * Creates a new PrintRenderer and allows you to pass in a specific PrinterJob instance * that this renderer should work with. * @param printerJob the PrinterJob instance + * @deprecated Please use the rendering options on the user agent to pass in the PrinterJob! */ public PrintRenderer(PrinterJob printerJob) { + this(); this.printerJob = printerJob; printerJob.setPageable(this); } - private void initializePrinterJob() throws IllegalArgumentException { + private void initializePrinterJob() { + if (this.printerJob == null) { + printerJob = PrinterJob.getPrinterJob(); + printerJob.setJobName("FOP Document"); + printerJob.setCopies(copies); + if (System.getProperty("dialog") != null) { + if (!printerJob.printDialog()) { + throw new RuntimeException( + "Printing cancelled by operator"); + } + } + printerJob.setPageable(this); + } + } + + private void setupFromSystemProperties() { + //TODO Remove me! This is not a beautiful way to do this. // read from command-line options copies = getIntProperty("copies", 1); - startNumber = getIntProperty("start", 1) - 1; + startNumber = getIntProperty("start", 1); endNumber = getIntProperty("end", -1); String str = System.getProperty("even"); if (str != null) { - mode = Boolean.valueOf(str).booleanValue() ? EVEN : ODD; + mode = Boolean.valueOf(str).booleanValue() ? PagesMode.EVEN : PagesMode.ODD; + } + } + + /** {@inheritDoc} */ + public void setUserAgent(FOUserAgent agent) { + super.setUserAgent(agent); + + Map rendererOptions = agent.getRendererOptions(); + + Object printerJobO = rendererOptions.get(PrintRenderer.PRINTER_JOB); + if (printerJobO != null) { + if (!(printerJobO instanceof PrinterJob)) { + throw new IllegalArgumentException( + "Renderer option " + PrintRenderer.PRINTER_JOB + + " must be an instance of java.awt.print.PrinterJob, but an instance of " + + printerJobO.getClass().getName() + " was given."); + } + printerJob = (PrinterJob)printerJobO; + printerJob.setPageable(this); + } + Object o = rendererOptions.get(PrintRenderer.PAGES_MODE); + if (o != null) { + if (o instanceof PagesMode) { + this.mode = (PagesMode)o; + } else if (o instanceof String) { + this.mode = PagesMode.byName((String)o); + } else { + throw new IllegalArgumentException( + "Renderer option " + PrintRenderer.PAGES_MODE + + " must be an 'all', 'even', 'odd' or a PagesMode instance."); + } } + + o = rendererOptions.get(PrintRenderer.START_PAGE); + if (o != null) { + this.startNumber = getPositiveInteger(o); + } + o = rendererOptions.get(PrintRenderer.END_PAGE); + if (o != null) { + this.endNumber = getPositiveInteger(o); + } + if (this.endNumber >= 0 && this.endNumber < this.endNumber) { + this.endNumber = this.startNumber; + } + o = rendererOptions.get(PrintRenderer.COPIES); + if (o != null) { + this.copies = getPositiveInteger(o); + } + initializePrinterJob(); + } - printerJob = PrinterJob.getPrinterJob(); - printerJob.setJobName("FOP Document"); - printerJob.setCopies(copies); - if (System.getProperty("dialog") != null) { - if (!printerJob.printDialog()) { + private int getPositiveInteger(Object o) { + if (o instanceof Integer) { + Integer i = (Integer)o; + if (i.intValue() < 1) { throw new IllegalArgumentException( - "Printing cancelled by operator"); + "Value must be a positive Integer"); } + return i.intValue(); + } else if (o instanceof String) { + return Integer.parseInt((String)o); + } else { + throw new IllegalArgumentException( + "Value must be a positive integer"); } - printerJob.setPageable(this); } /** @return the PrinterJob instance that this renderer prints to */ @@ -126,6 +224,7 @@ public class PrintRenderer extends Java2DRenderer implements Pageable { this.startNumber = start; } + /** {@inheritDoc} */ public void stopRenderer() throws IOException { super.stopRenderer(); @@ -136,7 +235,8 @@ public class PrintRenderer extends Java2DRenderer implements Pageable { Vector numbers = getInvalidPageNumbers(); for (int i = numbers.size() - 1; i > -1; i--) { - // removePage(Integer.parseInt((String)numbers.elementAt(i))); + int page = ((Integer)numbers.elementAt(i)).intValue(); + pageViewportList.remove(page - 1); } try { @@ -149,7 +249,7 @@ public class PrintRenderer extends Java2DRenderer implements Pageable { clearViewportList(); } - public static int getIntProperty(String name, int def) { + private static int getIntProperty(String name, int def) { String propValue = System.getProperty(name); if (propValue != null) { try { @@ -166,20 +266,20 @@ public class PrintRenderer extends Java2DRenderer implements Pageable { Vector vec = new Vector(); int max = getNumberOfPages(); boolean isValid; - for (int i = 0; i < max; i++) { + for (int i = 1; i <= max; i++) { isValid = true; if (i < startNumber || i > endNumber) { isValid = false; - } else if (mode != EVEN_AND_ALL) { - if (mode == EVEN && ((i + 1) % 2 != 0)) { + } else if (mode != PagesMode.ALL) { + if (mode == PagesMode.EVEN && (i % 2 != 0)) { isValid = false; - } else if (mode == ODD && ((i + 1) % 2 != 1)) { + } else if (mode == PagesMode.ODD && (i % 2 == 0)) { isValid = false; } } if (!isValid) { - vec.add(Integer.toString(i)); + vec.add(new Integer(i)); } } return vec; @@ -219,6 +319,7 @@ public class PrintRenderer extends Java2DRenderer implements Pageable { } } + /** {@inheritDoc} */ public Printable getPrintable(int pageIndex) throws IndexOutOfBoundsException { return this; diff --git a/status.xml b/status.xml index 1d2f91e60..c2bb24a52 100644 --- a/status.xml +++ b/status.xml @@ -59,6 +59,14 @@ <action context="Renderers" dev="AC" importance="high" type="add"> Added de-duplication and externalization support for IOCA and GOCA data resource objects. </action> + <action context="Renderers" dev="JM" type="add" fixes-bug="41687"> + Restored ability to specify from/to and odd/even pages as well as the number of copies + for printing from the command-line. + </action> + <action context="Renderers" dev="JM" type="add" fixes-bug="44678" due-to="Antti Karanta"> + Added ability to pass a preconfigured PrinterJob instance to the PrintRenderer via + the rendering options map. + </action> <action context="Renderers" dev="JM" type="add" fixes-bug="44743" due-to="Yegor Kozlov"> Added a public accessor for reference to the current page to PDFGraphics2D. </action> diff --git a/test/java/org/apache/fop/fotreetest/FOTreeTestSuite.java b/test/java/org/apache/fop/fotreetest/FOTreeTestSuite.java index 04752064f..aa9af4226 100644 --- a/test/java/org/apache/fop/fotreetest/FOTreeTestSuite.java +++ b/test/java/org/apache/fop/fotreetest/FOTreeTestSuite.java @@ -35,6 +35,7 @@ import org.apache.commons.io.filefilter.NameFileFilter; import org.apache.commons.io.filefilter.PrefixFileFilter; import org.apache.commons.io.filefilter.SuffixFileFilter; import org.apache.commons.io.filefilter.TrueFileFilter; + import org.apache.fop.DebugHelper; import org.apache.fop.fo.flow.table.CollapsedConditionalBorderTestCase; import org.apache.fop.fo.flow.table.IllegalRowSpanTestCase; @@ -104,9 +105,14 @@ public final class FOTreeTestSuite { final FOTreeTester tester, final File f) { suite.addTest(new FOTreeTestCase(f.getName()) { public void runTest() throws Exception { - org.apache.commons.logging.LogFactory.getLog(this.getClass()).info("Starting " + f.getName()); - prepare(tester, f); - testMain(); + try { + prepare(tester, f); + testMain(); + } catch (Exception e) { + org.apache.commons.logging.LogFactory.getLog(this.getClass()).info( + "Error on " + f.getName()); + throw e; + } } }); } diff --git a/test/java/org/apache/fop/fotreetest/FOTreeTester.java b/test/java/org/apache/fop/fotreetest/FOTreeTester.java index 9c2a260bc..6ffad6989 100644 --- a/test/java/org/apache/fop/fotreetest/FOTreeTester.java +++ b/test/java/org/apache/fop/fotreetest/FOTreeTester.java @@ -25,14 +25,15 @@ import java.util.List; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; +import org.xml.sax.SAXException; +import org.xml.sax.XMLReader; +import org.xml.sax.helpers.XMLFilterImpl; + import org.apache.fop.apps.FOUserAgent; import org.apache.fop.apps.Fop; import org.apache.fop.apps.FopFactory; - import org.apache.fop.fotreetest.ext.TestElementMapping; -import org.xml.sax.SAXException; -import org.xml.sax.XMLReader; -import org.xml.sax.helpers.XMLFilterImpl; +import org.apache.fop.util.ConsoleEventListenerForTests; /** * Test driver class for FO tree tests. @@ -66,6 +67,8 @@ public class FOTreeTester { FOUserAgent ua = fopFactory.newFOUserAgent(); ua.setBaseURL(testFile.getParentFile().toURL().toString()); ua.setFOEventHandlerOverride(new DummyFOEventHandler(ua)); + ua.getEventBroadcaster().addEventListener( + new ConsoleEventListenerForTests(testFile.getName())); //Used to set values in the user agent through processing instructions reader = new PIListener(reader, ua); diff --git a/test/java/org/apache/fop/fotreetest/FOTreeUnitTester.java b/test/java/org/apache/fop/fotreetest/FOTreeUnitTester.java index e19547345..a7fa11950 100644 --- a/test/java/org/apache/fop/fotreetest/FOTreeUnitTester.java +++ b/test/java/org/apache/fop/fotreetest/FOTreeUnitTester.java @@ -26,11 +26,13 @@ import javax.xml.parsers.SAXParserFactory; import junit.framework.TestCase; +import org.xml.sax.XMLReader; + import org.apache.fop.apps.FOUserAgent; import org.apache.fop.apps.Fop; import org.apache.fop.apps.FopFactory; import org.apache.fop.fo.FOEventHandler; -import org.xml.sax.XMLReader; +import org.apache.fop.util.ConsoleEventListenerForTests; /** @@ -82,6 +84,8 @@ public abstract class FOTreeUnitTester extends TestCase { public void setUp(String filename, FOEventHandlerFactory factory) throws Exception { FOUserAgent ua = fopFactory.newFOUserAgent(); ua.setFOEventHandlerOverride(factory.createFOEventHandler(ua)); + ua.getEventBroadcaster().addEventListener( + new ConsoleEventListenerForTests(filename)); Fop fop = fopFactory.newFop(ua); diff --git a/test/java/org/apache/fop/intermediate/AreaTreeParserTestCase.java b/test/java/org/apache/fop/intermediate/AreaTreeParserTestCase.java index ced81932b..96aa89bc3 100644 --- a/test/java/org/apache/fop/intermediate/AreaTreeParserTestCase.java +++ b/test/java/org/apache/fop/intermediate/AreaTreeParserTestCase.java @@ -50,6 +50,7 @@ import org.apache.fop.area.RenderPagesModel; import org.apache.fop.fonts.FontInfo; import org.apache.fop.render.Renderer; import org.apache.fop.render.xml.XMLRenderer; +import org.apache.fop.util.ConsoleEventListenerForTests; //XML Unit 1.0: See http://xmlunit.sourceforge.net (BSD-style License) import org.custommonkey.xmlunit.XMLTestCase; @@ -170,6 +171,8 @@ public class AreaTreeParserTestCase extends XMLTestCase { FOUserAgent userAgent = fopFactory.newFOUserAgent(); try { userAgent.setBaseURL(testDir.toURL().toExternalForm()); + userAgent.getEventBroadcaster().addEventListener( + new ConsoleEventListenerForTests(testFile.getName())); } catch (MalformedURLException e) { //ignore, won't happen } diff --git a/test/java/org/apache/fop/intermediate/IntermediateFormatTestSuite.java b/test/java/org/apache/fop/intermediate/IntermediateFormatTestSuite.java index f72b2da87..68c81da81 100644 --- a/test/java/org/apache/fop/intermediate/IntermediateFormatTestSuite.java +++ b/test/java/org/apache/fop/intermediate/IntermediateFormatTestSuite.java @@ -56,10 +56,14 @@ public class IntermediateFormatTestSuite { final File f) { suite.addTest(new AreaTreeParserTestCase(f) { public void runTest() throws Exception { - org.apache.commons.logging.LogFactory.getLog( - this.getClass()).info("Starting " + f.getName()); - testParserToAT(); - testParserToPDF(); + try { + testParserToAT(); + testParserToPDF(); + } catch (Exception e) { + org.apache.commons.logging.LogFactory.getLog( + this.getClass()).error("Error on " + f.getName()); + throw e; + } } }); } diff --git a/test/java/org/apache/fop/layoutengine/LayoutEngineTestSuite.java b/test/java/org/apache/fop/layoutengine/LayoutEngineTestSuite.java index 99a63f2b7..0597e0e91 100644 --- a/test/java/org/apache/fop/layoutengine/LayoutEngineTestSuite.java +++ b/test/java/org/apache/fop/layoutengine/LayoutEngineTestSuite.java @@ -34,6 +34,14 @@ import javax.xml.transform.TransformerFactory; import javax.xml.transform.sax.SAXResult; import javax.xml.transform.stream.StreamSource; +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.DefaultHandler; + import org.apache.commons.io.FileUtils; import org.apache.commons.io.filefilter.AndFileFilter; import org.apache.commons.io.filefilter.IOFileFilter; @@ -42,15 +50,8 @@ import org.apache.commons.io.filefilter.NotFileFilter; import org.apache.commons.io.filefilter.PrefixFileFilter; import org.apache.commons.io.filefilter.SuffixFileFilter; import org.apache.commons.io.filefilter.TrueFileFilter; -import org.apache.fop.DebugHelper; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; -import org.xml.sax.helpers.DefaultHandler; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import org.apache.fop.DebugHelper; /** * JUnit test suit for running layout engine test under JUnit control. @@ -187,10 +188,14 @@ public class LayoutEngineTestSuite { final LayoutEngineTester tester, final File f) { suite.addTest(new LayoutEngineTestCase(f.getName()) { public void runTest() throws Exception { - org.apache.commons.logging.LogFactory.getLog( - this.getClass()).info("Starting " + f.getName()); - prepare(tester, f); - testMain(); + try { + prepare(tester, f); + testMain(); + } catch (Exception e) { + org.apache.commons.logging.LogFactory.getLog( + this.getClass()).error("Error on " + f.getName()); + throw e; + } } }); } diff --git a/test/java/org/apache/fop/layoutengine/LayoutEngineTester.java b/test/java/org/apache/fop/layoutengine/LayoutEngineTester.java index a10bfa0e3..bcd5f1db4 100644 --- a/test/java/org/apache/fop/layoutengine/LayoutEngineTester.java +++ b/test/java/org/apache/fop/layoutengine/LayoutEngineTester.java @@ -43,19 +43,23 @@ import javax.xml.transform.sax.TransformerHandler; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import org.xml.sax.SAXException; + +import org.apache.xpath.XPathAPI; +import org.apache.xpath.objects.XObject; + import org.apache.fop.apps.FOUserAgent; import org.apache.fop.apps.Fop; import org.apache.fop.apps.FopFactory; import org.apache.fop.apps.FormattingResults; import org.apache.fop.layoutmgr.ElementListObserver; import org.apache.fop.render.xml.XMLRenderer; -import org.apache.xpath.XPathAPI; -import org.apache.xpath.objects.XObject; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; -import org.xml.sax.SAXException; +import org.apache.fop.util.ConsoleEventListenerForTests; /** * Class for testing the FOP's layout engine using testcases specified in XML @@ -154,6 +158,9 @@ public class LayoutEngineTester { //Setup FOP for area tree rendering FOUserAgent ua = effFactory.newFOUserAgent(); ua.setBaseURL(testFile.getParentFile().toURL().toString()); + ua.getEventBroadcaster().addEventListener( + new ConsoleEventListenerForTests(testFile.getName())); + XMLRenderer atrenderer = new XMLRenderer(); atrenderer.setUserAgent(ua); atrenderer.setContentHandler(athandler); diff --git a/test/java/org/apache/fop/util/ConsoleEventListenerForTests.java b/test/java/org/apache/fop/util/ConsoleEventListenerForTests.java new file mode 100644 index 000000000..9e8a57285 --- /dev/null +++ b/test/java/org/apache/fop/util/ConsoleEventListenerForTests.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* $Id$ */ + +package org.apache.fop.util; + +import org.apache.fop.events.Event; +import org.apache.fop.events.EventFormatter; +import org.apache.fop.events.EventListener; +import org.apache.fop.events.model.EventSeverity; + +/** A simple event listener that writes the events to stdout and sterr. */ +public class ConsoleEventListenerForTests implements EventListener { + + private String name; + + public ConsoleEventListenerForTests(String name) { + this.name = name; + } + + /** {@inheritDoc} */ + public void processEvent(Event event) { + if (this.name != null) { + System.out.println("Test: " + this.name); + this.name = null; + } + String msg = EventFormatter.format(event); + EventSeverity severity = event.getSeverity(); + if (severity == EventSeverity.INFO) { + System.out.println(" [INFO ] " + msg); + } else if (severity == EventSeverity.WARN) { + System.out.println(" [WARN ] " + msg); + } else if (severity == EventSeverity.ERROR) { + System.out.println(" [ERROR] " + msg); + } else if (severity == EventSeverity.FATAL) { + System.out.println(" [FATAL] " + msg); + } else { + assert false; + } + } +}
\ No newline at end of file |