use of org.eclipse.wst.xml.xpath2.api.Item in project webtools.sourceediting by eclipse.
the class FnTrace method trace.
/**
* Trace operation.
*
* @param args
* Result from the expressions evaluation.
* @throws DynamicError
* Dynamic error.
* @return Result of fn:trace operation.
*/
public static ResultSequence trace(Collection args) throws DynamicError {
// sanity check args
if (args.size() != 2)
DynamicError.throw_type_error();
Iterator argsi = args.iterator();
ResultSequence arg1 = (ResultSequence) argsi.next();
ResultSequence arg2 = (ResultSequence) argsi.next();
if (arg2.size() != 1)
DynamicError.throw_type_error();
Item at = arg2.first();
if (!(at instanceof XSString))
DynamicError.throw_type_error();
XSString label = (XSString) at;
int index = 1;
for (Iterator i = arg1.iterator(); i.hasNext(); index++) {
at = (AnyType) i.next();
System.out.println(label.value() + " [" + index + "] " + ((AnyType) at).string_type() + ":" + at.getStringValue());
}
return arg1;
}
use of org.eclipse.wst.xml.xpath2.api.Item in project webtools.sourceediting by eclipse.
the class FnRemove method remove.
/**
* Remove operation.
*
* @param args
* Result from the expressions evaluation.
* @throws DynamicError
* Dynamic error.
* @return Result of fn:remove operation.
*/
public static ResultSequence remove(Collection args) throws DynamicError {
assert args.size() == 2;
ResultBuffer rs = new ResultBuffer();
// get args
Iterator citer = args.iterator();
ResultSequence target = (ResultSequence) citer.next();
ResultSequence arg2 = (ResultSequence) citer.next();
// sanity chex
if (arg2.size() != 1)
DynamicError.throw_type_error();
Item at = arg2.first();
if (!(at instanceof XSInteger))
DynamicError.throw_type_error();
int position = ((XSInteger) at).int_value().intValue();
if (position < 1)
return target;
if (position > target.size())
return target;
if (target.empty())
return rs.getSequence();
int curpos = 1;
for (Iterator i = target.iterator(); i.hasNext(); ) {
at = (AnyType) i.next();
if (curpos != position)
rs.add(at);
curpos++;
}
return rs.getSequence();
}
use of org.eclipse.wst.xml.xpath2.api.Item in project webtools.sourceediting by eclipse.
the class STAxesTest method test_statictypingaxis_4.
// Evaluates static typing on parent axis. Context item not a node.
public void test_statictypingaxis_4() throws Exception {
String inputFile = "/TestSources/emptydoc.xml";
String xqFile = "/Queries/XQuery/StaticTyping/STPathExpr/STSteps/STAxes/statictypingaxis-4.xq";
String expectedResult = "XPTY0019";
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 STAxesTest method test_statictypingaxis_5.
// Evaluates static typing on descendant axis. Context item not a node.
public void test_statictypingaxis_5() throws Exception {
String inputFile = "/TestSources/emptydoc.xml";
String xqFile = "/Queries/XQuery/StaticTyping/STPathExpr/STSteps/STAxes/statictypingaxis-5.xq";
String expectedResult = "XPTY0019";
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 STAxesTest method test_statictypingaxis_1.
// Evaluates static typing on child axis. Context item not a node.
public void test_statictypingaxis_1() throws Exception {
String inputFile = "/TestSources/emptydoc.xml";
String xqFile = "/Queries/XQuery/StaticTyping/STPathExpr/STSteps/STAxes/statictypingaxis-1.xq";
String expectedResult = "XPTY0019";
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);
}
Aggregations