use of org.apache.xml.dtm.DTM in project j2objc by google.
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 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);
}
use of org.apache.xml.dtm.DTM in project j2objc by google.
the class FuncUnparsedEntityURI 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 {
String name = m_arg0.execute(xctxt).str();
int context = xctxt.getCurrentNode();
DTM dtm = xctxt.getDTM(context);
int doc = dtm.getDocument();
String uri = dtm.getUnparsedEntityURI(name);
return new XString(uri);
}
use of org.apache.xml.dtm.DTM in project j2objc by google.
the class FunctionDef1Arg method getArg0AsNumber.
/**
* Execute the first argument expression that is expected to return a
* number. If the argument is null, then get the number value from the
* current context node.
*
* @param xctxt Runtime XPath context.
*
* @return The number value of the first argument, or the number value of the
* current context node if the first argument is null.
*
* @throws javax.xml.transform.TransformerException if an error occurs while
* executing the argument expression.
*/
protected double getArg0AsNumber(XPathContext xctxt) throws javax.xml.transform.TransformerException {
if (null == m_arg0) {
int currentNode = xctxt.getCurrentNode();
if (DTM.NULL == currentNode)
return 0;
else {
DTM dtm = xctxt.getDTM(currentNode);
XMLString str = dtm.getStringValue(currentNode);
return str.toDouble();
}
} else
return m_arg0.execute(xctxt).num();
}
use of org.apache.xml.dtm.DTM in project j2objc by google.
the class XObject method rtf.
/**
* Cast result object to a result tree fragment.
*
* @param support XPath context to use for the conversion
*
* @return the objec as a result tree fragment.
*/
public int rtf(XPathContext support) {
int result = rtf();
if (DTM.NULL == result) {
DTM frag = support.createDocumentFragment();
// %OPT%
frag.appendTextChild(str());
result = frag.getDocument();
}
return result;
}
Aggregations