ModuleURIResolver not used if set from Initializer

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

ModuleURIResolver not used if set from Initializer

Florent Georges-3
Hi,

I have a problem with an Initializer setting a ModuleURIResolver on
the Configuration object.  It seems the resolver is never called.  To
reproduce, here is TestInitializer.java:

    import net.sf.saxon.Configuration;
    import net.sf.saxon.lib.Initializer;
    import javax.xml.transform.stream.StreamSource;
    import net.sf.saxon.lib.ModuleURIResolver;

    public class TestInitializer
   implements Initializer
    {
@Override
public void initialize(Configuration config)
{
   System.err.println("Initialize...");
   config.setModuleURIResolver(new Resolver());
}

private static final class Resolver
implements ModuleURIResolver
{
   @Override
   public StreamSource[] resolve(String ns, String base, String[] locs)
   {
System.err.println("Resolve: " + ns + ", " + base);
return null;
   }
}
    }

If you compile it with (from within the same dir where the Java file
is, adapt the path to the Saxon JAR on your machine):

    javac -cp .:/path/to/saxon9he.jar TestInitializer.java 

Given the following query file in the same dir (named query.xq):

    import module namespace h = "http://example.org/ns/hello";
    h:new-hello('world')

Execute Saxon with (adapt the path to the Saxon JAR):

    java -cp .:/path/to/saxon9he.jar net.sf.saxon.Query \
        -init:TestInitializer query.xq

The output is:

    Initialize...
    Error on line 2 column 1 of query.xq:
      XQST0059 XQuery static error near #...tp://example.org/ns/hello"; <#:
        Cannot locate module for namespace http://example.org/ns/hello
    Static error(s) in query

That is, the initializer is called, setting the ModuleURIResolver on
the configuration object it receives, but the import statement fails
without the resolver being called.

I use Saxon 9.6.0.7 (I can't use 9.7 already, waiting for some other
components to be adapted to Saxon 9.7 first).  But I tested this
example with 9.7.0.1 and it gives the same result.

Did I miss anything?  Is there anything specific to do in order to set
a module URI resolver from within an initializer?

Regards,

-- 
Florent Georges
http://fgeorges.org/
http://h2oconsulting.be/



------------------------------------------------------------------------------
Go from Idea to Many App Stores Faster with Intel(R) XDK
Give your users amazing mobile app experiences with Intel(R) XDK.
Use one codebase in this all-in-one HTML5 development environment.
Design, debug & build mobile apps & 2D/3D high-impact games for multiple OSs.
http://pubads.g.doubleclick.net/gampad/clk?id=254741911&iu=/4140
_______________________________________________
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: ModuleURIResolver not used if set from Initializer

Michael Kay
Thanks Florent. Logged here:


patch committed and tested; will appear in next maintenance release.

Michael Kay
Saxonica


On 7 Dec 2015, at 12:14, Florent Georges <[hidden email]> wrote:

Hi,

I have a problem with an Initializer setting a ModuleURIResolver on
the Configuration object.  It seems the resolver is never called.  To
reproduce, here is TestInitializer.java:

    import net.sf.saxon.Configuration;
    import net.sf.saxon.lib.Initializer;
    import javax.xml.transform.stream.StreamSource;
    import net.sf.saxon.lib.ModuleURIResolver;

    public class TestInitializer
   implements Initializer
    {
@Override
public void initialize(Configuration config)
{
   System.err.println("Initialize...");
   config.setModuleURIResolver(new Resolver());
}

private static final class Resolver
implements ModuleURIResolver
{
   @Override
   public StreamSource[] resolve(String ns, String base, String[] locs)
   {
System.err.println("Resolve: " + ns + ", " + base);
return null;
   }
}
    }

If you compile it with (from within the same dir where the Java file
is, adapt the path to the Saxon JAR on your machine):

    javac -cp .:/path/to/saxon9he.jar TestInitializer.java 

Given the following query file in the same dir (named query.xq):

    import module namespace h = "http://example.org/ns/hello";
    h:new-hello('world')

