Search in sources :

Example 11 with QName

use of org.eclipse.wst.xml.xpath2.processor.internal.types.QName in project webtools.sourceediting by eclipse.

the class FnPrefixFromQName method prefix.

/**
 * Prefix-from-QName operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:prefix-from-QName operation.
 */
public static ResultSequence prefix(Collection args, StaticContext sc) throws DynamicError {
    Collection cargs = Function.convert_arguments(args, expected_args());
    // get arg
    ResultSequence arg1 = (ResultSequence) cargs.iterator().next();
    if (arg1.empty())
        return ResultBuffer.EMPTY;
    QName qname = (QName) arg1.first();
    String prefix = qname.prefix();
    if (prefix != null) {
        if (!XMLConstants.NULL_NS_URI.equals(sc.getNamespaceContext().getNamespaceURI(prefix))) {
            return new XSNCName(prefix);
        } else {
            throw DynamicError.invalidPrefix();
        }
    }
    return ResultBuffer.EMPTY;
}
Also used : XSNCName(org.eclipse.wst.xml.xpath2.processor.internal.types.XSNCName) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) QName(org.eclipse.wst.xml.xpath2.processor.internal.types.QName) Collection(java.util.Collection)

Example 12 with QName

use of org.eclipse.wst.xml.xpath2.processor.internal.types.QName in project webtools.sourceediting by eclipse.

the class FnPrefixFromQName method expected_args.

/**
 * Obtain a list of expected arguments.
 *
 * @return Result of operation.
 */
public static synchronized Collection expected_args() {
    if (_expected_args == null) {
        _expected_args = new ArrayList();
        SeqType arg = new SeqType(new QName(), SeqType.OCC_QMARK);
        _expected_args.add(arg);
    }
    return _expected_args;
}
Also used : SeqType(org.eclipse.wst.xml.xpath2.processor.internal.SeqType) QName(org.eclipse.wst.xml.xpath2.processor.internal.types.QName) ArrayList(java.util.ArrayList)

Example 13 with QName

use of org.eclipse.wst.xml.xpath2.processor.internal.types.QName in project webtools.sourceediting by eclipse.

the class QNameEQTest method test_op_qname_equal_4.

// Evaluates the "op:qname-equal" operator used with simple different qname values (different namespace URI values, same local part). Uses the ne operator.
public void test_op_qname_equal_4() throws Exception {
    String inputFile = "/TestSources/emptydoc.xml";
    String xqFile = "/Queries/XQuery/Expressions/Operators/CompExpr/ValComp/QNameOp/QNameEQ/op-qname-equal-4.xq";
    String resultFile = "/ExpectedTestResults/Expressions/Operators/CompExpr/ValComp/QNameOp/QNameEQ/op-qName-equal-4.txt";
    String expectedResult = getExpectedResult(resultFile);
    URL fileURL = bundle.getEntry(inputFile);
    loadDOMDocument(fileURL);
    // Get XML Schema Information for the Document
    XSModel schema = getGrammar();
    setupDynamicContext(schema);
    String xpath = extractXPathExpression(xqFile, inputFile);
    String actual = null;
    try {
        compileXPath(xpath);
        ResultSequence rs = evaluate(domDoc);
        actual = buildResultString(rs);
    } catch (XPathParserException ex) {
        actual = ex.code();
    } catch (StaticError ex) {
        actual = ex.code();
    } catch (DynamicError ex) {
        actual = ex.code();
    }
    assertEquals("XPath Result Error " + xqFile + ":", expectedResult, actual);
}
Also used : XPathParserException(org.eclipse.wst.xml.xpath2.processor.XPathParserException) ResultSequence(org.eclipse.wst.xml.xpath2.processor.ResultSequence) XSModel(org.apache.xerces.xs.XSModel) StaticError(org.eclipse.wst.xml.xpath2.processor.StaticError) DynamicError(org.eclipse.wst.xml.xpath2.processor.DynamicError) URL(java.net.URL)

Example 14 with QName

use of org.eclipse.wst.xml.xpath2.processor.internal.types.QName in project webtools.sourceediting by eclipse.

the class QNameEQTest method test_op_qname_equal_18.

