/** * Declare a named collation. Collations are only available in a query if this method * has been called externally to declare the collation and associate it with an * implementation, in the form of a Java StringCollator. The default collation is the * Unicode codepoint collation, unless otherwise specified. * * @param name The name of the collation (technically, a URI) * @param collation The Java Comparator used to implement the collating sequence * @since 8.9. * @deprecated since 9.6. All collations are now registered at the level of the * Configuration. If this method is called, the effect is that the supplied collation * is registered with the configuration */ public void declareCollation(String name, StringCollator collation) { getConfiguration().registerCollation(name, collation); }
/** * Declare a named collation. Collations are only available in a query if this method * has been called externally to declare the collation and associate it with an * implementation, in the form of a Java StringCollator. The default collation is the * Unicode codepoint collation, unless otherwise specified. * * @param name The name of the collation (technically, a URI) * @param collation The Java Comparator used to implement the collating sequence * @since 8.9. * @deprecated since 9.6. All collations are now registered at the level of the * Configuration. If this method is called, the effect is that the supplied collation * is registered with the configuration */ public void declareCollation(String name, StringCollator collation) { getConfiguration().registerCollation(name, collation); }
/** * Set the default collation. * * @param name The collation name, as specified in the query prolog. Must be the name * of a known registered collation. * @throws NullPointerException if the supplied value is null * @throws IllegalStateException if the supplied value is not a known collation URI registered with the * configuration. * @since 8.4. Changed in 9.7.0.15 so that it validates the collation name: see bug 3121. */ public void declareDefaultCollation(String name) { if (name == null) { throw new NullPointerException(); } StringCollator c; try { c = getConfiguration().getCollation(name); } catch (XPathException e) { c = null; } if (c == null) { throw new IllegalStateException("Unknown collation " + name); } this.defaultCollationName = name; }
/** * Set the default collation. * * @param name The collation name, as specified in the query prolog. Must be the name * of a known registered collation. * @throws NullPointerException if the supplied value is null * @throws IllegalStateException if the supplied value is not a known collation URI registered with the * configuration. * @since 8.4. Changed in 9.7.0.15 so that it validates the collation name: see bug 3121. */ public void declareDefaultCollation(String name) { if (name == null) { throw new NullPointerException(); } StringCollator c; try { c = getConfiguration().getCollation(name); } catch (XPathException e) { c = null; } if (c == null) { throw new IllegalStateException("Unknown collation " + name); } this.defaultCollationName = name; }
/** * Say whether the query is allowed to be updating. XQuery update syntax will be rejected * during query compilation unless this flag is set. XQuery Update is supported only under Saxon-EE. * * @param updating true if the query is allowed to use the XQuery Update facility * (requires Saxon-EE). If set to false, the query must not be an updating query. If set * to true, it may be either an updating or a non-updating query. * @throws UnsupportedOperationException if updating is requested and the Saxon Configuration does * not support updating, either because it is not an EnterpriseConfiguration, or because no license * key is available. * @since 9.1 */ public void setUpdatingEnabled(boolean updating) { if (updating && !env.getConfiguration().isLicensedFeature(Configuration.LicenseFeature.ENTERPRISE_XQUERY)) { throw new UnsupportedOperationException("XQuery Update is not supported in this Saxon Configuration"); } env.setUpdatingEnabled(updating); }
/** * Say whether the query is allowed to be updating. XQuery update syntax will be rejected * during query compilation unless this flag is set. XQuery Update is supported only under Saxon-EE. * * @param updating true if the query is allowed to use the XQuery Update facility * (requires Saxon-EE). If set to false, the query must not be an updating query. If set * to true, it may be either an updating or a non-updating query. * @throws UnsupportedOperationException if updating is requested and the Saxon Configuration does * not support updating, either because it is not an EnterpriseConfiguration, or because no license * key is available. * @since 9.1 */ public void setUpdatingEnabled(boolean updating) { if (updating && !env.getConfiguration().isLicensedFeature(Configuration.LicenseFeature.ENTERPRISE_XQUERY)) { throw new UnsupportedOperationException("XQuery Update is not supported in this Saxon Configuration"); } env.setUpdatingEnabled(updating); }
/** * Declare a named collation. Collations are only available in a query if this method * has been called externally to declare the collation and associate it with an * implementation, in the form of a Java Comparator. The default collation is the * Unicode codepoint collation, unless otherwise specified. * * @param name The name of the collation (technically, a URI) * @param comparator The Java Comparator used to implement the collating sequence * @since 8.4. * @deprecated since 9.6. All collations are now registered at the level of the * Configuration. If this method is called, the effect is that the supplied collation * is registered with the configuration */ public void declareCollation(String name, Comparator comparator) { getConfiguration().registerCollation(name, new SimpleCollation(name, comparator)); }
/** * Declare a named collation. Collations are only available in a query if this method * has been called externally to declare the collation and associate it with an * implementation, in the form of a Java Comparator. The default collation is the * Unicode codepoint collation, unless otherwise specified. * * @param name The name of the collation (technically, a URI) * @param comparator The Java Comparator used to implement the collating sequence * @since 8.4. * @deprecated since 9.6. All collations are now registered at the level of the * Configuration. If this method is called, the effect is that the supplied collation * is registered with the configuration */ public void declareCollation(String name, Comparator comparator) { getConfiguration().registerCollation(name, new SimpleCollation(name, comparator)); }
/** * Create a QueryModule for a main module, copying the data that has been set up in a * StaticQueryContext object * @param sqc the StaticQueryContext object from which this module is initialized */ public QueryModule(StaticQueryContext sqc) throws XPathException { config = sqc.getConfiguration(); isMainModule = true; topModule = this; activeNamespaces = new Stack(); baseURI = sqc.getBaseURI(); try { locationURI = (baseURI == null ? null : new URI(baseURI)); } catch (URISyntaxException err) { throw new XPathException("Invalid location URI: " + baseURI); } executable = null; importers = null; init(sqc); resetFunctionLibraries(); }
/** * Get a named collation. * * @param name the name of the collation, as an absolute URI * @return the collation identified by the given name, as set previously using declareCollation. * If no collation with this name has been declared, the method calls the CollationURIResolver * to locate a collation with this name. * Return null if no collation with this name is found. * @throws NullPointerException if the collation name argument is null. * @since 8.4 * @deprecated since 9.6. Collations are now all held globally at the level of the * Configuration. Calling this method will get the relevant collation held in the Configuration. */ public StringCollator getCollation(String name) { try { return getConfiguration().getCollation(name); } catch (XPathException e) { getErrorListener().warning(e); return null; } }
/** * Create a QueryModule for a main module, copying the data that has been set up in a * StaticQueryContext object * @param sqc the StaticQueryContext object from which this module is initialized */ public QueryModule(StaticQueryContext sqc) throws XPathException { config = sqc.getConfiguration(); isMainModule = true; topModule = this; activeNamespaces = new Stack(); baseURI = sqc.getBaseURI(); try { locationURI = (baseURI == null ? null : new URI(baseURI)); } catch (URISyntaxException err) { throw new XPathException("Invalid location URI: " + baseURI); } executable = null; importers = null; init(sqc); resetFunctionLibraries(); for (Iterator vars = sqc.iterateDeclaredGlobalVariables(); vars.hasNext(); ) { GlobalVariableDefinition var = (GlobalVariableDefinition)vars.next(); declareVariable(var); } }
/** * Get a named collation. * * @param name the name of the collation, as an absolute URI * @return the collation identified by the given name, as set previously using declareCollation. * If no collation with this name has been declared, the method calls the CollationURIResolver * to locate a collation with this name. * Return null if no collation with this name is found. * @throws NullPointerException if the collation name argument is null. * @since 8.4 * @deprecated since 9.6. Collations are now all held globally at the level of the * Configuration. Calling this method will get the relevant collation held in the Configuration. */ public StringCollator getCollation(String name) { try { return getConfiguration().getCollation(name); } catch (XPathException e) { getErrorListener().warning(e); return null; } }
if (!type.matches(val, getConfiguration())) { throw new XPathException("Value of declared variable does not match its type");
throw new NullPointerException("No initial value for declared variable"); if (value != null && !type.matches(value, getConfiguration().getTypeHierarchy())) { throw new XPathException("Value of declared variable does not match its type");
throw new NullPointerException("No initial value for declared variable"); if (value != null && !type.matches(value, getConfiguration().getTypeHierarchy())) { throw new XPathException("Value of declared variable does not match its type");
/** * Reset the state of this StaticQueryContext to an uninitialized state * * @since 8.4 */ public void reset() { userDeclaredNamespaces = new HashMap<>(10); externalNamespaceResolver = null; errorListener = config.getErrorListener(); if (errorListener instanceof StandardErrorListener) { errorListener = ((StandardErrorListener) errorListener).makeAnother(Configuration.XQUERY); ((StandardErrorListener) errorListener).setRecoveryPolicy(Configuration.DO_NOT_RECOVER); } constructionMode = getConfiguration().isLicensedFeature(Configuration.LicenseFeature.ENTERPRISE_XQUERY) ? Validation.PRESERVE : Validation.STRIP; preserveSpace = false; defaultEmptyLeast = true; requiredContextItemType = AnyItemType.getInstance(); defaultFunctionNamespace = NamespaceConstant.FN; defaultElementNamespace = NamespaceConstant.NULL; moduleURIResolver = null; defaultCollationName = config.getDefaultCollationName(); clearNamespaces(); isUpdating = false; optimizerOptions = config.getOptimizerOptions(); }
/** * Reset the state of this StaticQueryContext to an uninitialized state * * @since 8.4 */ public void reset() { userDeclaredNamespaces = new HashMap<>(10); externalNamespaceResolver = null; errorListener = config.getErrorListener(); if (errorListener instanceof StandardErrorListener) { errorListener = ((StandardErrorListener) errorListener).makeAnother(Configuration.XQUERY); ((StandardErrorListener) errorListener).setRecoveryPolicy(Configuration.DO_NOT_RECOVER); } constructionMode = getConfiguration().isLicensedFeature(Configuration.LicenseFeature.ENTERPRISE_XQUERY) ? Validation.PRESERVE : Validation.STRIP; preserveSpace = false; defaultEmptyLeast = true; requiredContextItemType = AnyItemType.getInstance(); defaultFunctionNamespace = NamespaceConstant.FN; defaultElementNamespace = NamespaceConstant.NULL; moduleURIResolver = null; defaultCollationName = config.getDefaultCollationName(); clearNamespaces(); isUpdating = false; optimizerOptions = config.getOptimizerOptions(); }
/** * Reset the state of this StaticQueryContext to an uninitialized state * * @since 8.4 */ public void reset() { userDeclaredNamespaces = new HashMap(10); externalNamespaceResolver = null; collations = new CollationMap(config); errorListener = config.getErrorListener(); if (errorListener instanceof StandardErrorListener) { errorListener = ((StandardErrorListener)errorListener).makeAnother(Configuration.XQUERY); ((StandardErrorListener)errorListener).setRecoveryPolicy(Configuration.DO_NOT_RECOVER); } constructionMode = getConfiguration().isSchemaAware(Configuration.XQUERY) ? Validation.PRESERVE : Validation.STRIP; preserveSpace = false; defaultEmptyLeast = true; requiredContextItemType = AnyItemType.getInstance(); defaultFunctionNamespace = NamespaceConstant.FN; defaultElementNamespace = NamespaceConstant.NULL; moduleURIResolver = config.getModuleURIResolver(); collations.setDefaultCollationName(NamespaceConstant.CODEPOINT_COLLATION_URI); clearNamespaces(); generateCode = false; }
/** * Reset the state of this StaticQueryContext to an uninitialized state * * @since 8.4 */ public void reset() { userDeclaredNamespaces = new HashMap(10); externalNamespaceResolver = null; collations = new CollationMap(config); errorListener = config.getErrorListener(); if (errorListener instanceof StandardErrorListener) { errorListener = ((StandardErrorListener)errorListener).makeAnother(Configuration.XQUERY); ((StandardErrorListener)errorListener).setRecoveryPolicy(Configuration.DO_NOT_RECOVER); } constructionMode = getConfiguration().isSchemaAware(Configuration.XQUERY) ? Validation.PRESERVE : Validation.STRIP; preserveSpace = false; defaultEmptyLeast = true; requiredContextItemType = AnyItemType.getInstance(); defaultFunctionNamespace = NamespaceConstant.FN; defaultElementNamespace = NamespaceConstant.NULL; moduleURIResolver = config.getModuleURIResolver(); collations.setDefaultCollationName(NamespaceConstant.CODEPOINT_COLLATION_URI); clearNamespaces(); generateCode = false; }
/** * Prepare an XQuery query for subsequent evaluation. The source text of the query * is supplied as a String. The base URI of the query is taken from the static context, * and defaults to the current working directory. * * <p>Note that this interface makes the caller responsible for decoding the query and * presenting it as a string of characters. This means it is likely that any encoding * specified in the query prolog will be ignored.</p> * * @param query The XQuery query to be evaluated, supplied as a string. * @return an XQueryExpression object representing the prepared expression * @throws net.sf.saxon.trans.XPathException * if the syntax of the expression is wrong, * or if it references namespaces, variables, or functions that have not been declared, * or contains other static errors. * @since 8.4 */ public XQueryExpression compileQuery(String query) throws XPathException { QueryParser qp = getConfiguration().newQueryParser(isUpdating); qp.setCompileWithTracing(isCompileWithTracing() || config.isCompileWithTracing()); QueryModule mainModule = new QueryModule(this); mainModule.setExecutable(executable); return qp.makeXQueryExpression(query, mainModule, config); }