URI representation

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

URI representation

cmarchand

 

 

Hi,

 

I have a strange problem :

in a xsl, I generate a

<xsl href="{resolve-uri($xxx)}"/>

 

Then, in a Java program I have this :

String href = fileNode.getAttributeValue(Xslt.ATTR_HREF);

File f = new File (href);

String uri = f.toURI().toURL().toExternalForm();

System.out.println(uri);

StreamSource source = new StreamSource(new FileInputStream(f));

source.setSystemId(uri);

xslCompile.compile(source);

 

The generated XML is like this :

<xsl href="file:/home/ext-cmarchand/.../test.xsl"/>

And java output is

file:/usr/local/current-folder/file:/home/ext-cmarchand/.../test.xsl

and then xslCompiler.compile fails... normal.

 

It seems that URI format is not the same between xpath:resolve-uri and Java new File(String path)

According to http://www.ietf.org/rfc/rfc3986.txt, the format should be file:///home/ext-cmarchand/...

 

My XSL is run under calabash, with default URIResolver.

I don't know what to think about all this, and where to look at... should the URIResolver.resolve() be called when calling resolve-uri(...), what the expected URI format returned by, what new File(String path) should do when path is an URI, etc...

Is it a calabash URIResolver issue, is this a Java issue, is this a saxon issue... ?

 

As a workaround, I use this :

File f = href.startsWith("file:") ? new File(new URI(href)) : new File(href);

 

Any help will be much appreciated...

 

Best regards,

Christophe

 

 


------------------------------------------------------------------------------

_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help 
Reply | Threaded
Open this post in threaded view
|

Re: URI representation

Michael Kay
Because href is a java.lang.String, not a java.net.URI, your call on “new File(href)” calls the File(String) constructor, not the File(URI) constructor. This expects a “pathname”, which is not the same as a URI-converted-to-a-string. Try new File(new URI(href)) (I see you’ve already done that…)

If the URI has a scheme other than “file” then this isn’t going to work, but nor is your existing code.

Michael Kay
Saxonica 


On 2 Oct 2015, at 13:45, [hidden email] wrote:

 
 

Hi,

 

I have a strange problem :

in a xsl, I generate a

<xsl href="{resolve-uri($xxx)}"/>

 

Then, in a Java program I have this :

String href = fileNode.getAttributeValue(Xslt.ATTR_HREF);

File f = new File (href);

String uri = f.toURI().toURL().toExternalForm();

System.out.println(uri);

StreamSource source = new StreamSource(new FileInputStream(f));

source.setSystemId(uri);

xslCompile.compile(source);

 

The generated XML is like this :

<xsl href="file:/home/ext-cmarchand/.../test.xsl"/>

And java output is

file:/usr/local/current-folder/file:/home/ext-cmarchand/.../test.xsl

and then xslCompiler.compile fails... normal.

 

It seems that URI format is not the same between xpath:resolve-uri and Java new File(String path)

According to http://www.ietf.org/rfc/rfc3986.txt, the format should be file:///home/ext-cmarchand/...

 

My XSL is run under calabash, with default URIResolver.

I don't know what to think about all this, and where to look at... should the URIResolver.resolve() be called when calling resolve-uri(...), what the expected URI format returned by, what new File(String path) should do when path is an URI, etc...

Is it a calabash URIResolver issue, is this a Java issue, is this a saxon issue... ?

 

As a workaround, I use this :

File f = href.startsWith("file:") ? new File(new URI(href)) : new File(href);

 

Any help will be much appreciated...

 

Best regards,

Christophe

 
 
------------------------------------------------------------------------------
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help


------------------------------------------------------------------------------

_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help 
Reply | Threaded
Open this post in threaded view
|

Re: URI representation

cmarchand

 

 

Ok, so the difference is between what is expected by the two constructors.

 

And are file:/home/ext-cmarchand/test.xsl and file:///home/ext-cmarchand/test.xsl equivalent ?

 

Thanks a lot,

Christophe

 

 

 

Le 2015-10-02 15:58, Michael Kay a écrit :

