diff options
author | Jeremias Maerki <jeremias@apache.org> | 2006-02-17 13:48:26 +0000 |
---|---|---|
committer | Jeremias Maerki <jeremias@apache.org> | 2006-02-17 13:48:26 +0000 |
commit | fbfdbea38c593b79b29656276873309d1b33865f (patch) | |
tree | a550217804c5214ea4c39e683b65050429cbea56 /src | |
parent | a2010e775b602f00a641cd0b85576db446c037d8 (diff) | |
download | xmlgraphics-fop-fbfdbea38c593b79b29656276873309d1b33865f.tar.gz xmlgraphics-fop-fbfdbea38c593b79b29656276873309d1b33865f.zip |
Added support for userconfig attribute in FOP Ant task.
Submitted by: Jirí Mareš <Jiri.Mares.at.svt.cz>
In addition to that:
Now deleting the output file when an exception is encountered.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@378508 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r-- | src/java/org/apache/fop/tools/anttasks/Fop.java | 36 |
1 files changed, 31 insertions, 5 deletions
diff --git a/src/java/org/apache/fop/tools/anttasks/Fop.java b/src/java/org/apache/fop/tools/anttasks/Fop.java index 10badfefa..1096feb5a 100644 --- a/src/java/org/apache/fop/tools/anttasks/Fop.java +++ b/src/java/org/apache/fop/tools/anttasks/Fop.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2005 The Apache Software Foundation. + * Copyright 1999-2006 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,6 +27,7 @@ import org.apache.tools.ant.types.FileSet; import org.apache.tools.ant.util.GlobPatternMapper; // Java +import java.io.BufferedOutputStream; import java.io.File; import java.io.IOException; import java.io.OutputStream; @@ -39,8 +40,12 @@ import org.apache.fop.apps.FOUserAgent; import org.apache.fop.apps.MimeConstants; import org.apache.fop.cli.InputHandler; +import org.apache.avalon.framework.configuration.Configuration; +import org.apache.avalon.framework.configuration.ConfigurationException; +import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder; import org.apache.commons.logging.impl.SimpleLog; import org.apache.commons.logging.Log; +import org.xml.sax.SAXException; /** * Wrapper for FOP which allows it to be accessed from within an Ant task. @@ -403,8 +408,20 @@ class FOPTaskStarter { */ public void run() throws FOPException { //Setup configuration + Configuration userConfig = null; if (task.getUserconfig() != null) { - /**@todo implement me */ + if (task.getUserconfig() != null) { + DefaultConfigurationBuilder configBuilder = new DefaultConfigurationBuilder(); + try { + userConfig = configBuilder.buildFromFile(task.getUserconfig()); + } catch (SAXException e) { + throw new FOPException(e); + } catch (ConfigurationException e) { + throw new FOPException(e); + } catch (IOException e) { + throw new FOPException(e); + } + } } //Set base directory @@ -450,7 +467,7 @@ class FOPTaskStarter { // output file is older than input file if (task.getForce() || !outf.exists() || (task.getFofile().lastModified() > outf.lastModified() )) { - render(task.getFofile(), outf, outputFormat); + render(task.getFofile(), outf, outputFormat, userConfig); actioncount++; } else if (outf.exists() && (task.getFofile().lastModified() <= outf.lastModified() )) { @@ -502,7 +519,7 @@ class FOPTaskStarter { // output file is older than input file if (task.getForce() || !outf.exists() || (f.lastModified() > outf.lastModified() )) { - render(f, outf, outputFormat); + render(f, outf, outputFormat, userConfig); actioncount++; } else if (outf.exists() && (f.lastModified() <= outf.lastModified() )) { skippedcount++; @@ -521,12 +538,13 @@ class FOPTaskStarter { } private void render(File foFile, File outFile, - String outputFormat) throws FOPException { + String outputFormat, Configuration userConfig) throws FOPException { InputHandler inputHandler = new InputHandler(foFile); OutputStream out = null; try { out = new java.io.FileOutputStream(outFile); + out = new BufferedOutputStream(out); } catch (Exception ex) { throw new BuildException("Failed to open " + outFile, ex); } @@ -535,10 +553,15 @@ class FOPTaskStarter { task.log(foFile + " -> " + outFile, Project.MSG_INFO); } + boolean success = false; try { FOUserAgent userAgent = new FOUserAgent(); userAgent.setBaseURL(this.baseURL); + if (userConfig != null) { + userAgent.setUserConfig(userConfig); + } inputHandler.renderTo(userAgent, outputFormat, out); + success = true; } catch (Exception ex) { throw new BuildException(ex); } finally { @@ -547,6 +570,9 @@ class FOPTaskStarter { } catch (IOException ioe) { logger.error("Error closing output file", ioe); } + if (!success) { + outFile.delete(); + } } } |