use of org.apache.xml.dtm.DTM in project robovm by robovm.
the class FuncSum method execute.
/**
* Execute the function. The function must return
* a valid object.
* @param xctxt The current execution context.
* @return A valid XObject.
*
* @throws javax.xml.transform.TransformerException
*/
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException {
DTMIterator nodes = m_arg0.asIterator(xctxt, xctxt.getCurrentNode());
double sum = 0.0;
int pos;
while (DTM.NULL != (pos = nodes.nextNode())) {
DTM dtm = nodes.getDTM(pos);
XMLString s = dtm.getStringValue(pos);
if (null != s)
sum += s.toDouble();
}
nodes.detach();
return new XNumber(sum);
}
use of org.apache.xml.dtm.DTM in project robovm by robovm.
the class NodeTest method execute.
/**
* Tell what the test score is for the given node.
*
*
* @param xctxt XPath runtime context.
* @param context The node being tested.
*
* @return {@link org.apache.xpath.patterns.NodeTest#SCORE_NODETEST},
* {@link org.apache.xpath.patterns.NodeTest#SCORE_NONE},
* {@link org.apache.xpath.patterns.NodeTest#SCORE_NSWILD},
* {@link org.apache.xpath.patterns.NodeTest#SCORE_QNAME}, or
* {@link org.apache.xpath.patterns.NodeTest#SCORE_OTHER}.
*
* @throws javax.xml.transform.TransformerException
*/
public XObject execute(XPathContext xctxt, int context) throws javax.xml.transform.TransformerException {
DTM dtm = xctxt.getDTM(context);
short nodeType = dtm.getNodeType(context);
if (m_whatToShow == DTMFilter.SHOW_ALL)
return m_score;
int nodeBit = (m_whatToShow & (0x00000001 << (nodeType - 1)));
switch(nodeBit) {
case DTMFilter.SHOW_DOCUMENT_FRAGMENT:
case DTMFilter.SHOW_DOCUMENT:
return SCORE_OTHER;
case DTMFilter.SHOW_COMMENT:
return m_score;
case DTMFilter.SHOW_CDATA_SECTION:
case DTMFilter.SHOW_TEXT:
// ? m_score : SCORE_NONE;
return m_score;
case DTMFilter.SHOW_PROCESSING_INSTRUCTION:
return subPartMatch(dtm.getNodeName(context), m_name) ? m_score : SCORE_NONE;
// the prefix expands, regardless of the local part of the name."
case DTMFilter.SHOW_NAMESPACE:
{
String ns = dtm.getLocalName(context);
return (subPartMatch(ns, m_name)) ? m_score : SCORE_NONE;
}
case DTMFilter.SHOW_ATTRIBUTE:
case DTMFilter.SHOW_ELEMENT:
{
return (m_isTotallyWild || (subPartMatchNS(dtm.getNamespaceURI(context), m_namespace) && subPartMatch(dtm.getLocalName(context), m_name))) ? m_score : SCORE_NONE;
}
default:
return SCORE_NONE;
}
// end switch(testType)
}
use of org.apache.xml.dtm.DTM in project robovm by robovm.
the class StepPattern method getProximityPosition.
/**
* Get the proximity position index of the current node based on this
* node test.
*
*
* @param xctxt XPath runtime context.
* @param predPos Which predicate we're evaluating of foo[1][2][3].
* @param findLast If true, don't terminate when the context node is found.
*
* @return the proximity position index of the current node based on the
* node test.
*/
private final int getProximityPosition(XPathContext xctxt, int predPos, boolean findLast) {
int pos = 0;
int context = xctxt.getCurrentNode();
DTM dtm = xctxt.getDTM(context);
int parent = dtm.getParent(context);
try {
DTMAxisTraverser traverser = dtm.getAxisTraverser(Axis.CHILD);
for (int child = traverser.first(parent); DTM.NULL != child; child = traverser.next(parent, child)) {
try {
xctxt.pushCurrentNode(child);
if (NodeTest.SCORE_NONE != super.execute(xctxt, child)) {
boolean pass = true;
try {
xctxt.pushSubContextList(this);
for (int i = 0; i < predPos; i++) {
xctxt.pushPredicatePos(i);
try {
XObject pred = m_predicates[i].execute(xctxt);
try {
if (XObject.CLASS_NUMBER == pred.getType()) {
if ((pos + 1) != (int) pred.numWithSideEffects()) {
pass = false;
break;
}
} else if (!pred.boolWithSideEffects()) {
pass = false;
break;
}
} finally {
pred.detach();
}
} finally {
xctxt.popPredicatePos();
}
}
} finally {
xctxt.popSubContextList();
}
if (pass)
pos++;
if (!findLast && child == context) {
return pos;
}
}
} finally {
xctxt.popCurrentNode();
}
}
} catch (javax.xml.transform.TransformerException se) {
// TODO: should keep throw sax exception...
throw new java.lang.RuntimeException(se.getMessage());
}
return pos;
}
use of org.apache.xml.dtm.DTM in project robovm by robovm.
the class XString method rtf.
/**
* Cast result object to a result tree fragment.
*
* @param support Xpath context to use for the conversion
*
* @return A document fragment with this string as a child node
*/
public int rtf(XPathContext support) {
DTM frag = support.createDocumentFragment();
frag.appendTextChild(str());
return frag.getDocument();
}
use of org.apache.xml.dtm.DTM in project j2objc by google.
the class FuncSum method execute.
/**
* Execute the function. The function must return
* a valid object.
* @param xctxt The current execution context.
* @return A valid XObject.
*
* @throws javax.xml.transform.TransformerException
*/
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException {
DTMIterator nodes = m_arg0.asIterator(xctxt, xctxt.getCurrentNode());
double sum = 0.0;
int pos;
while (DTM.NULL != (pos = nodes.nextNode())) {
DTM dtm = nodes.getDTM(pos);
XMLString s = dtm.getStringValue(pos);
if (null != s)
sum += s.toDouble();
}
nodes.detach();
return new XNumber(sum);
}
Aggregations