use of org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType in project webtools.sourceediting by eclipse.
the class ParentAxis method iterate.
/**
* returns parent accessors of the context node
*
* @param node
* is the node type.
* @throws dc
* is the Dynamic context.
*/
public void iterate(NodeType node, ResultBuffer copyInto, Node limitNode) {
Node n = node.node_value();
if (limitNode != null && limitNode.isSameNode(n)) {
// no further, we have reached the limit node
return;
}
Node parent = findParent(n);
// if a parent exists... add it
if (parent != null) {
NodeType nodeType = NodeType.dom_to_xpath(parent, node.getTypeModel());
if (nodeType != null) {
copyInto.add(nodeType);
}
}
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType in project webtools.sourceediting by eclipse.
the class AbstractPsychoPathTest method buildXMLResultString.
protected String buildXMLResultString(ResultSequence rs) throws Exception {
DOMImplementationLS domLS = (DOMImplementationLS) domDoc.getImplementation().getFeature("LS", "3.0");
LSOutput outputText = domLS.createLSOutput();
LSSerializer serializer = null;
ClassLoader originalLoader = Thread.currentThread().getContextClassLoader();
DelegatingLoader newContext = new DelegatingLoader(originalLoader);
Thread.currentThread().setContextClassLoader(newContext);
try {
serializer = domLS.createLSSerializer();
} finally {
Thread.currentThread().setContextClassLoader(originalLoader);
}
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
outputText.setByteStream(outputStream);
String actual = new String();
Iterator iterator = rs.iterator();
boolean queueSpace = false;
while (iterator.hasNext()) {
AnyType aat = (AnyType) iterator.next();
if (aat instanceof NodeType) {
NodeType nodeType = (NodeType) aat;
Node node = nodeType.node_value();
serializer.write(node, outputText);
queueSpace = false;
} else {
if (queueSpace)
outputText.getByteStream().write(32);
outputText.getByteStream().write(aat.getStringValue().getBytes("UTF-8"));
queueSpace = true;
}
}
actual = outputStream.toString("UTF-8");
actual = actual.replace("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "");
actual = actual.replace("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>", "");
outputStream.close();
return actual.trim();
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType in project webtools.sourceediting by eclipse.
the class FnLocalName method local_name.
/**
* Local-Name operation.
*
* @param args
* Result from the expressions evaluation.
* @throws DynamicError
* Dynamic error.
* @return Result of fn:local-name operation.
*/
public static ResultSequence local_name(Collection args, EvaluationContext context) throws DynamicError {
Collection cargs = Function.convert_arguments(args, expected_args());
// get arg
ResultSequence arg1 = null;
if (cargs.isEmpty()) {
if (context.getContextItem() == null)
throw DynamicError.contextUndefined();
else {
arg1 = (AnyType) context.getContextItem();
}
} else {
arg1 = (ResultSequence) cargs.iterator().next();
}
if (arg1.empty()) {
return new XSString("");
}
NodeType an = (NodeType) arg1.first();
QName name = an.node_name();
String sname = "";
if (name != null)
sname = name.local();
return new XSString(sname);
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType in project webtools.sourceediting by eclipse.
the class FnDocumentUri method document_uri.
/**
* Document-Uri operation.
*
* @param args
* Result from the expressions evaluation.
* @throws DynamicError
* Dynamic error.
* @return Result of fn:document-uri operation.
*/
public static ResultSequence document_uri(Collection args) throws DynamicError {
Collection cargs = Function.convert_arguments(args, expected_args());
ResultSequence arg1 = (ResultSequence) cargs.iterator().next();
if (arg1.empty())
return ResultBuffer.EMPTY;
NodeType nt = (NodeType) arg1.first();
if (!(nt instanceof DocType))
return ResultBuffer.EMPTY;
DocType dt = (DocType) nt;
String documentURI = dt.value().getDocumentURI();
if (documentURI != null) {
XSAnyURI docUri = new XSAnyURI(documentURI);
return docUri;
}
return ResultBuffer.EMPTY;
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType in project webtools.sourceediting by eclipse.
the class FnIDREF method idref.
/**
* Insert-Before operation.
*
* @param args
* Result from the expressions evaluation.
* @param dc
* @throws DynamicError
* Dynamic error.
* @return Result of fn:insert-before operation.
*/
public static ResultSequence idref(Collection args, EvaluationContext ec) throws DynamicError {
Collection cargs = Function.convert_arguments(args, expected_args());
ResultBuffer rs = new ResultBuffer();
Iterator argIt = cargs.iterator();
ResultSequence idrefRS = (ResultSequence) argIt.next();
String[] idst = idrefRS.first().getStringValue().split(" ");
ArrayList ids = createIDs(idst);
ResultSequence nodeArg = null;
NodeType nodeType = null;
if (argIt.hasNext()) {
nodeArg = (ResultSequence) argIt.next();
nodeType = (NodeType) nodeArg.first();
} else {
if (ec.getContextItem() == null) {
throw DynamicError.contextUndefined();
}
if (!(ec.getContextItem() instanceof NodeType)) {
throw new DynamicError(TypeError.invalid_type(null));
}
nodeType = (NodeType) ec.getContextItem();
if (nodeType.node_value().getOwnerDocument() == null) {
throw DynamicError.contextUndefined();
}
}
Node node = nodeType.node_value();
if (node.getOwnerDocument() == null) {
// W3C test suite seems to want XPDY0002 here
throw DynamicError.contextUndefined();
// throw DynamicError.noContextDoc();
}
if (hasID(ids, node)) {
ElementType element = new ElementType((Element) node, ec.getStaticContext().getTypeModel());
rs.add(element);
}
rs = processAttributes(node, ids, rs, ec);
rs = processChildNodes(node, ids, rs, ec);
return rs.getSequence();
}
Aggregations