Project

Profile

Help

Revision 5ec44c49

Added by Michael Kay about 12 years ago

Fix bug 2864240 ModuleURIResolver handling main module

View differences:

latest9.1/bj/net/sf/saxon/Query.java
755 755
            exp = staticEnv.compileQuery(q);
756 756
        } else if (useURLs || queryFileName.startsWith("http:") || queryFileName.startsWith("file:")) {
757 757
            ModuleURIResolver resolver = staticEnv.getModuleURIResolver();
758
            boolean isStandardResolver = false;
758 759
            if (resolver == null) {
759 760
                resolver = staticEnv.getConfiguration().getStandardModuleURIResolver();
761
                isStandardResolver = true;
760 762
            }
761
            String[] locations = {queryFileName};
762
            Source[] sources = resolver.resolve(null, null, locations);
763
            if (sources.length != 1 || !(sources[0] instanceof StreamSource)) {
764
                quit("Module URI Resolver must return a single StreamSource", 2);
763
            while (true) {
764
                String[] locations = {queryFileName};
765
                Source[] sources;
766
                try {
767
                    sources = resolver.resolve(null, null, locations);
768
                } catch (Exception e) {
769
                    if (e instanceof XPathException) {
770
                        throw (XPathException)e;
771
                    } else {
772
                        XPathException err = new XPathException("Exception in ModuleURIResolver: ", e);
773
                        err.setErrorCode("XQST0059");
774
                        throw err;
775
                    }
776
                }
777
                if (sources == null) {
778
                    if (isStandardResolver) {
779
                        // this should not happen
780
                        quit("System problem: standard ModuleURIResolver returned null", 4);
781
                    } else {
782
                        resolver = staticEnv.getConfiguration().getStandardModuleURIResolver();
783
                        isStandardResolver = true;
784
                    }
785
                } else {
786
                    if (sources.length != 1 || !(sources[0] instanceof StreamSource)) {
787
                        quit("Module URI Resolver must return a single StreamSource", 2);
788
                    }
789
                    String queryText = QueryReader.readSourceQuery((StreamSource)sources[0], config.getNameChecker());
790
                    exp = staticEnv.compileQuery(queryText);
791
                    break;
792
                }
765 793
            }
766
            String queryText = QueryReader.readSourceQuery((StreamSource)sources[0], config.getNameChecker());
767
            exp = staticEnv.compileQuery(queryText);
768 794
        } else {
769 795
            InputStream queryStream = new FileInputStream(queryFileName);
770 796
            staticEnv.setBaseURI(new File(queryFileName).toURI().toString());
latest9.2/hej/net/sf/saxon/Query.java
845 845
            exp = staticEnv.compileQuery(q);
846 846
        } else if (useURLs || queryFileName.startsWith("http:") || queryFileName.startsWith("file:")) {
847 847
            ModuleURIResolver resolver = staticEnv.getModuleURIResolver();
848
            boolean isStandardResolver = false;
848 849
            if (resolver == null) {
849 850
                resolver = staticEnv.getConfiguration().getStandardModuleURIResolver();
851
                isStandardResolver = true;
850 852
            }
851
            String[] locations = {queryFileName};
852
            Source[] sources;
853
            try {
854
                sources = resolver.resolve(null, null, locations);
855
            } catch (Exception e) {
856
                if (e instanceof XPathException) {
857
                    throw (XPathException)e;
853
            while (true) {
854
                String[] locations = {queryFileName};
855
                Source[] sources;
856
                try {
857
                    sources = resolver.resolve(null, null, locations);
858
                } catch (Exception e) {
859
                    if (e instanceof XPathException) {
860
                        throw (XPathException)e;
861
                    } else {
862
                        XPathException err = new XPathException("Exception in ModuleURIResolver: ", e);
863
                        err.setErrorCode("XQST0059");
864
                        throw err;
865
                    }
866
                }
867
                if (sources == null) {
868
                    if (isStandardResolver) {
869
                        // this should not happen
870
                        quit("System problem: standard ModuleURIResolver returned null", 4);
871
                    } else {
872
                        resolver = staticEnv.getConfiguration().getStandardModuleURIResolver();
873
                        isStandardResolver = true;
874
                    }
858 875
                } else {
859
                    XPathException err = new XPathException("Exception in ModuleURIResolver: ", e);
860
                    err.setErrorCode("XQST0059");
861
                    throw err;
876
                    if (sources.length != 1 || !(sources[0] instanceof StreamSource)) {
877
                        quit("Module URI Resolver must return a single StreamSource", 2);
878
                    }
879
                    String queryText = QueryReader.readSourceQuery((StreamSource)sources[0], config.getNameChecker());
880
                    exp = staticEnv.compileQuery(queryText);
881
                    break;
862 882
                }
863 883
            }
864
            if (sources.length != 1 || !(sources[0] instanceof StreamSource)) {
865
                quit("Module URI Resolver must return a single StreamSource", 2);
866
            }
867
            String queryText = QueryReader.readSourceQuery((StreamSource)sources[0], config.getNameChecker());
868
            exp = staticEnv.compileQuery(queryText);
869 884
        } else {
870 885
            InputStream queryStream = new FileInputStream(queryFileName);
871 886
            staticEnv.setBaseURI(new File(queryFileName).toURI().toString());

Also available in: Unified diff