use of org.eclipse.wst.xml.xpath2.api.Item in project webtools.sourceediting by eclipse.
the class STAxesTest method test_statictypingaxis_2.
// Evaluates static typing on self axis. Context item not a node.
public void test_statictypingaxis_2() throws Exception {
String inputFile = "/TestSources/emptydoc.xml";
String xqFile = "/Queries/XQuery/StaticTyping/STPathExpr/STSteps/STAxes/statictypingaxis-2.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 AbstractURIFunction method escape_uri.
/**
* Apply the URI escaping rules to the arguments.
*
* @param args
* have the URI escaping rules applied to them.
* @param escape_space TODO
* @throws DynamicError
* Dynamic error.
* @return The result of applying the URI escaping rules to the arguments.
*/
public static ResultSequence escape_uri(Collection args, boolean escape_delimiters, boolean escape_space) throws DynamicError {
Collection cargs = Function.convert_arguments(args, expected_args());
Iterator argi = cargs.iterator();
ResultSequence arg1 = (ResultSequence) argi.next();
if (arg1.empty()) {
return new XSString("");
}
AnyType aat = (AnyType) arg1.item(0);
String str = aat.getStringValue();
ByteBuffer buffer = UTF_8.encode(str);
StringBuffer sb = new StringBuffer();
for (int i = 0; i < buffer.limit(); i++) {
byte x = buffer.get(i);
if (needs_escape(x, escape_delimiters, escape_space)) {
sb.append("%");
sb.append(Integer.toHexString(x & 0xFF).toUpperCase());
} else
sb.append((char) x);
}
return new XSString(sb.toString());
}
use of org.eclipse.wst.xml.xpath2.api.Item in project webtools.sourceediting by eclipse.
the class FnAdjustDateToTimeZone method adjustDate.
/**
* Evaluate the function using the arguments passed.
*
* @param args
* Result from the expressions evaluation.
* @param sc
* Result of static context operation.
* @throws DynamicError
* Dynamic error.
* @return Result of the fn:dateTime operation.
*/
public static ResultSequence adjustDate(Collection args, DynamicContext dc) throws DynamicError {
Collection cargs = Function.convert_arguments(args, expectedArgs());
// get args
Iterator argiter = cargs.iterator();
ResultSequence arg1 = (ResultSequence) argiter.next();
if (arg1.empty()) {
return ResultBuffer.EMPTY;
}
ResultSequence arg2 = ResultBuffer.EMPTY;
if (argiter.hasNext()) {
arg2 = (ResultSequence) argiter.next();
}
XSDate date = (XSDate) arg1.item(0);
XSDayTimeDuration timezone = null;
if (arg2.empty()) {
if (date.timezoned()) {
XSDate localized = new XSDate(date.calendar(), null);
return localized;
}
return arg1;
}
timezone = (XSDayTimeDuration) arg2.item(0);
if (timezone.lt(minDuration, dc) || timezone.gt(maxDuration, dc)) {
throw DynamicError.invalidTimezone();
}
if (date.tz() == null) {
return new XSDate(date.calendar(), timezone);
}
XMLGregorianCalendar xmlCalendar = _datatypeFactory.newXMLGregorianCalendar((GregorianCalendar) date.normalizeCalendar(date.calendar(), date.tz()));
Duration duration = _datatypeFactory.newDuration(timezone.getStringValue());
xmlCalendar.add(duration);
return new XSDate(xmlCalendar.toGregorianCalendar(), timezone);
}
use of org.eclipse.wst.xml.xpath2.api.Item in project webtools.sourceediting by eclipse.
the class ElementTest method createElementType.
private AnyType createElementType(Item at, StaticContext sc) {
anyType = new ElementType();
NodeType nodeType = (NodeType) at;
Node node = nodeType.node_value();
Document doc = null;
if (node.getNodeType() == Node.DOCUMENT_NODE) {
doc = (Document) node;
} else {
doc = nodeType.node_value().getOwnerDocument();
}
NodeList nodeList = null;
if (!wild()) {
nodeList = doc.getElementsByTagNameNS(name().namespace(), name().local());
} else {
nodeList = new SingleItemNodeListImpl(node);
}
if (nodeList.getLength() > 0) {
anyType = createElementForXSDType(nodeList, sc);
}
return anyType;
}
use of org.eclipse.wst.xml.xpath2.api.Item in project webtools.sourceediting by eclipse.
the class AttributeTest method createAttrType.
private AnyType createAttrType(Item at, StaticContext sc) {
anyType = new AttrType();
NodeType nodeType = (NodeType) at;
Node node = nodeType.node_value();
if (node == null) {
return anyType;
}
String nodeName = node.getLocalName();
if (wild()) {
if (type() != null) {
anyType = createAttrForXSDType(node, sc);
}
} else if (nodeName.equals(name().local())) {
if (type() != null) {
anyType = createAttrForXSDType(node, sc);
} else {
anyType = new AttrType((Attr) node, sc.getTypeModel());
}
}
return anyType;
}
Aggregations