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 ChildIterator method asNode.
/**
* Return the first node out of the nodeset, if this expression is
* a nodeset expression. This is the default implementation for
* nodesets.
* <p>WARNING: Do not mutate this class from this function!</p>
* @param xctxt The XPath runtime context.
* @return the first node out of the nodeset, or DTM.NULL.
*/
public int asNode(XPathContext xctxt) throws javax.xml.transform.TransformerException {
int current = xctxt.getCurrentNode();
DTM dtm = xctxt.getDTM(current);
return dtm.getFirstChild(current);
}
use of org.apache.xml.dtm.DTM in project j2objc by google.
the class DescendantIterator method asNode.
/**
* Return the first node out of the nodeset, if this expression is
* a nodeset expression. This is the default implementation for
* nodesets.
* <p>WARNING: Do not mutate this class from this function!</p>
* @param xctxt The XPath runtime context.
* @return the first node out of the nodeset, or DTM.NULL.
*/
public int asNode(XPathContext xctxt) throws javax.xml.transform.TransformerException {
if (getPredicateCount() > 0)
return super.asNode(xctxt);
int current = xctxt.getCurrentNode();
DTM dtm = xctxt.getDTM(current);
DTMAxisTraverser traverser = dtm.getAxisTraverser(m_axis);
String localName = getLocalName();
String namespace = getNamespace();
int what = m_whatToShow;
// NodeTest.debugWhatToShow(what);
if (DTMFilter.SHOW_ALL == what || localName == NodeTest.WILD || namespace == NodeTest.WILD) {
return traverser.first(current);
} else {
int type = getNodeTypeTest(what);
int extendedType = dtm.getExpandedTypeID(namespace, localName, type);
return traverser.first(current, extendedType);
}
}
Aggregations