import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
+import java.io.OutputStream;
import java.util.Iterator;
import java.util.List;
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;
//Generate translation file (with potentially new translations)
src = new DOMSource(sourceDocument);
- Result res = new StreamResult(getTranslationFile().toURI().toURL().toExternalForm());
- 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());
import java.io.File;
import java.io.IOException;
+import java.io.OutputStream;
import java.io.Serializable;
import java.util.Iterator;
import java.util.Map;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
+import org.apache.commons.io.IOUtils;
+
import org.apache.xmlgraphics.util.XMLizable;
/**
}
private void writeXMLizable(XMLizable object, File outputFile) throws IOException {
- //Result res = new StreamResult(outputFile); //Does not seem to work in all environments
- Result res = new StreamResult(outputFile.toURI().toURL().toExternalForm());
+ //These two approaches do not seem to work in all environments:
+ //Result res = new StreamResult(outputFile);
+ //Result res = new StreamResult(outputFile.toURI().toURL().toExternalForm());
+ //With an old Xalan version: file:/C:/.... --> file:\C:\.....
+ OutputStream out = new java.io.FileOutputStream(outputFile);
+ out = new java.io.BufferedOutputStream(out);
+ Result res = new StreamResult(out);
try {
SAXTransformerFactory tFactory
= (SAXTransformerFactory)SAXTransformerFactory.newInstance();
+ System.out.println(tFactory.getClass().getName());
TransformerHandler handler = tFactory.newTransformerHandler();
Transformer transformer = handler.getTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
throw new IOException(e.getMessage());
} catch (SAXException e) {
throw new IOException(e.getMessage());
+ } finally {
+ IOUtils.closeQuietly(out);
}
}