Search in sources :

Example 61 with DynamicContext

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

the class TestWTPDOMXPath2 method test_Axes076_2.

// elem//child::node() gets 1 child element.
public void test_Axes076_2() throws Exception {
    String inputFile = "/TestSources/Tree1Child.xml";
    String xqFile = "/Queries/XQuery/Expressions/PathExpr/Steps/Axes/Axes076.xq";
    String resultFile = "/ExpectedTestResults/Expressions/PathExpr/Steps/Axes/Axes076-2.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 62 with DynamicContext

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

the class AbstractPsychoPathTest method compileXPath.

protected XPath compileXPath(String xpath, boolean isRootlessAccess) throws XPathParserException, StaticError {
    XPathParser xpp = new JFlexCupParser();
    XPath path = null;
    if (isRootlessAccess) {
        path = xpp.parse(xpath, isRootlessAccess);
    } else {
        path = xpp.parse(xpath);
    }
    StaticChecker name_check = new StaticNameResolver(dynamicContext);
    name_check.check(path);
    return path;
}
Also used : XPath(org.eclipse.wst.xml.xpath2.processor.ast.XPath) StaticChecker(org.eclipse.wst.xml.xpath2.processor.StaticChecker) XPathParser(org.eclipse.wst.xml.xpath2.processor.XPathParser) StaticNameResolver(org.eclipse.wst.xml.xpath2.processor.StaticNameResolver) JFlexCupParser(org.eclipse.wst.xml.xpath2.processor.JFlexCupParser)

Example 63 with DynamicContext

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

the class AbstractPsychoPathTest method setupDynamicContext.

protected DefaultDynamicContext setupDynamicContext(XSModel schema) {
    XercesTypeModel typeModel = schema != null ? new XercesTypeModel(schema) : null;
    if (useNewApi) {
        staticContextBuilder.withTypeModel(typeModel);
        staticContextBuilder.withNamespace("xs", "http://www.w3.org/2001/XMLSchema");
        staticContextBuilder.withNamespace("xsd", "http://www.w3.org/2001/XMLSchema");
        staticContextBuilder.withNamespace("fn", "http://www.w3.org/2005/xpath-functions");
        staticContextBuilder.withNamespace("xml", "http://www.w3.org/XML/1998/namespace");
        dynamicContextBuilder = new DynamicContextBuilder(staticContextBuilder);
        setupVariables(dynamicContext);
        try {
            dynamicContextBuilder.withTimezoneOffset(DatatypeFactory.newInstance().newDuration(false, /*i.e. negative*/
            0, 0, 0, 5, 0, 0));
        } catch (DatatypeConfigurationException e) {
            throw new RuntimeException("Shouldn't fail here", e);
        }
        return null;
    }
    DefaultDynamicContext dc = new DefaultDynamicContext(typeModel);
    dynamicContext = dc;
    dc.add_namespace("xs", "http://www.w3.org/2001/XMLSchema");
    dc.add_namespace("xsd", "http://www.w3.org/2001/XMLSchema");
    dc.add_namespace("fn", "http://www.w3.org/2005/xpath-functions");
    dc.add_namespace("xml", "http://www.w3.org/XML/1998/namespace");
    dc.add_function_library(new FnFunctionLibrary());
    dc.add_function_library(new XSCtrLibrary());
    setupVariables(dc);
    return dc;
}
Also used : DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) FnFunctionLibrary(org.eclipse.wst.xml.xpath2.processor.function.FnFunctionLibrary) DynamicContextBuilder(org.eclipse.wst.xml.xpath2.processor.util.DynamicContextBuilder) DefaultDynamicContext(org.eclipse.wst.xml.xpath2.processor.DefaultDynamicContext) XercesTypeModel(org.eclipse.wst.xml.xpath2.processor.internal.types.xerces.XercesTypeModel) XSCtrLibrary(org.eclipse.wst.xml.xpath2.processor.function.XSCtrLibrary)

Example 64 with DynamicContext

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

the class AbstractPsychoPathTest method compileXPath.

protected XPath compileXPath(String xpath) throws XPathParserException, StaticError {
    if (useNewApi) {
        newXPath = new Engine().parseExpression(xpath, staticContextBuilder);
        return null;
    } else {
        XPathParser xpp = new JFlexCupParser();
        XPath path = oldXPath = xpp.parse(xpath);
        StaticChecker name_check = new StaticNameResolver(dynamicContext);
        name_check.check(path);
        return path;
    }
}
Also used : XPath(org.eclipse.wst.xml.xpath2.processor.ast.XPath) StaticChecker(org.eclipse.wst.xml.xpath2.processor.StaticChecker) XPathParser(org.eclipse.wst.xml.xpath2.processor.XPathParser) StaticNameResolver(org.eclipse.wst.xml.xpath2.processor.StaticNameResolver) JFlexCupParser(org.eclipse.wst.xml.xpath2.processor.JFlexCupParser) Engine(org.eclipse.wst.xml.xpath2.processor.Engine)

Example 65 with DynamicContext

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

the class TestXPath20 method testSetupNullContenxt.

public void testSetupNullContenxt() throws Exception {
    DynamicContext dc = new DefaultDynamicContext(null, null);
    dc.add_namespace("xsd", "http://www.w3.org/2001/XMLSchema");
}
Also used : DefaultDynamicContext(org.eclipse.wst.xml.xpath2.processor.DefaultDynamicContext) DynamicContext(org.eclipse.wst.xml.xpath2.processor.DynamicContext) DefaultDynamicContext(org.eclipse.wst.xml.xpath2.processor.DefaultDynamicContext)

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