Search in sources :

Example 91 with DynamicContext

use of org.eclipse.wst.xml.xpath2.api.DynamicContext in project webtools.sourceediting by eclipse.

the class TestWTPDOMXPath2 method test_nodeexpression9.

// Evaluation of a Node expression With the operands/operator set with the
// following format: Single Node Element is empty Sequence.
public void test_nodeexpression9() throws Exception {
    String inputFile = "/TestSources/works.xml";
    String xqFile = "/Queries/XQuery/Expressions/Operators/NodeOp/NodeSame/nodeexpression9.xq";
    String resultFile = "/ExpectedTestResults/Expressions/Operators/NodeOp/NodeSame/nodeexpression9.txt";
    String expectedResult = getExpectedResult(resultFile);
    URL fileURL = bundle.getEntry(inputFile);
    domDoc = load(fileURL);
    // Get XML Schema Information for the Document
    XSModel schema = null;
    DynamicContext dc = setupDynamicContext(schema);
    String xpath = extractXPathExpression(xqFile, inputFile);
    String actual = null;
    try {
        XPath path = compileXPath(dc, xpath);
        Evaluator eval = new DefaultEvaluator(dc, domDoc);
        ResultSequence rs = eval.evaluate(path);
        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 : XPath(org.eclipse.wst.xml.xpath2.processor.ast.XPath) XPathParserException(org.eclipse.wst.xml.xpath2.processor.XPathParserException) ResultSequence(org.eclipse.wst.xml.xpath2.processor.ResultSequence) DefaultEvaluator(org.eclipse.wst.xml.xpath2.processor.DefaultEvaluator) XSModel(org.apache.xerces.xs.XSModel) StaticError(org.eclipse.wst.xml.xpath2.processor.StaticError) Evaluator(org.eclipse.wst.xml.xpath2.processor.Evaluator) DefaultEvaluator(org.eclipse.wst.xml.xpath2.processor.DefaultEvaluator) DynamicError(org.eclipse.wst.xml.xpath2.processor.DynamicError) URL(java.net.URL) DynamicContext(org.eclipse.wst.xml.xpath2.processor.DynamicContext)

Example 92 with DynamicContext

use of org.eclipse.wst.xml.xpath2.api.DynamicContext in project webtools.sourceediting by eclipse.

the class TestWTPDOMXPath2 method test_Axes074_1.

// No children of any kind, elem//child::* gets none.
public void test_Axes074_1() throws Exception {
    String inputFile = "/TestSources/TreeTrunc.xml";
    String xqFile = "/Queries/XQuery/Expressions/PathExpr/Steps/Axes/Axes074.xq";
    String resultFile = "/ExpectedTestResults/Expressions/PathExpr/Steps/Axes/Axes074-1.txt";
    String expectedResult = getExpectedResult(resultFile);
    URL fileURL = bundle.getEntry(inputFile);
    domDoc = load(fileURL);
    // Get XML Schema Information for the Document
    XSModel schema = null;
    DynamicContext dc = setupDynamicContext(schema);
    String xpath = extractXPathExpression(xqFile, inputFile);
    String actual = null;
    try {
        XPath path = compileXPath(dc, xpath);
        Evaluator eval = new DefaultEvaluator(dc, domDoc);
        ResultSequence rs = eval.evaluate(path);
        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 : XPath(org.eclipse.wst.xml.xpath2.processor.ast.XPath) XPathParserException(org.eclipse.wst.xml.xpath2.processor.XPathParserException) ResultSequence(org.eclipse.wst.xml.xpath2.processor.ResultSequence) DefaultEvaluator(org.eclipse.wst.xml.xpath2.processor.DefaultEvaluator) XSModel(org.apache.xerces.xs.XSModel) StaticError(org.eclipse.wst.xml.xpath2.processor.StaticError) Evaluator(org.eclipse.wst.xml.xpath2.processor.Evaluator) DefaultEvaluator(org.eclipse.wst.xml.xpath2.processor.DefaultEvaluator) DynamicError(org.eclipse.wst.xml.xpath2.processor.DynamicError) URL(java.net.URL) DynamicContext(org.eclipse.wst.xml.xpath2.processor.DynamicContext)

Example 93 with DynamicContext

use of org.eclipse.wst.xml.xpath2.api.DynamicContext in project webtools.sourceediting by eclipse.

the class CompleteNewApiTest method evaluateSimpleXPath.

protected Object evaluateSimpleXPath(String xpath, StaticContext sc, Document doc, Class resultClass) {
    XPath2Expression path = new Engine().parseExpression(xpath, sc);
    DynamicContext dynamicContext = new DynamicContextBuilder(sc);
    org.eclipse.wst.xml.xpath2.api.ResultSequence rs = path.evaluate(dynamicContext, doc != null ? new Object[] { doc } : new Object[0]);
    assertEquals("Expected single result from \'" + xpath + "\'", 1, rs.size());
    Object result = rs.value(0);
    assertTrue("Exected XPath result instanceof class " + resultClass.getSimpleName() + " from \'" + xpath + "\', got " + result.getClass(), resultClass.isInstance(result));
    return result;
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) DynamicContextBuilder(org.eclipse.wst.xml.xpath2.processor.util.DynamicContextBuilder) XPath2Expression(org.eclipse.wst.xml.xpath2.api.XPath2Expression) Engine(org.eclipse.wst.xml.xpath2.processor.Engine) DynamicContext(org.eclipse.wst.xml.xpath2.api.DynamicContext)

Example 94 with DynamicContext

use of org.eclipse.wst.xml.xpath2.api.DynamicContext in project webtools.sourceediting by eclipse.

the class AbstractPsychoPathTest method setupVariables.

protected DynamicContext setupVariables(DynamicContext dc) {
    setVariable("x", (AnyType) null);
    setVariable("var", (AnyType) null);
    if (domDoc != null) {
        TypeModel typeModel = dynamicContext != null ? dynamicContext.getTypeModel(domDoc) : staticContextBuilder.getTypeModel();
        AnyType docType = new DocType(domDoc, typeModel);
        setVariable("input-context1", docType);
        setVariable("input-context", docType);
        if (domDoc2 == null) {
            setVariable("input-context2", docType);
        } else {
            setVariable("input-context2", (AnyType) new DocType(domDoc2, typeModel));
        }
    }
    return dc;
}
Also used : TypeModel(org.eclipse.wst.xml.xpath2.api.typesystem.TypeModel) XercesTypeModel(org.eclipse.wst.xml.xpath2.processor.internal.types.xerces.XercesTypeModel) AnyType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType) DocType(org.eclipse.wst.xml.xpath2.processor.internal.types.DocType)

Example 95 with DynamicContext

use of org.eclipse.wst.xml.xpath2.api.DynamicContext in project webtools.sourceediting by eclipse.

the class FnNormalizeUnicode method normalize_unicode.

/**
 * Normalize unicode codepoints in the argument.
 *
 * @param args
 *            are used to obtain the input string and optionally the normalization type from.
 * @throws DynamicError
 *             Dynamic error.
 * @return The result of normalizing the space in the arguments.
 */
public static ResultSequence normalize_unicode(Collection args, DynamicContext d_context) throws DynamicError {
    assert args.size() >= 1 && args.size() <= 2;
    Collection cargs = Function.convert_arguments(args, expected_args());
    Iterator cargsIterator = cargs.iterator();
    ResultSequence arg1 = (ResultSequence) cargsIterator.next();
    String normalizationType = "NFC";
    if (cargsIterator.hasNext()) {
        ResultSequence arg2 = (ResultSequence) cargsIterator.next();
        // Trim and convert to upper as per the spec
        if (arg2.empty()) {
            normalizationType = "";
        } else {
            normalizationType = ((XSString) arg2.first()).value().trim().toUpperCase();
        }
    }
    String argument = "";
    if (!arg1.empty())
        argument = ((XSString) arg1.first()).value();
    String normalized = normalizationType.equals("") ? argument : getNormalizer().normalize(argument, normalizationType);
    return new XSString(normalized);
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) Iterator(java.util.Iterator) Collection(java.util.Collection) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)

Aggregations

XPath (org.eclipse.wst.xml.xpath2.processor.ast.XPath)77 DynamicContext (org.eclipse.wst.xml.xpath2.processor.DynamicContext)75 DynamicError (org.eclipse.wst.xml.xpath2.processor.DynamicError)75 URL (java.net.URL)73 DefaultEvaluator (org.eclipse.wst.xml.xpath2.processor.DefaultEvaluator)73 Evaluator (org.eclipse.wst.xml.xpath2.processor.Evaluator)73 ResultSequence (org.eclipse.wst.xml.xpath2.processor.ResultSequence)73 StaticError (org.eclipse.wst.xml.xpath2.processor.StaticError)72 XPathParserException (org.eclipse.wst.xml.xpath2.processor.XPathParserException)72 XSModel (org.apache.xerces.xs.XSModel)69 ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)20 Item (org.eclipse.wst.xml.xpath2.api.Item)17 Iterator (java.util.Iterator)13 AnyType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)11 Collection (java.util.Collection)10 XSBoolean (org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean)8 XSString (org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)8 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)6 XSDayTimeDuration (org.eclipse.wst.xml.xpath2.processor.internal.types.XSDayTimeDuration)6 Duration (javax.xml.datatype.Duration)5