Execute Saxon with (adapt the path to the Saxon JAR):

    java -cp .:/path/to/saxon9he.jar net.sf.saxon.Query \
        -init:TestInitializer query.xq

The output is:

    Initialize...
    Error on line 2 column 1 of query.xq:
      XQST0059 XQuery static error near #...<a href="tp://example.org/ns/hello" class="">tp://example.org/ns/hello"; <#:
        Cannot locate module for namespace http://example.org/ns/hello
    Static error(s) in query

That is, the initializer is called, setting the ModuleURIResolver on
the configuration object it receives, but the import statement fails
without the resolver being called.

I use Saxon 9.6.0.7 (I can't use 9.7 already, waiting for some other
components to be adapted to Saxon 9.7 first).  But I tested this
example with 9.7.0.1 and it gives the same result.

Did I miss anything?  Is there anything specific to do in order to set
a module URI resolver from within an initializer?

Regards,

-- 
Florent Georges


------------------------------------------------------------------------------
Go from Idea to Many App Stores Faster with Intel(R) XDK
Give your users amazing mobile app experiences with Intel(R) XDK.
Use one codebase in this all-in-one HTML5 development environment.
Design, debug & build mobile apps & 2D/3D high-impact games for multiple OSs.
http://pubads.g.doubleclick.net/gampad/clk?id=254741911&iu=/4140_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help


------------------------------------------------------------------------------
Go from Idea to Many App Stores Faster with Intel(R) XDK
Give your users amazing mobile app experiences with Intel(R) XDK.
Use one codebase in this all-in-one HTML5 development environment.
Design, debug & build mobile apps & 2D/3D high-impact games for multiple OSs.
http://pubads.g.doubleclick.net/gampad/clk?id=254741911&iu=/4140
_______________________________________________
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: ModuleURIResolver not used if set from Initializer

Florent Georges-3
Thank you for the quick support, Mike.  I am sad to see it is a bug
(one for which there is no workaround I guess), but at least I am now
reassured about my own sanity.

Regards,

--
Florent Georges
http://fgeorges.org/
http://h2oconsulting.be/


On 7 December 2015 at 17:04, Michael Kay wrote:

