use of org.eclipse.wst.xml.xpath2.processor.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);
}
use of org.eclipse.wst.xml.xpath2.processor.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);
}
use of org.eclipse.wst.xml.xpath2.processor.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;
}
use of org.eclipse.wst.xml.xpath2.processor.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;
}
use of org.eclipse.wst.xml.xpath2.processor.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);
}
Aggregations