use of org.eclipse.wst.xml.xpath2.api.Item in project webtools.sourceediting by eclipse.
the class SeqIDREFFuncTest method test_fn_idref_2.
// Evaluation of fn:idref with second argument ommited and no context item.
public void test_fn_idref_2() throws Exception {
String inputFile = "/TestSources/emptydoc.xml";
String xqFile = "/Queries/XQuery/Functions/NodeSeqFunc/SeqIDREFFunc/fn-idref-2.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:idref(\"argument1\")";
String actual = null;
try {
compileXPath(xpath);
// no context
ResultSequence rs = evaluate(null);
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 SeqExactlyOneFuncTest method test_fn_exactly_one_1.
// Evaluates the "exactly-one" function with the argument set to a sequence with more than one item.
public void test_fn_exactly_one_1() throws Exception {
String inputFile = "/TestSources/emptydoc.xml";
String xqFile = "/Queries/XQuery/Functions/SeqFunc/CardinalitySeqFunc/SeqExactlyOneFunc/fn-exactly-one-1.xq";
String expectedResult = "FORG0005";
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 SeqBooleanFuncTest method test_context_item_1.
// Evaluates fn:boolean that uses a context item, which is not defined.
public void test_context_item_1() throws Exception {
String inputFile = "/TestSources/emptydoc.xml";
String xqFile = "/Queries/XQuery/Functions/SeqFunc/GeneralSeqFunc/SeqBooleanFunc/context-item-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 = extractXPathExpression(xqFile, inputFile);
xpath = "fn:boolean(.)";
String actual = null;
try {
compileXPath(xpath);
// no context
ResultSequence rs = evaluate(null);
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 StringFuncTest method test_fn_string_3.
// Evaluates the "string" function with argument set to "." and context item undefined.
public void test_fn_string_3() throws Exception {
String inputFile = "/TestSources/emptydoc.xml";
String xqFile = "/Queries/XQuery/Functions/AccessorFunc/StringFunc/fn-string-3.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:string(.)";
String actual = null;
try {
compileXPath(xpath);
// no context document!
ResultSequence rs = evaluate(null);
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 visit.
/**
* visit XPath expression
*
* @param e
* is the XPath expression.
* @return a new function
*/
public Object visit(XPathExpr e) {
XPathExpr xp = e;
ResultSequence rs = null;
Focus original_focus = focus();
// do all the steps
while (xp != null) {
StepExpr se = xp.expr();
if (se != null) {
// this is not the first step
if (rs != null) {
// results...
if (rs.size() == 0)
break;
// nodes!
for (Iterator i = rs.iterator(); i.hasNext(); ) {
AnyType item = (AnyType) i.next();
if (!(item instanceof NodeType)) {
report_error(TypeError.step_conatins_atoms(null));
// unreach
return null;
}
}
// check if we got a //
if (xp.slashes() == 2) {
rs = descendant_or_self_node(rs);
if (rs.size() == 0)
break;
}
// make result of previous step the new
// focus
set_focus(new Focus(rs));
// do the step for all item in context
rs = do_step(se);
} else // this is first step...
// note... we may be called from upstream...
// like in the expression sorbo/*[2] ... we may
// be called to evaluate the 2... the caller
// will iterate through the whole outer focus
// for us
{
// XXX ???
if (xp.slashes() == 1) {
rs = root_self_node();
set_focus(new Focus(rs));
rs = do_step(se);
} else if (xp.slashes() == 2) {
rs = root_self_node();
rs = descendant_or_self_node(rs);
set_focus(new Focus(rs));
rs = do_step(se);
} else
rs = (ResultSequence) se.accept(this);
}
} else // the expression is "/"
{
assert xp.slashes() == 1;
rs = root_self_node();
}
xp = xp.next();
}
// restore focus
set_focus(original_focus);
return rs;
}
Aggregations