> Thanks Florent. Logged here:
>
> https://saxonica.plan.io/issues/2532
>
> patch committed and tested; will appear in next maintenance release.
>
> Michael Kay
> Saxonica
>
>
> On 7 Dec 2015, at 12:14, Florent Georges <[hidden email]> wrote:
>
> Hi,
>
> I have a problem with an Initializer setting a ModuleURIResolver on
> the Configuration object.  It seems the resolver is never called.  To
> reproduce, here is TestInitializer.java:
>
>     import net.sf.saxon.Configuration;
>     import net.sf.saxon.lib.Initializer;
>     import javax.xml.transform.stream.StreamSource;
>     import net.sf.saxon.lib.ModuleURIResolver;
>
>     public class TestInitializer
>    implements Initializer
>     {
> @Override
> public void initialize(Configuration config)
> {
>    System.err.println("Initialize...");
>    config.setModuleURIResolver(new Resolver());
> }
>
> private static final class Resolver
> implements ModuleURIResolver
> {
>    @Override
>    public StreamSource[] resolve(String ns, String base, String[] locs)
>    {
> System.err.println("Resolve: " + ns + ", " + base);
> return null;
>    }
> }
>     }
>
> If you compile it with (from within the same dir where the Java file
> is, adapt the path to the Saxon JAR on your machine):
>
>     javac -cp .:/path/to/saxon9he.jar TestInitializer.java
>
> Given the following query file in the same dir (named query.xq):
>
>     import module namespace h = "http://example.org/ns/hello";
>     h:new-hello('world')
>
> Execute Saxon with (adapt the path to the Saxon JAR):
>
>     java -cp .:/path/to/saxon9he.jar net.sf.saxon.Query \
>         -init:TestInitializer query.xq
>
> The output is:
>
>     Initialize...
>     Error on line 2 column 1 of query.xq:
>       XQST0059 XQuery static error near #...tp://example.org/ns/hello"; <#:
>         Cannot locate module for namespace http://example.org/ns/hello
>     Static error(s) in query
>
> That is, the initializer is called, setting the ModuleURIResolver on
> the configuration object it receives, but the import statement fails
> without the resolver being called.
>
> I use Saxon 9.6.0.7 (I can't use 9.7 already, waiting for some other
> components to be adapted to Saxon 9.7 first).  But I tested this
> example with 9.7.0.1 and it gives the same result.
>
> Did I miss anything?  Is there anything specific to do in order to set
> a module URI resolver from within an initializer?
>
> Regards,
>
> --
> Florent Georges
> http://fgeorges.org/
> http://h2oconsulting.be/
>
>
> ------------------------------------------------------------------------------
> Go from Idea to Many App Stores Faster with Intel(R) XDK
> Give your users amazing mobile app experiences with Intel(R) XDK.
> Use one codebase in this all-in-one HTML5 development environment.
> Design, debug & build mobile apps & 2D/3D high-impact games for multiple
> OSs.
> http://pubads.g.doubleclick.net/gampad/clk?id=254741911&iu=/4140_______________________________________________
> saxon-help mailing list archived at http://saxon.markmail.org/
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/saxon-help
>
>
>
> ------------------------------------------------------------------------------
> Go from Idea to Many App Stores Faster with Intel(R) XDK
> Give your users amazing mobile app experiences with Intel(R) XDK.
> Use one codebase in this all-in-one HTML5 development environment.
> Design, debug & build mobile apps & 2D/3D high-impact games for multiple
> OSs.
> http://pubads.g.doubleclick.net/gampad/clk?id=254741911&iu=/4140
> _______________________________________________
> saxon-help mailing list archived at http://saxon.markmail.org/
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/saxon-help

------------------------------------------------------------------------------
Go from Idea to Many App Stores Faster with Intel(R) XDK
Give your users amazing mobile app experiences with Intel(R) XDK.
Use one codebase in this all-in-one HTML5 development environment.
Design, debug & build mobile apps & 2D/3D high-impact games for multiple OSs.
http://pubads.g.doubleclick.net/gampad/clk?id=254741911&iu=/4140
_______________________________________________
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: ModuleURIResolver not used if set from Initializer

Michael Kay
A workaround might be to define the ModuleURIResolver in a configuration file, which you can name on the command line using -config; or use the -mr option directly

Michael Kay
Saxonica