// Evaluates the "op:qname-equal" operator used with second namespace URI set to empty string, same local part and no prefix. Uses the ne operator.
public void test_op_qname_equal_18() throws Exception {
    String inputFile = "/TestSources/emptydoc.xml";
    String xqFile = "/Queries/XQuery/Expressions/Operators/CompExpr/ValComp/QNameOp/QNameEQ/op-qname-equal-18.xq";
    String resultFile = "/ExpectedTestResults/Expressions/Operators/CompExpr/ValComp/QNameOp/QNameEQ/op-qname-equal-18.txt";
    String expectedResult = getExpectedResult(resultFile);
    URL fileURL = bundle.getEntry(inputFile);
    loadDOMDocument(fileURL);
    // Get XML Schema Information for the Document
    XSModel schema = getGrammar();
    setupDynamicContext(schema);
    String xpath = extractXPathExpression(xqFile, inputFile);
    String actual = null;
    try {
        compileXPath(xpath);
        ResultSequence rs = evaluate(domDoc);
        actual = buildResultString(rs);
    } catch (XPathParserException ex) {
        actual = ex.code();
    } catch (StaticError ex) {
        actual = ex.code();
    } catch (DynamicError ex) {
        actual = ex.code();
    }
    assertEquals("XPath Result Error " + xqFile + ":", expectedResult, actual);
}
Also used : XPathParserException(org.eclipse.wst.xml.xpath2.processor.XPathParserException) ResultSequence(org.eclipse.wst.xml.xpath2.processor.ResultSequence) XSModel(org.apache.xerces.xs.XSModel) StaticError(org.eclipse.wst.xml.xpath2.processor.StaticError) DynamicError(org.eclipse.wst.xml.xpath2.processor.DynamicError) URL(java.net.URL)

Example 15 with QName

use of org.eclipse.wst.xml.xpath2.processor.internal.types.QName in project webtools.sourceediting by eclipse.

the class QNameEQTest method test_op_qname_equal_21.

// Evaluates the "op:qname-equal" operator used as an argument to the fn:not function. Uses the eq operator.
public void test_op_qname_equal_21() throws Exception {
    String inputFile = "/TestSources/emptydoc.xml";
    String xqFile = "/Queries/XQuery/Expressions/Operators/CompExpr/ValComp/QNameOp/QNameEQ/op-qname-equal-21.xq";
    String resultFile = "/ExpectedTestResults/Expressions/Operators/CompExpr/ValComp/QNameOp/QNameEQ/op-qname-equal-21.txt";
    String expectedResult = getExpectedResult(resultFile);
    URL fileURL = bundle.getEntry(inputFile);
    loadDOMDocument(fileURL);
    // Get XML Schema Information for the Document
    XSModel schema = getGrammar();
    setupDynamicContext(schema);
    String xpath = extractXPathExpression(xqFile, inputFile);
    String actual = null;
    try {
        compileXPath(xpath);
        ResultSequence rs = evaluate(domDoc);
        actual = buildResultString(rs);
    } catch (XPathParserException ex) {
        actual = ex.code();
    } catch (StaticError ex) {
        actual = ex.code();
    } catch (DynamicError ex) {
        actual = ex.code();
    }
    assertEquals("XPath Result Error " + xqFile + ":", expectedResult, actual);
}
Also used : XPathParserException(org.eclipse.wst.xml.xpath2.processor.XPathParserException) ResultSequence(org.eclipse.wst.xml.xpath2.processor.ResultSequence) XSModel(org.apache.xerces.xs.XSModel) StaticError(org.eclipse.wst.xml.xpath2.processor.StaticError) DynamicError(org.eclipse.wst.xml.xpath2.processor.DynamicError) URL(java.net.URL)

Aggregations

DynamicError (org.eclipse.wst.xml.xpath2.processor.DynamicError)77 ResultSequence (org.eclipse.wst.xml.xpath2.processor.ResultSequence)77 URL (java.net.URL)76 XSModel (org.apache.xerces.xs.XSModel)76 StaticError (org.eclipse.wst.xml.xpath2.processor.StaticError)76 XPathParserException (org.eclipse.wst.xml.xpath2.processor.XPathParserException)76 QName (org.eclipse.wst.xml.xpath2.processor.internal.types.QName)42 ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)21 Iterator (java.util.Iterator)18 Collection (java.util.Collection)17 ArrayList (java.util.ArrayList)13 VarExprPair (org.eclipse.wst.xml.xpath2.processor.internal.ast.VarExprPair)11 AnyType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)10 NodeType (org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType)10 ListIterator (java.util.ListIterator)9 XSString (org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)9 XPathExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.XPathExpr)6 TypeDefinition (org.eclipse.wst.xml.xpath2.api.typesystem.TypeDefinition)5 SeqType (org.eclipse.wst.xml.xpath2.processor.internal.SeqType)5 Schema (javax.xml.validation.Schema)4