use of org.eclipse.wst.xml.xpath2.processor.DynamicContext in project webtools.sourceediting by eclipse.
the class TestXPath20 method testAddLibraries.
public void testAddLibraries() throws Exception {
DynamicContext dc = new DefaultDynamicContext(null, domDoc);
dc.add_namespace("xsd", "http://www.w3.org/2001/XMLSchema");
dc.add_function_library(new FnFunctionLibrary());
dc.add_function_library(new XSCtrLibrary());
}
use of org.eclipse.wst.xml.xpath2.processor.DynamicContext in project webtools.sourceediting by eclipse.
the class AbstractPsychoPathWTPTest method assertXPathTrue.
protected void assertXPathTrue(String xpath, DynamicContext dc, Document domDoc) {
XSBoolean result = evaluateBoolXPath(xpath, dc, domDoc);
assertEquals(true, result.value());
}
use of org.eclipse.wst.xml.xpath2.processor.DynamicContext in project webtools.sourceediting by eclipse.
the class AbstractPsychoPathWTPTest method setupDynamicContext2.
protected DefaultDynamicContext setupDynamicContext2(TypeModel model) {
DefaultDynamicContext dc = new DefaultDynamicContext(model);
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;
}
use of org.eclipse.wst.xml.xpath2.processor.DynamicContext in project webtools.sourceediting by eclipse.
the class AbstractPsychoPathWTPTest method evaluateSimpleXPath.
protected AnyType evaluateSimpleXPath(String xpath, DynamicContext dc, Document doc, Class resultClass) {
XPath path;
try {
path = compileXPath(dc, xpath);
} catch (XPathParserException e) {
throw new RuntimeException("XPath parse: " + e.getMessage(), e);
} catch (StaticError e) {
throw new RuntimeException("Static error: " + e.getMessage(), e);
}
Evaluator eval = new DefaultEvaluator(dc, doc);
ResultSequence rs;
try {
rs = eval.evaluate(path);
} catch (DynamicError e) {
throw new RuntimeException("Evaluation error: " + e.getMessage(), e);
}
assertEquals("Expected single result from \'" + xpath + "\'", 1, rs.size());
AnyType result = rs.first();
assertTrue("Exected XPath result instanceof class " + resultClass.getSimpleName() + " from \'" + xpath + "\', got " + result.getClass(), resultClass.isInstance(result));
return result;
}
use of org.eclipse.wst.xml.xpath2.processor.DynamicContext in project webtools.sourceediting by eclipse.
the class TestWTPDOMXPath2 method test_unabbreviatedSyntax_33.
// Evaluates unabbreviated syntax. Evaluate
// "child::*[self::empnum or self::pnum][fn:position() = fn:last()]".
// Selects the last empnum or pnum child of the context node.
public void test_unabbreviatedSyntax_33() throws Exception {
String inputFile = "/TestSources/works-mod.xml";
String xqFile = "/Queries/XQuery/Expressions/PathExpr/UnabbrAxes/unabbreviatedSyntax-33.xq";
String resultFile = "/ExpectedTestResults/Expressions/PathExpr/UnabbrAxes/unabbreviatedSyntax-33.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 = buildXMLResultString(rs);
} catch (XPathParserException ex) {
actual = ex.code();
} catch (StaticError ex) {
actual = ex.code();
} catch (DynamicError ex) {
actual = ex.code();
}
assertXMLEqual("XPath Result Error " + xqFile + ":", expectedResult, actual);
}
Aggregations