/** * Parse the version declaration if present. * * @throws XPathException in the event of a syntax error. */ private void parseVersionDeclaration() throws XPathException { if (t.currentToken == Token.XQUERY_VERSION) { nextToken(); expect(Token.STRING_LITERAL); if (!("1.0".equals(t.currentTokenValue))) { grumble("XQuery version must be 1.0", "XQST0031"); } nextToken(); if ("encoding".equals(t.currentTokenValue)) { nextToken(); expect(Token.STRING_LITERAL); if (!encNamePattern.matcher(t.currentTokenValue).matches()) { grumble("Encoding name contains invalid characters", "XQST0087"); } // we ignore the encoding now: it was handled earlier, while decoding the byte stream nextToken(); } expect(Token.SEMICOLON); nextToken(); } }
/** * Parse the version declaration if present. * * @throws XPathException in the event of a syntax error. */ private void parseVersionDeclaration() throws XPathException { if (t.currentToken == Token.XQUERY_VERSION) { nextToken(); expect(Token.STRING_LITERAL); if (!("1.0".equals(t.currentTokenValue))) { grumble("XQuery version must be 1.0", "XQST0031"); } nextToken(); if ("encoding".equals(t.currentTokenValue)) { nextToken(); expect(Token.STRING_LITERAL); if (!encNamePattern.matcher(t.currentTokenValue).matches()) { grumble("Encoding name contains invalid characters", "XQST0087"); } // we ignore the encoding now: it was handled earlier, while decoding the byte stream nextToken(); } expect(Token.SEMICOLON); nextToken(); } }
/** * Parse the "declare ordering" declaration. * Syntax: <"declare" "ordering"> ("ordered" | "unordered") * * @throws XPathException */ private void parseOrderingDeclaration() throws XPathException { if (foundOrderingDeclaration) { grumble("ordering mode declaration appears more than once", "XQST0065"); } foundOrderingDeclaration = true; nextToken(); expect(Token.NAME); if ("ordered".equals(t.currentTokenValue)) { // no action } else if ("unordered".equals(t.currentTokenValue)) { // no action } else { grumble("ordering mode must be 'ordered' or 'unordered'"); } nextToken(); }
/** * Parse the "declare ordering" declaration. * Syntax: <"declare" "ordering"> ("ordered" | "unordered") * * @throws XPathException */ private void parseOrderingDeclaration() throws XPathException { if (foundOrderingDeclaration) { grumble("ordering mode declaration appears more than once", "XQST0065"); } foundOrderingDeclaration = true; nextToken(); expect(Token.NAME); if ("ordered".equals(t.currentTokenValue)) { // no action } else if ("unordered".equals(t.currentTokenValue)) { // no action } else { grumble("ordering mode must be 'ordered' or 'unordered'"); } nextToken(); }
expect(Token.MODULE_NAMESPACE); nextToken(); expect(Token.NAME); String prefix = t.currentTokenValue; nextToken(); expect(Token.EQUALS); nextToken(); expect(Token.STRING_LITERAL); String uri = URILiteral(t.currentTokenValue); checkProhibitedPrefixes(prefix, uri); expect(Token.SEMICOLON); nextToken(); try {
/** * Parse the "default function namespace" declaration. * Syntax: <"declare" "default" "function" "namespace"> StringLiteral * * @throws XPathException to indicate a syntax error */ private void parseDefaultFunctionNamespace() throws XPathException { if (foundDefaultFunctionNamespace) { grumble("default function namespace appears more than once", "XQST0066"); } foundDefaultFunctionNamespace = true; nextToken(); expect(Token.NAME); if (!"namespace".equals(t.currentTokenValue)) { grumble("After 'declare default function', expected 'namespace'"); } nextToken(); expect(Token.STRING_LITERAL); String uri = URILiteral(t.currentTokenValue); ((QueryModule)env).setDefaultFunctionNamespace(uri); nextToken(); }
/** * Parse the "default element namespace" declaration. * Syntax: <"declare" "default" "element" "namespace"> StringLiteral * * @throws XPathException to indicate a syntax error */ private void parseDefaultElementNamespace() throws XPathException { if (foundDefaultElementNamespace) { grumble("default element namespace appears more than once", "XQST0066"); } foundDefaultElementNamespace = true; nextToken(); expect(Token.NAME); if (!"namespace".equals(t.currentTokenValue)) { grumble("After 'declare default element', expected 'namespace'"); } nextToken(); expect(Token.STRING_LITERAL); String uri = URILiteral(t.currentTokenValue); ((QueryModule)env).setDefaultElementNamespace(uri); nextToken(); }
/** * Parse the "default element namespace" declaration. * Syntax: <"declare" "default" "element" "namespace"> StringLiteral * * @throws XPathException to indicate a syntax error */ private void parseDefaultElementNamespace() throws XPathException { if (foundDefaultElementNamespace) { grumble("default element namespace appears more than once", "XQST0066"); } foundDefaultElementNamespace = true; nextToken(); expect(Token.NAME); if (!"namespace".equals(t.currentTokenValue)) { grumble("After 'declare default element', expected 'namespace'"); } nextToken(); expect(Token.STRING_LITERAL); String uri = URILiteral(t.currentTokenValue); ((QueryModule)env).setDefaultElementNamespace(uri); nextToken(); }
/** * Parse the "default function namespace" declaration. * Syntax: <"declare" "default" "function" "namespace"> StringLiteral * * @throws XPathException to indicate a syntax error */ private void parseDefaultFunctionNamespace() throws XPathException { if (foundDefaultFunctionNamespace) { grumble("default function namespace appears more than once", "XQST0066"); } foundDefaultFunctionNamespace = true; nextToken(); expect(Token.NAME); if (!"namespace".equals(t.currentTokenValue)) { grumble("After 'declare default function', expected 'namespace'"); } nextToken(); expect(Token.STRING_LITERAL); String uri = URILiteral(t.currentTokenValue); ((QueryModule)env).setDefaultFunctionNamespace(uri); nextToken(); }
/** * Parse the "declare construction" declaration. * Syntax: <"declare" "construction"> ("preserve" | "strip") * * @throws XPathException */ private void parseConstructionDeclaration() throws XPathException { if (foundConstructionDeclaration) { grumble("declare construction appears more than once", "XQST0067"); } foundConstructionDeclaration = true; nextToken(); expect(Token.NAME); int val; if ("preserve".equals(t.currentTokenValue)) { val = Validation.PRESERVE; } else if ("strip".equals(t.currentTokenValue)) { val = Validation.STRIP; } else { grumble("construction mode must be 'preserve' or 'strip'"); val = Validation.STRIP; } ((QueryModule)env).setConstructionMode(val); nextToken(); }
/** * Parse the Base URI declaration. * Syntax: <"declare" "base-uri"> uri-literal * * @throws XPathException */ private void parseBaseURIDeclaration() throws XPathException { if (foundBaseURIDeclaration) { grumble("Base URI Declaration may only appear once", "XQST0032"); } foundBaseURIDeclaration = true; nextToken(); expect(Token.STRING_LITERAL); String uri = URILiteral(t.currentTokenValue); try { // if the supplied URI is relative, try to resolve it URI baseURI = new URI(uri); if (!baseURI.isAbsolute()) { String oldBase = env.getBaseURI(); URI oldBaseURI = new URI(oldBase); uri = oldBaseURI.resolve(uri).toString(); } ((QueryModule)env).setBaseURI(uri); } catch (URISyntaxException err) { // The spec says this "is not intrinsically an error", but can cause a failure later ((QueryModule)env).setBaseURI(uri); } nextToken(); }
/** * Parse the "declare construction" declaration. * Syntax: <"declare" "construction"> ("preserve" | "strip") * * @throws XPathException */ private void parseConstructionDeclaration() throws XPathException { if (foundConstructionDeclaration) { grumble("declare construction appears more than once", "XQST0067"); } foundConstructionDeclaration = true; nextToken(); expect(Token.NAME); int val; if ("preserve".equals(t.currentTokenValue)) { val = Validation.PRESERVE; } else if ("strip".equals(t.currentTokenValue)) { val = Validation.STRIP; } else { grumble("construction mode must be 'preserve' or 'strip'"); val = Validation.STRIP; } ((QueryModule)env).setConstructionMode(val); nextToken(); }
/** * Parse the "declare xmlspace" declaration. * Syntax: <"declare" "boundary-space"> ("preserve" | "strip") * * @throws XPathException */ private void parseBoundarySpaceDeclaration() throws XPathException { if (foundBoundarySpaceDeclaration) { grumble("'declare boundary-space' appears more than once", "XQST0068"); } foundBoundarySpaceDeclaration = true; nextToken(); expect(Token.NAME); if ("preserve".equals(t.currentTokenValue)) { ((QueryModule)env).setPreserveBoundarySpace(true); } else if ("strip".equals(t.currentTokenValue)) { ((QueryModule)env).setPreserveBoundarySpace(false); } else { grumble("boundary-space must be 'preserve' or 'strip'"); } nextToken(); }
/** * Parse the "declare xmlspace" declaration. * Syntax: <"declare" "boundary-space"> ("preserve" | "strip") * * @throws XPathException */ private void parseBoundarySpaceDeclaration() throws XPathException { if (foundBoundarySpaceDeclaration) { grumble("'declare boundary-space' appears more than once", "XQST0068"); } foundBoundarySpaceDeclaration = true; nextToken(); expect(Token.NAME); if ("preserve".equals(t.currentTokenValue)) { ((QueryModule)env).setPreserveBoundarySpace(true); } else if ("strip".equals(t.currentTokenValue)) { ((QueryModule)env).setPreserveBoundarySpace(false); } else { grumble("boundary-space must be 'preserve' or 'strip'"); } nextToken(); }
private void parseDefaultCollation() throws XPathException { // <"default" "collation"> StringLiteral if (foundDefaultCollation) { grumble("default collation appears more than once", "XQST0038"); } foundDefaultCollation = true; nextToken(); expect(Token.STRING_LITERAL); String uri = URILiteral(t.currentTokenValue); ((QueryModule)env).setDefaultCollationName(uri); nextToken(); }
private void parseDefaultCollation() throws XPathException { // <"default" "collation"> StringLiteral if (foundDefaultCollation) { grumble("default collation appears more than once", "XQST0038"); } foundDefaultCollation = true; nextToken(); expect(Token.STRING_LITERAL); String uri = URILiteral(t.currentTokenValue); ((QueryModule)env).setDefaultCollationName(uri); nextToken(); }
/** * Parse a namespace declaration in the Prolog. * Syntax: <"declare" "namespace"> NCName "=" StringLiteral * * @throws XPathException */ private void parseNamespaceDeclaration() throws XPathException { nextToken(); expect(Token.NAME); String prefix = t.currentTokenValue; if (!nameChecker.isValidNCName(prefix)) { grumble("Invalid namespace prefix " + Err.wrap(prefix)); } nextToken(); expect(Token.EQUALS); nextToken(); expect(Token.STRING_LITERAL); String uri = URILiteral(t.currentTokenValue); checkProhibitedPrefixes(prefix, uri); try { ((QueryModule)env).declarePrologNamespace(prefix, uri); } catch (XPathException err) { err.setLocator(makeLocator()); reportError(err); } nextToken(); }
/** * Parse a namespace declaration in the Prolog. * Syntax: <"declare" "namespace"> NCName "=" StringLiteral * * @throws XPathException */ private void parseNamespaceDeclaration() throws XPathException { nextToken(); expect(Token.NAME); String prefix = t.currentTokenValue; if (!nameChecker.isValidNCName(prefix)) { grumble("Invalid namespace prefix " + Err.wrap(prefix)); } nextToken(); expect(Token.EQUALS); nextToken(); expect(Token.STRING_LITERAL); String uri = URILiteral(t.currentTokenValue); checkProhibitedPrefixes(prefix, uri); try { ((QueryModule)env).declarePrologNamespace(prefix, uri); } catch (XPathException err) { err.setLocator(makeLocator()); reportError(err); } nextToken(); }
private Expression parseTypeswitchReturnClause(StructuredQName varQName, LetExpression outerLet) throws XPathException { Expression action; t.treatCurrentAsOperator(); expect(Token.RETURN); nextToken(); LetExpression innerLet = makeLetExpression(); innerLet.setRequiredType(SequenceType.ANY_SEQUENCE); innerLet.setVariableQName(varQName); innerLet.setSequence(new LocalVariableReference(outerLet)); declareRangeVariable(innerLet); action = parseExprSingle(); undeclareRangeVariable(); innerLet.setAction(action); action = innerLet; return action; }
private Expression parseTypeswitchReturnClause(StructuredQName varQName, LetExpression outerLet) throws XPathException { Expression action; t.treatCurrentAsOperator(); expect(Token.RETURN); nextToken(); LetExpression innerLet = makeLetExpression(); innerLet.setRequiredType(SequenceType.ANY_SEQUENCE); innerLet.setVariableQName(varQName); innerLet.setSequence(new LocalVariableReference(outerLet)); declareRangeVariable(innerLet); action = parseExprSingle(); undeclareRangeVariable(); innerLet.setAction(action); return innerLet; // if (Literal.isEmptySequence(action)) { // // The purpose of simplifying this now is that () is allowed in a branch even in XQuery Update when // // other branches of the typeswitch are updating. // return action; // } else { // return innerLet; // } }