/** * Set the static base URI for the query * * @param baseURI the static base URI; or null to indicate that no base URI is available */ public void setBaseURI(URI baseURI) { if (baseURI == null) { env.setBaseURI(null); } else { if (!baseURI.isAbsolute()) { throw new IllegalArgumentException("Base URI must be an absolute URI: " + baseURI); } env.setBaseURI(baseURI.toString()); } }
/** * Set the static base URI for the query * @param baseURI the static base URI */ public void setBaseURI(URI baseURI) { if (!baseURI.isAbsolute()) { throw new IllegalArgumentException("Base URI must be an absolute URI"); } env.setBaseURI(baseURI.toString()); }
/** * Set the static base URI for the query * * @param baseURI the static base URI; or null to indicate that no base URI is available */ public void setBaseURI(URI baseURI) { if (baseURI == null) { env.setBaseURI(null); } else { if (!baseURI.isAbsolute()) { throw new IllegalArgumentException("Base URI must be an absolute URI: " + baseURI); } env.setBaseURI(baseURI.toString()); } }
/** * Compile a library module supplied as a file. The code generated by compiling the library is available * for importing by all subsequent compilations using the same XQueryCompiler; it is identified by an * "import module" declaration that specifies the module URI of the library module. No module location * hint is required, and if one is present, it is ignored. * <p>The encoding of the input stream may be specified using {@link #setEncoding(String)}; * if this has not been set, the compiler determines the encoding from the version header of the * query, and if that too is absent, it assumes UTF-8.</p> * <p>Separate compilation of library modules is supported only under Saxon-EE</p> * * @param query the file containing the query. The URI corresponding to this file will be used as the * base URI of the query, overriding any URI supplied using {@link #setBaseURI(java.net.URI)} (but not * overriding any base URI specified within the query prolog) * @throws SaxonApiException if the query compilation fails with a static error * @throws IOException if the file does not exist or cannot be read * @since 9.2 */ public void compileLibrary(File query) throws SaxonApiException, IOException { try (FileInputStream stream = new FileInputStream(query)) { String savedBaseUri = env.getBaseURI(); env.setBaseURI(query.toURI().toString()); env.compileLibrary(stream, encoding); env.setBaseURI(savedBaseUri); } catch (XPathException e) { throw new SaxonApiException(e); } }
/** * Compile a library module supplied as a file. The code generated by compiling the library is available * for importing by all subsequent compilations using the same XQueryCompiler; it is identified by an * "import module" declaration that specifies the module URI of the library module. No module location * hint is required, and if one is present, it is ignored. * <p>The encoding of the input stream may be specified using {@link #setEncoding(String)}; * if this has not been set, the compiler determines the encoding from the version header of the * query, and if that too is absent, it assumes UTF-8.</p> * <p>Separate compilation of library modules is supported only under Saxon-EE</p> * * @param query the file containing the query. The URI corresponding to this file will be used as the * base URI of the query, overriding any URI supplied using {@link #setBaseURI(java.net.URI)} (but not * overriding any base URI specified within the query prolog) * @throws SaxonApiException if the query compilation fails with a static error * @throws IOException if the file does not exist or cannot be read * @since 9.2 */ public void compileLibrary(File query) throws SaxonApiException, IOException { try (FileInputStream stream = new FileInputStream(query)) { String savedBaseUri = env.getBaseURI(); env.setBaseURI(query.toURI().toString()); env.compileLibrary(stream, encoding); env.setBaseURI(savedBaseUri); } catch (XPathException e) { throw new SaxonApiException(e); } }
/** * Compile a query supplied as a file * * @param query the file containing the query. The URI corresponding to this file will be used as the * base URI of the query, overriding any URI supplied using {@link #setBaseURI(java.net.URI)} (but not * overriding any base URI specified within the query prolog) * @return an XQueryExecutable representing the compiled query * @throws SaxonApiException if the query compilation fails with a static error * @throws IOException if the file does not exist or cannot be read * @since 9.1 */ public XQueryExecutable compile(File query) throws SaxonApiException, IOException { try (FileInputStream stream = new FileInputStream(query)) { String savedBaseUri = env.getBaseURI(); env.setBaseURI(query.toURI().toString()); XQueryExecutable exec = new XQueryExecutable(processor, env.compileQuery(stream, encoding)); env.setBaseURI(savedBaseUri); return exec; } catch (XPathException e) { throw new SaxonApiException(e); } }
/** * Compile a query supplied as a file * * @param query the file containing the query. The URI corresponding to this file will be used as the * base URI of the query, overriding any URI supplied using {@link #setBaseURI(java.net.URI)} (but not * overriding any base URI specified within the query prolog) * @return an XQueryExecutable representing the compiled query * @throws SaxonApiException if the query compilation fails with a static error * @throws IOException if the file does not exist or cannot be read * @since 9.1 */ public XQueryExecutable compile(File query) throws SaxonApiException, IOException { try (FileInputStream stream = new FileInputStream(query)) { String savedBaseUri = env.getBaseURI(); env.setBaseURI(query.toURI().toString()); XQueryExecutable exec = new XQueryExecutable(processor, env.compileQuery(stream, encoding)); env.setBaseURI(savedBaseUri); return exec; } catch (XPathException e) { throw new SaxonApiException(e); } }
} else { InputStream queryStream = new FileInputStream(queryFileName); staticEnv.setBaseURI(new File(queryFileName).toURI().toString()); exp = staticEnv.compileQuery(queryStream, null);
/** * Main method for testing * @param args Takes one argument, the XPath expression to be analyzed * @throws Exception */ public static void main(String[] args) throws Exception { Configuration config = new Configuration(); Expression exp; if (args[0].equals("xpath")) { XPathEvaluator xpath = new XPathEvaluator(config); XPathExpression xpexp = xpath.createExpression(args[1]); exp = xpexp.getInternalExpression(); } else if (args[0].equals("xquery")) { StaticQueryContext sqc = new StaticQueryContext(config); sqc.setBaseURI(new File(args[1]).toURI().toString()); XQueryExpression xqe = sqc.compileQuery(new FileReader(args[1])); exp = xqe.getExpression(); } else { throw new IllegalArgumentException("first argument must be xpath or xquery"); } exp.explain(System.err); PathMap initialPath = new PathMap(exp); initialPath.diagnosticDump(System.err); PathMapRoot[] roots = initialPath.getPathMapRoots(); for (int i=0; i<roots.length; i++) { initialPath.reduceToDownwardsAxes(roots[i]); } System.err.println("AFTER REDUCTION:"); initialPath.diagnosticDump(System.err); }
String value = props.getProperty(pn_xqj_baseURI); if (value != null && !value.isEmpty()) { sqc.setBaseURI(value);
/** * Main method for testing * @param args Takes one argument, the XPath expression to be analyzed * @throws Exception */ public static void main(String[] args) throws Exception { Configuration config = new Configuration(); Expression exp; if (args[0].equals("xpath")) { XPathEvaluator xpath = new XPathEvaluator(config); XPathExpression xpexp = xpath.createExpression(args[1]); exp = xpexp.getInternalExpression(); } else if (args[0].equals("xquery")) { StaticQueryContext sqc = new StaticQueryContext(config); sqc.setBaseURI(new File(args[1]).toURI().toString()); XQueryExpression xqe = sqc.compileQuery(new FileReader(args[1])); exp = xqe.getExpression(); } else { throw new IllegalArgumentException("first argument must be xpath or xquery"); } exp.explain(System.err); PathMap initialPath = new PathMap(exp); initialPath.diagnosticDump(System.err); PathMapRoot[] roots = initialPath.getPathMapRoots(); for (int i=0; i<roots.length; i++) { initialPath.reduceToDownwardsAxes(roots[i]); } System.err.println("AFTER REDUCTION:"); initialPath.diagnosticDump(System.err); }
staticEnv.setBaseURI(new File(queryFileName).toURI().toString()); exp = staticEnv.compileQuery(queryStream, null);
/** * Load a query library module * @return the QueryModule object representing the loaded library module */ private QueryModule loadModule() throws XPathException { // Create a dummy main query module and compile it StaticQueryContext sqc = new StaticQueryContext(getConfiguration()); sqc.setExecutable(getExecutable()); sqc.setBaseURI(getBaseURI()); String mainModule = "import module namespace m = \"" + moduleURI + "\" at \"" + href + "\"; ()"; XQueryExpression exp = sqc.compileQuery(mainModule); return exp.getStaticContext(); }
staticEnv.setRequiredContextItemType(t); staticEnv.setBaseURI(baseResourceURI.toString());
/** * Load a query library module * @return the QueryModule object representing the loaded library module */ private QueryModule loadModule() throws XPathException { // Create a dummy main query module and compile it StaticQueryContext sqc = new StaticQueryContext(getConfiguration()); sqc.setExecutable(getExecutable()); sqc.setBaseURI(getBaseURI()); String mainModule = "import module namespace m = \"" + moduleURI + "\" at \"" + href + "\"; ()"; XQueryExpression exp = sqc.compileQuery(mainModule); return exp.getStaticContext(); }
final StaticQueryContext aStaticQueryCtx = aConfiguration.newStaticQueryContext (); aStaticQueryCtx.setBaseURI (m_sBaseURL);
final StaticQueryContext aStaticQueryCtx = aConfiguration.newStaticQueryContext (); aStaticQueryCtx.setBaseURI (m_sBaseURL);
protected void setStaticContext(StaticQueryContext sqc, XQStaticContext ctx) throws XQException { sqc.setBaseURI(ctx.getBaseURI());