use of org.eclipse.wst.xml.xpath2.api.Item in project webtools.sourceediting by eclipse.
the class XSInteger method plus.
/**
* Mathematical addition operator between this XSInteger and the supplied
* ResultSequence.
*
* @param arg
* The ResultSequence to perform an addition with
* @return A XSInteger consisting of the result of the mathematical
* addition.
*/
public ResultSequence plus(ResultSequence arg) throws DynamicError {
ResultSequence carg = convertResultSequence(arg);
Item at = get_single_arg(carg);
if (!(at instanceof XSInteger))
DynamicError.throw_type_error();
XSInteger val = (XSInteger) at;
return ResultSequenceFactory.create_new(new XSInteger(int_value().add(val.int_value())));
}
use of org.eclipse.wst.xml.xpath2.api.Item in project webtools.sourceediting by eclipse.
the class FnResolveURI method resolveURI.
/**
* Resolve-URI operation.
*
* @param args
* Result from the expressions evaluation.
* @param d_context
* Dynamic context
* @throws DynamicError
* Dynamic error.
* @return Result of fn:resolve-uri operation.
*/
public static ResultSequence resolveURI(Collection args, EvaluationContext ec) throws DynamicError {
if (ec.getStaticContext().getBaseUri() == null) {
throw DynamicError.noBaseURI();
}
Collection cargs = args;
Iterator argit = cargs.iterator();
ResultSequence relativeRS = (ResultSequence) argit.next();
ResultSequence baseUriRS = null;
if (argit.hasNext()) {
baseUriRS = (ResultSequence) argit.next();
}
if (relativeRS.empty()) {
return ResultBuffer.EMPTY;
}
Item relativeURI = relativeRS.first();
String resolvedURI = null;
if (baseUriRS == null) {
resolvedURI = resolveURI(ec.getStaticContext().getBaseUri().toString(), relativeURI.getStringValue());
} else {
Item baseURI = baseUriRS.first();
resolvedURI = resolveURI(baseURI.getStringValue(), relativeURI.getStringValue());
}
return new XSAnyURI(resolvedURI);
}
use of org.eclipse.wst.xml.xpath2.api.Item in project webtools.sourceediting by eclipse.
the class FnRoot method fn_root.
/**
* Root operation.
*
* @param arg
* Result from the expressions evaluation.
* @param dc
* Result of dynamic context operation.
* @throws DynamicError
* Dynamic error.
* @return Result of fn:root operation.
*/
public static ResultSequence fn_root(Collection args, EvaluationContext ec) {
Collection cargs = Function.convert_arguments(args, expected_args());
if (cargs.size() > 1)
throw new DynamicError(TypeError.invalid_type(null));
ResultSequence arg = null;
if (cargs.isEmpty()) {
if (ec.getContextItem() == null) {
throw DynamicError.contextUndefined();
}
arg = ResultBuffer.wrap(ec.getContextItem());
} else {
arg = (ResultSequence) cargs.iterator().next();
}
if (arg.empty()) {
return ResultBuffer.EMPTY;
}
Item aa = arg.item(0);
if (!(aa instanceof NodeType))
throw new DynamicError(TypeError.invalid_type(null));
NodeType nt = (NodeType) aa;
// ok we got a sane argument... own it.
Node root = nt.node_value();
while (root != null && !(root instanceof Document)) {
Node newroot = root.getParentNode();
if (newroot == null && root instanceof Attr) {
newroot = ((Attr) root).getOwnerElement();
}
// found it
if (newroot == null)
break;
root = newroot;
}
return NodeType.dom_to_xpath(root, ec.getStaticContext().getTypeModel());
}
use of org.eclipse.wst.xml.xpath2.api.Item in project webtools.sourceediting by eclipse.
the class InternalContextExprTest method test_internalcontextitem_12.
// Evaluation of Internal context item expression where context item used as part of a multiplication operation.
public void test_internalcontextitem_12() throws Exception {
String inputFile = "/TestSources/emptydoc.xml";
String xqFile = "/Queries/XQuery/Expressions/ContextExpr/InternalContextExpr/internalcontextitem-12.xq";
String resultFile = "/ExpectedTestResults/Expressions/ContextExpr/InternalContextExpr/internalcontextitem-12.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 InternalContextExprTest method test_internalcontextitem_16.
// Evaluation of Internal context item expression where context item used as part of a boolean expression (and operator).
public void test_internalcontextitem_16() throws Exception {
String inputFile = "/TestSources/emptydoc.xml";
String xqFile = "/Queries/XQuery/Expressions/ContextExpr/InternalContextExpr/internalcontextitem-16.xq";
String resultFile = "/ExpectedTestResults/Expressions/ContextExpr/InternalContextExpr/internalcontextitem-16.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);
}
Aggregations