use of org.eclipse.wst.xml.xpath2.api.Item in project webtools.sourceediting by eclipse.
the class InternalContextExprTest method test_internalcontextitem_8.
// Evaluation of Internal context item expression where context item is used as aboolean with fn:not.
public void test_internalcontextitem_8() throws Exception {
String inputFile = "/TestSources/emptydoc.xml";
String xqFile = "/Queries/XQuery/Expressions/ContextExpr/InternalContextExpr/internalcontextitem-8.xq";
String resultFile = "/ExpectedTestResults/Expressions/ContextExpr/InternalContextExpr/internalcontextitem-8.txt";
String expectedResult = getExpectedResult(resultFile);
URL fileURL = bundle.getEntry(inputFile);
loadDOMDocument(fileURL);
// Get XML Schema Information for the Document
XSModel schema = getGrammar();
setupDynamicContext(schema);
String xpath = extractXPathExpression(xqFile, inputFile);
String actual = null;
try {
compileXPath(xpath);
ResultSequence rs = evaluate(domDoc);
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.api.Item in project webtools.sourceediting by eclipse.
the class NodeLangFuncTest method test_fn_lang_1.
// Evaluates the "lang" function with the second argument not set and no context item defined.
public void test_fn_lang_1() throws Exception {
String inputFile = "/TestSources/emptydoc.xml";
String xqFile = "/Queries/XQuery/Functions/NodeFunc/NodeLangFunc/fn-lang-1.xq";
String expectedResult = "XPDY0002";
URL fileURL = bundle.getEntry(inputFile);
loadDOMDocument(fileURL);
// Get XML Schema Information for the Document
XSModel schema = getGrammar();
setupDynamicContext(schema);
String xpath = "fn:lang(\"en\")";
String actual = null;
try {
compileXPath(xpath);
// no context
ResultSequence rs = evaluate(null);
} 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.api.Item in project webtools.sourceediting by eclipse.
the class NodeLangFuncTest method test_fn_lang_15.
// Evaluates the "lang" function with the context item not being a node.
public void test_fn_lang_15() throws Exception {
String inputFile = "/TestSources/emptydoc.xml";
String xqFile = "/Queries/XQuery/Functions/NodeFunc/NodeLangFunc/fn-lang-15.xq";
String expectedResult = "XPTY0004";
URL fileURL = bundle.getEntry(inputFile);
loadDOMDocument(fileURL);
// Get XML Schema Information for the Document
XSModel schema = getGrammar();
setupDynamicContext(schema);
String xpath = extractXPathExpression(xqFile, inputFile);
String actual = null;
try {
compileXPath(xpath);
ResultSequence rs = evaluate(domDoc);
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.api.Item in project webtools.sourceediting by eclipse.
the class DefaultEvaluator method node_cmp.
private ResultSequence node_cmp(int type, Collection args) {
assert args.size() == 2;
Iterator argsiter = args.iterator();
ResultSequence one = (ResultSequence) argsiter.next();
ResultSequence two = (ResultSequence) argsiter.next();
int size_one = one.size();
int size_two = two.size();
if (size_one > 1 || size_two > 1)
report_error(TypeError.invalid_type(null));
if (size_one == 0 || size_two == 0)
return ResultBuffer.EMPTY;
Item at_one = one.item(0);
Item at_two = two.item(0);
if (!(at_one instanceof NodeType) || !(at_two instanceof NodeType))
report_error(TypeError.invalid_type(null));
// ok we got the args finally
NodeType nt_one = (NodeType) at_one;
NodeType nt_two = (NodeType) at_two;
// we are pessimistic as usual
boolean answer = false;
// do comparison
switch(type) {
case CmpExpr.IS:
answer = nt_one.node_value() == nt_two.node_value();
break;
case CmpExpr.LESS_LESS:
answer = nt_one.before(nt_two);
break;
case CmpExpr.GREATER_GREATER:
answer = nt_one.after(nt_two);
break;
default:
assert false;
}
return XSBoolean.valueOf(answer);
}
use of org.eclipse.wst.xml.xpath2.api.Item in project webtools.sourceediting by eclipse.
the class DefaultEvaluator method descendant_or_self_node.
private ResultSequence descendant_or_self_node(ResultSequence rs) {
ResultBuffer res = new ResultBuffer();
Axis axis = new DescendantOrSelfAxis();
// for all nodes, get descendant or self nodes
for (Iterator i = rs.iterator(); i.hasNext(); ) {
NodeType item = (NodeType) i.next();
axis.iterate(item, res, _dc.getLimitNode());
}
return res.getSequence();
}
Aggregations