[ 
https://issues.apache.org/jira/browse/XALANJ-2182?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12865209#action_12865209
 ] 

Michael Vorburger commented on XALANJ-2182:
-------------------------------------------

Well... this one wasn't really a duplicate of XALANJ-1978 actually, because 
XALANJ-1978  only seems to have addressed the "with file:/ instead of file:///. 
" issue, but not the actual root cause here which is incorrect URL handling in 
TransformerIdentityImpl, which the proposed fix above would have addressed but 
which what was done in XALANJ-1978 has not addressed.

XALANJ-2461 is still open about the root cause of incorrect URL unescaping in 
TransformerIdentityImpl.

> Incorrect URL (systemId) handling when running with Sun JRE 1.5.0 or above
> --------------------------------------------------------------------------
>
>                 Key: XALANJ-2182
>                 URL: https://issues.apache.org/jira/browse/XALANJ-2182
>             Project: XalanJ2
>          Issue Type: Bug
>          Components: transformation
>    Affects Versions: 2.6
>         Environment: Windows XP SP2, Sun JDK 1.5.0_01, Xalan 2.6.0
>            Reporter: Rick Riemer
>            Priority: Minor
>             Fix For: 2.7
>
>
> 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.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-dev-unsubscr...@xml.apache.org
For additional commands, e-mail: xalan-dev-h...@xml.apache.org

Reply via email to