Because href is a java.lang.String, not a java.net.URI, your call on "new File(href)" calls the File(String) constructor, not the File(URI) constructor. This expects a "pathname", which is not the same as a URI-converted-to-a-string. Try new File(new URI(href)) (I see you've already done that...)
 
If the URI has a scheme other than "file" then this isn't going to work, but nor is your existing code.
 
Michael Kay
Saxonica 
 

On 2 Oct 2015, at 13:45, [hidden email] wrote:
 
 

Hi,

 

I have a strange problem :

in a xsl, I generate a

<xsl href="{resolve-uri($xxx)}"/>

 

Then, in a Java program I have this :

String href = fileNode.getAttributeValue(Xslt.ATTR_HREF);

File f = new File (href);

String uri = f.toURI().toURL().toExternalForm();

System.out.println(uri);

StreamSource source = new StreamSource(new FileInputStream(f));

source.setSystemId(uri);

xslCompile.compile(source);

 

The generated XML is like this :

<xsl href="file:/home/ext-cmarchand/.../test.xsl"/>

And java output is

file:/usr/local/current-folder/file:/home/ext-cmarchand/.../test.xsl

and then xslCompiler.compile fails... normal.

 

It seems that URI format is not the same between xpath:resolve-uri and Java new File(String path)

According to http://www.ietf.org/rfc/rfc3986.txt, the format should be file:///home/ext-cmarchand/...

 

My XSL is run under calabash, with default URIResolver.

I don't know what to think about all this, and where to look at... should the URIResolver.resolve() be called when calling resolve-uri(...), what the expected URI format returned by, what new File(String path) should do when path is an URI, etc...

Is it a calabash URIResolver issue, is this a Java issue, is this a saxon issue... ?

 

As a workaround, I use this :

File f = href.startsWith("file:") ? new File(new URI(href)) : new File(href);

 

Any help will be much appreciated...

 

Best regards,

Christophe

 
 
------------------------------------------------------------------------------
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help


------------------------------------------------------------------------------

_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help

------------------------------------------------------------------------------

_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help 
Reply | Threaded
Open this post in threaded view
|

Re: URI representation

Michael Kay
I think that entire PhD theses have been written on the question of URI equivalence…

But yes, they both represent a URI with an absent authority component, so they should generally be treated as equivalent. That does not always mean they will be: it’s quite common for URIs to be compared as strings.

Michael Kay
Saxonica


On 2 Oct 2015, at 15:02, [hidden email] wrote:

 
 

Ok, so the difference is between what is expected by the two constructors.

 

And are file:/home/ext-cmarchand/test.xsl and file:///home/ext-cmarchand/test.xsl equivalent ?

 

Thanks a lot,

Christophe

 
 
 

Le 2015-10-02 15:58, Michael Kay a écrit :

Because href is a java.lang.String, not a java.net.URI, your call on "new File(href)" calls the File(String) constructor, not the File(URI) constructor. This expects a "pathname", which is not the same as a URI-converted-to-a-string. Try new File(new URI(href)) (I see you've already done that...)
 
If the URI has a scheme other than "file" then this isn't going to work, but nor is your existing code.
 
Michael Kay
Saxonica 
 

On 2 Oct 2015, at 13:45, [hidden email] wrote:
 
 

Hi,

 

I have a strange problem :

in a xsl, I generate a

<xsl href="{resolve-uri($xxx)}"/>

 

Then, in a Java program I have this :

String href = fileNode.getAttributeValue(Xslt.ATTR_HREF);

File f = new File (href);

String uri = f.toURI().toURL().toExternalForm();

System.out.println(uri);

StreamSource source = new StreamSource(new FileInputStream(f));

source.setSystemId(uri);

xslCompile.compile(source);

 

The generated XML is like this :

<xsl href="file:/home/ext-cmarchand/.../test.xsl"/>

And java output is

file:/usr/local/current-folder/file:/home/ext-cmarchand/.../test.xsl

and then xslCompiler.compile fails... normal.

 

It seems that URI format is not the same between xpath:resolve-uri and Java new File(String path)

According to http://www.ietf.org/rfc/rfc3986.txt, the format should be file:///home/ext-cmarchand/...

 

My XSL is run under calabash, with default URIResolver.

I don't know what to think about all this, and where to look at... should the URIResolver.resolve() be called when calling resolve-uri(...), what the expected URI format returned by, what new File(String path) should do when path is an URI, etc...

Is it a calabash URIResolver issue, is this a Java issue, is this a saxon issue... ?

 

As a workaround, I use this :

File f = href.startsWith("file:") ? new File(new URI(href)) : new File(href);

 

Any help will be much appreciated...

 

Best regards,

Christophe

 
 
------------------------------------------------------------------------------
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help


------------------------------------------------------------------------------

_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help
------------------------------------------------------------------------------
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help


------------------------------------------------------------------------------

_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help