[
http://issues.apache.org/jira/browse/XALANJ-1978?page=comments#action_57689 ]
D Gardner commented on XALANJ-1978:
-----------------------------------
I have reproduced the issue described. Note that the
problem only occurs on Java 5.0/1.5 NOT Java 1.4, so
that may be a problem when trying to reproduce it.
The offending code has not changed between Xalan 2.6.0
and the latest CVS version (as of 17-Jan-2005). The
problem lies in the interaction between the Java 5.0
version of javax.xml.transform.stream.StreamResult and
the org.apache.xalan.transformer.TransformerImpl class.
For a file like "C:\test.xml", the following occurs:
new StreamResult(new File("C:\\test.xml")).getSystemId();
returns "file:///C:/Temp/test.xml" on Java 1.4, but it
returns "file:/C:/Temp/test.xml" on Java 1.5.
The code in TransformerImpl that uses the StreamResult
attempts to remove the "file:///" if it exists and then
creates a new FileOutputStream with the resulting file
name. The file name will be "C:/Temp/test.xml" on Java
1.4, but "file:/C:/Temp/test.xml" on Java 1.5, as the
extra "//" characters were not matched. FileOutputStream
will invoke:
new File("file:/C:/Temp/test.xml");
and that results in a FileNotFoundException, exactly as
described in the original bug report, as the "file:/"
prefix is invalid.
In TransformerImpl, changing this code (line 1108 onwards
in 2.6.0):
String fileURL = sresult.getSystemId();
if (fileURL.startsWith("file:///"))
{
if (fileURL.substring(8).indexOf(":") >0)
fileURL = fileURL.substring(8);
else
fileURL = fileURL.substring(7);
}
m_outputStream = new java.io.FileOutputStream(fileURL);
to this code:
// Catch MalformedURLException, etc., of course.
String fileURL = new URL(sresult.getSystemId()).getFile();
m_outputStream = new java.io.FileOutputStream(fileURL);
will fix the problem on Java 1.5 and it still works with
Java 1.3 and 1.4.
> Using StreamResult with File argument throws exception
> ------------------------------------------------------
>
> Key: XALANJ-1978
> URL: http://issues.apache.org/jira/browse/XALANJ-1978
> Project: XalanJ2
> Type: Bug
> Components: JAXP, Xalan-interpretive
> Versions: 2.6
> Environment: Windows 2000
> Java 1.5
> Reporter: Thomas Mathis
>
> Source-Code:
> ============
> import java.io.*;
> import org.w3c.dom.Document;
> import javax.xml.parsers.DocumentBuilderFactory;
> import javax.xml.transform.TransformerFactory;
> import javax.xml.transform.stream.StreamResult;
> import javax.xml.transform.Source;
> import javax.xml.transform.dom.DOMSource;
> import javax.xml.transform.Result;
> import javax.xml.transform.Transformer;
> public class JDK5Test {
> public JDK5Test() {
> }
> public static void main(String[] args) {
> JDK5Test test = new JDK5Test();
> try {
> test.test1();
> } catch (Exception ex) {
> ex.printStackTrace();
> }
> }
> protected void test1()
> throws Exception
> {
> File destFile = new File("test.xml");
> destFile.delete();
> Document doc =
> DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
> Source source = new DOMSource( doc );
> Result result = new StreamResult( destFile );
> TransformerFactory tf = TransformerFactory.newInstance();
> Transformer transformer = tf.newTransformer();
> transformer.transform(source, result);
> System.out.println("length=" + destFile.length() );
> Thread.sleep(3000);
> System.out.println("length=" + destFile.length() );
> }
> }
> StackTrace:
> ===========
> javax.xml.transform.TransformerException: java.io.FileNotFoundException:
> file:\C:\JDK5Test\test.xml (Die Syntax f�r den Dateinamen, Verzeichnisnamen
> oder die Datentr�gerbezeichnung ist falsch)
> at
> org.apache.xalan.transformer.TransformerIdentityImpl.createResultContentHandler(TransformerIdentityImpl.java:245)
> at
> org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:278)
> at JDK5Test.test1(JDK5Test.java:43)
> at JDK5Test.main(JDK5Test.java:19)
> Caused by: java.io.FileNotFoundException:
> file:\E:\jbprojectX\JDK5Test\test.xml (Die Syntax f�r den Dateinamen,
> Verzeichnisnamen oder die Datentr�gerbezeichnung ist falsch)
> at java.io.FileOutputStream.open(Native Method)
> at java.io.FileOutputStream.<init>(FileOutputStream.java:179)
> at java.io.FileOutputStream.<init>(FileOutputStream.java:70)
> at
> org.apache.xalan.transformer.TransformerIdentityImpl.createResultContentHandler(TransformerIdentityImpl.java:235)
> ... 3 more
> ---------
> java.io.FileNotFoundException: file:\C:\JDK5Test\test.xml (Die Syntax f�r den
> Dateinamen, Verzeichnisnamen oder die Datentr�gerbezeichnung ist falsch)
> at java.io.FileOutputStream.open(Native Method)
> at java.io.FileOutputStream.<init>(FileOutputStream.java:179)
> at java.io.FileOutputStream.<init>(FileOutputStream.java:70)
> at
> org.apache.xalan.transformer.TransformerIdentityImpl.createResultContentHandler(TransformerIdentityImpl.java:235)
> at
> org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:278)
> at JDK5Test.test1(JDK5Test.java:43)
> at JDK5Test.main(JDK5Test.java:19)
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]