> On 7 Dec 2015, at 16:18, Florent Georges <[hidden email]> wrote:
>
> Thank you for the quick support, Mike.  I am sad to see it is a bug
> (one for which there is no workaround I guess), but at least I am now
> reassured about my own sanity.
>
> Regards,
>
> --
> Florent Georges
> http://fgeorges.org/
> http://h2oconsulting.be/
>
>
> On 7 December 2015 at 17:04, Michael Kay wrote:
>> Thanks Florent. Logged here:
>>
>> https://saxonica.plan.io/issues/2532
>>
>> patch committed and tested; will appear in next maintenance release.
>>
>> Michael Kay
>> Saxonica
>>
>>
>> On 7 Dec 2015, at 12:14, Florent Georges <[hidden email]> wrote:
>>
>> Hi,
>>
>> I have a problem with an Initializer setting a ModuleURIResolver on
>> the Configuration object.  It seems the resolver is never called.  To
>> reproduce, here is TestInitializer.java:
>>
>>    import net.sf.saxon.Configuration;
>>    import net.sf.saxon.lib.Initializer;
>>    import javax.xml.transform.stream.StreamSource;
>>    import net.sf.saxon.lib.ModuleURIResolver;
>>
>>    public class TestInitializer
>>   implements Initializer
>>    {
>> @Override
>> public void initialize(Configuration config)
>> {
>>   System.err.println("Initialize...");
>>   config.setModuleURIResolver(new Resolver());
>> }
>>
>> private static final class Resolver
>> implements ModuleURIResolver
>> {
>>   @Override
>>   public StreamSource[] resolve(String ns, String base, String[] locs)
>>   {
>> System.err.println("Resolve: " + ns + ", " + base);
>> return null;
>>   }
>> }
>>    }
>>
>> If you compile it with (from within the same dir where the Java file
>> is, adapt the path to the Saxon JAR on your machine):
>>
>>    javac -cp .:/path/to/saxon9he.jar TestInitializer.java
>>
>> Given the following query file in the same dir (named query.xq):
>>
>>    import module namespace h = "http://example.org/ns/hello";
>>    h:new-hello('world')
>>
>> Execute Saxon with (adapt the path to the Saxon JAR):
>>
>>    java -cp .:/path/to/saxon9he.jar net.sf.saxon.Query \
>>        -init:TestInitializer query.xq
>>
>> The output is:
>>
>>    Initialize...
>>    Error on line 2 column 1 of query.xq:
>>      XQST0059 XQuery static error near #...tp://example.org/ns/hello"; <#:
>>        Cannot locate module for namespace http://example.org/ns/hello
>>    Static error(s) in query
>>
>> That is, the initializer is called, setting the ModuleURIResolver on
>> the configuration object it receives, but the import statement fails
>> without the resolver being called.
>>
>> I use Saxon 9.6.0.7 (I can't use 9.7 already, waiting for some other
>> components to be adapted to Saxon 9.7 first).  But I tested this
>> example with 9.7.0.1 and it gives the same result.
>>
>> Did I miss anything?  Is there anything specific to do in order to set
>> a module URI resolver from within an initializer?
>>
>> Regards,
>>
>> --
>> Florent Georges
>> http://fgeorges.org/
>> http://h2oconsulting.be/
>>
>>
>> ------------------------------------------------------------------------------
>> Go from Idea to Many App Stores Faster with Intel(R) XDK
>> Give your users amazing mobile app experiences with Intel(R) XDK.
>> Use one codebase in this all-in-one HTML5 development environment.
>> Design, debug & build mobile apps & 2D/3D high-impact games for multiple
>> OSs.
>> http://pubads.g.doubleclick.net/gampad/clk?id=254741911&iu=/4140_______________________________________________
>> saxon-help mailing list archived at http://saxon.markmail.org/
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/saxon-help
>>
>>
>>
>> ------------------------------------------------------------------------------
>> Go from Idea to Many App Stores Faster with Intel(R) XDK
>> Give your users amazing mobile app experiences with Intel(R) XDK.
>> Use one codebase in this all-in-one HTML5 development environment.
>> Design, debug & build mobile apps & 2D/3D high-impact games for multiple
>> OSs.
>> http://pubads.g.doubleclick.net/gampad/clk?id=254741911&iu=/4140
>> _______________________________________________
>> saxon-help mailing list archived at http://saxon.markmail.org/
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/saxon-help
>
> ------------------------------------------------------------------------------
> Go from Idea to Many App Stores Faster with Intel(R) XDK
> Give your users amazing mobile app experiences with Intel(R) XDK.
> Use one codebase in this all-in-one HTML5 development environment.
> Design, debug & build mobile apps & 2D/3D high-impact games for multiple OSs.
> http://pubads.g.doubleclick.net/gampad/clk?id=254741911&iu=/4140
> _______________________________________________
> saxon-help mailing list archived at http://saxon.markmail.org/
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/saxon-help 



------------------------------------------------------------------------------
Go from Idea to Many App Stores Faster with Intel(R) XDK
Give your users amazing mobile app experiences with Intel(R) XDK.
Use one codebase in this all-in-one HTML5 development environment.
Design, debug & build mobile apps & 2D/3D high-impact games for multiple OSs.
http://pubads.g.doubleclick.net/gampad/clk?id=254741911&iu=/4140
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help