diff options
Diffstat (limited to 'src/codegen/java/org/apache/fop/tools/EventProducerCollectorTask.java')
-rw-r--r-- | src/codegen/java/org/apache/fop/tools/EventProducerCollectorTask.java | 57 |
1 files changed, 34 insertions, 23 deletions
diff --git a/src/codegen/java/org/apache/fop/tools/EventProducerCollectorTask.java b/src/codegen/java/org/apache/fop/tools/EventProducerCollectorTask.java index 743811142..e00b05b55 100644 --- a/src/codegen/java/org/apache/fop/tools/EventProducerCollectorTask.java +++ b/src/codegen/java/org/apache/fop/tools/EventProducerCollectorTask.java @@ -22,6 +22,7 @@ package org.apache.fop.tools; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; +import java.io.OutputStream; import java.util.Iterator; import java.util.List; @@ -38,6 +39,7 @@ import javax.xml.transform.stream.StreamSource; import org.w3c.dom.Node; +import org.apache.commons.io.IOUtils; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.DirectoryScanner; import org.apache.tools.ant.Project; @@ -95,7 +97,7 @@ public class EventProducerCollectorTask extends Task { = (SAXTransformerFactory)SAXTransformerFactory.newInstance(); //Generate fresh generated translation file as template - Source src = new StreamSource(getModelFile()); + Source src = new StreamSource(getModelFile().toURI().toURL().toExternalForm()); StreamSource xslt1 = new StreamSource( getClass().getResourceAsStream(MODEL2TRANSLATION)); if (xslt1.getInputStream() == null) { @@ -109,7 +111,7 @@ public class EventProducerCollectorTask extends Task { Node sourceDocument; if (resultExists) { //Load existing translation file into memory (because we overwrite it later) - src = new StreamSource(getTranslationFile()); + src = new StreamSource(getTranslationFile().toURI().toURL().toExternalForm()); domres = new DOMResult(); transformer = tFactory.newTransformer(); transformer.transform(src, domres); @@ -121,29 +123,38 @@ public class EventProducerCollectorTask extends Task { //Generate translation file (with potentially new translations) src = new DOMSource(sourceDocument); - Result res = new StreamResult(getTranslationFile()); - StreamSource xslt2 = new StreamSource( - getClass().getResourceAsStream(MERGETRANSLATION)); - if (xslt2.getInputStream() == null) { - throw new FileNotFoundException(MERGETRANSLATION + " not found"); - } - transformer = tFactory.newTransformer(xslt2); - transformer.setURIResolver(new URIResolver() { - public Source resolve(String href, String base) throws TransformerException { - if ("my:dom".equals(href)) { - return new DOMSource(generated); + + //The following triggers a bug in older Xalan versions + //Result res = new StreamResult(getTranslationFile()); + OutputStream out = new java.io.FileOutputStream(getTranslationFile()); + out = new java.io.BufferedOutputStream(out); + Result res = new StreamResult(out); + try { + StreamSource xslt2 = new StreamSource( + getClass().getResourceAsStream(MERGETRANSLATION)); + if (xslt2.getInputStream() == null) { + throw new FileNotFoundException(MERGETRANSLATION + " not found"); + } + transformer = tFactory.newTransformer(xslt2); + transformer.setURIResolver(new URIResolver() { + public Source resolve(String href, String base) throws TransformerException { + if ("my:dom".equals(href)) { + return new DOMSource(generated); + } + return null; } - return null; + }); + if (resultExists) { + transformer.setParameter("generated-url", "my:dom"); } - }); - if (resultExists) { - transformer.setParameter("generated-url", "my:dom"); - } - transformer.transform(src, res); - if (resultExists) { - log("Translation file updated: " + getTranslationFile()); - } else { - log("Translation file generated: " + getTranslationFile()); + transformer.transform(src, res); + if (resultExists) { + log("Translation file updated: " + getTranslationFile()); + } else { + log("Translation file generated: " + getTranslationFile()); + } + } finally { + IOUtils.closeQuietly(out); } } catch (TransformerException te) { throw new IOException(te.getMessage()); |