Incorrect URL (systemId) handling when running with Sun JRE 1.5.0 or above
--------------------------------------------------------------------------

         Key: XALANJ-2182
         URL: http://issues.apache.org/jira/browse/XALANJ-2182
     Project: XalanJ2
        Type: Bug
  Components: transformation  
    Versions: 2.6    
 Environment: Windows XP SP2, Sun JDK 1.5.0_01, Xalan 2.6.0
    Reporter: Rick Riemer
    Priority: Minor


When running the following piece of code:
Transformer identity = TransformerFactory.newInstance().newTransformer();
identity.setOutputProperty("method", "xml");
identity.setOutputProperty("indent", "yes");
identity.transform(src, new StreamResult(new File("file.xml")));

on a Sun JRE 1.5.0 or above, Xalan is unable to create a new file and thus 
throws a TransformerException.

This is caused by lines 225-235 in Xalan's TransformerIdentityImpl.java:
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);

As of JRE 1.5.0 Sun now generates URIs in a different way in StreamResult (see 
StreamResult.setSystemId()), an therefore the URI will start with file:/ 
instead of file:///. Thus FileOutputStream will not be able to open the file 
anymore, since the if-block never executes.

The suggested fix is to change the code to the following:
String fileURL = sresult.getSystemId();

File file = new File(new URI(fileURL));
m_outputStream = new java.io.FileOutputStream(file);


-- 
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
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to