use of permafrost.tundra.xml.dom.Nodes in project Tundra by Permafrost.
the class xpath method get.
public static final void get(IData pipeline) throws ServiceException {
// --- <<IS-START(get)>> ---
// @subtype unknown
// @sigtype java 3.5
// [i] object:0:optional $content
// [i] field:0:optional $encoding
// [i] field:0:required $expression
// [i] record:0:optional $namespace
// [i] - field:0:optional default
// [i] field:0:optional $recurse? {"false","true"}
// [o] record:1:optional $nodes
// [o] - object:0:required node
// [o] - field:0:required name.qualified
// [o] - field:0:optional name.local
// [o] - field:0:optional name.prefix
// [o] - field:0:optional name.uri
// [o] - field:0:required type
// [o] - field:0:optional value
// [o] - record:1:optional attributes
// [o] -- object:0:required node
// [o] -- field:0:required name.qualified
// [o] -- field:0:optional name.local
// [o] -- field:0:optional name.prefix
// [o] -- field:0:optional name.uri
// [o] -- field:0:required type
// [o] -- field:0:optional value
// [o] - record:1:optional elements
// [o] -- object:0:required node
// [o] -- field:0:required name.qualified
// [o] -- field:0:optional name.local
// [o] -- field:0:optional name.prefix
// [o] -- field:0:optional name.uri
// [o] -- field:0:required type
// [o] -- field:0:optional value
// [o] field:0:required $nodes.length
IDataCursor cursor = pipeline.getCursor();
try {
Object content = IDataHelper.get(cursor, "$content");
Charset charset = IDataHelper.get(cursor, "$encoding", Charset.class);
String expression = IDataHelper.get(cursor, "$expression", String.class);
NamespaceContext namespace = IDataHelper.get(cursor, "$namespace", IDataNamespaceContext.class);
boolean recurse = IDataHelper.getOrDefault(cursor, "$recurse?", Boolean.class, false);
XPathExpression compiledExpression = XPathHelper.compile(expression, namespace);
Node node = null;
if (content instanceof Node) {
node = (Node) content;
} else if (content instanceof InputSource) {
node = DocumentHelper.parse((InputSource) content, namespace);
} else if (content != null) {
node = DocumentHelper.parse(InputStreamHelper.normalize(content, charset), charset, true, namespace);
}
Nodes nodes = XPathHelper.get(node, compiledExpression);
if (nodes != null) {
IDataHelper.put(cursor, "$nodes", nodes.reflect(namespace, recurse));
IDataHelper.put(cursor, "$nodes.length", nodes.size(), String.class);
} else {
IDataHelper.put(cursor, "$nodes.length", "0");
}
} catch (XPathExpressionException ex) {
ExceptionHelper.raise(ex);
} finally {
cursor.destroy();
}
// --- <<IS-END>> ---
}
Aggregations