Search in sources :

Example 21 with DynamicContext

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

the class AbstractPsychoPathWTPTest method setupVariables.

protected DynamicContext setupVariables(DynamicContext dc) {
    dc.add_variable(new QName("x"));
    dc.add_variable(new QName("var"));
    if (domDoc != null) {
        AnyType docType = new DocType(domDoc, dc.getTypeModel(domDoc));
        dc.set_variable(new QName("input-context1"), docType);
        dc.set_variable(new QName("input-context"), docType);
        if (domDoc2 == null) {
            dc.set_variable(new QName("input-context2"), docType);
        } else {
            dc.set_variable(new QName("input-context2"), (AnyType) new DocType(domDoc2, dc.getTypeModel(domDoc2)));
        }
    }
    return dc;
}
Also used : QName(org.eclipse.wst.xml.xpath2.processor.internal.types.QName) AnyType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType) DocType(org.eclipse.wst.xml.xpath2.processor.internal.types.DocType)

Example 22 with DynamicContext

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

the class AbstractPsychoPathWTPTest method compileXPath.

protected XPath compileXPath(DynamicContext dc, String xpath) throws XPathParserException, StaticError {
    XPathParser xpp = new JFlexCupParser();
    XPath path = xpp.parse(xpath);
    StaticChecker name_check = new StaticNameResolver(dc);
    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 23 with DynamicContext

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

the class AbstractPsychoPathWTPTest method setupDynamicContext.

protected DefaultDynamicContext setupDynamicContext(XSModel schema) {
    XercesTypeModel typeModel = schema != null ? new XercesTypeModel(schema) : null;
    DefaultDynamicContext dc = new DefaultDynamicContext(typeModel);
    // DefaultDynamicContext dc = new DefaultDynamicContext(schema, domDoc);
    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 : FnFunctionLibrary(org.eclipse.wst.xml.xpath2.processor.function.FnFunctionLibrary) 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 24 with DynamicContext

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

the class AbstractPsychoPathWTPTest method compileXPath.

protected XPath compileXPath(DynamicContext dc, 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(dc);
    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 25 with DynamicContext

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

the class TestWTPDOMXPath2 method test_nodeexpression11.

// Evaluation of a Node expression With the operands/operator set with the
// following format: Single Node Element is Single Node Element.
public void test_nodeexpression11() throws Exception {
    String inputFile = "/TestSources/works.xml";
    String xqFile = "/Queries/XQuery/Expressions/Operators/NodeOp/NodeSame/nodeexpression11.xq";
    String resultFile = "/ExpectedTestResults/Expressions/Operators/NodeOp/NodeSame/nodeexpression11.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)

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