use of org.apache.xml.dtm.DTM in project robovm by robovm.
the class XPath method getMatchScore.
/**
* Get the match score of the given node.
*
* @param xctxt XPath runtime context.
* @param context The current source tree context node.
*
* @return score, one of {@link #MATCH_SCORE_NODETEST},
* {@link #MATCH_SCORE_NONE}, {@link #MATCH_SCORE_OTHER},
* or {@link #MATCH_SCORE_QNAME}.
*
* @throws javax.xml.transform.TransformerException
*/
public double getMatchScore(XPathContext xctxt, int context) throws javax.xml.transform.TransformerException {
xctxt.pushCurrentNode(context);
xctxt.pushCurrentExpressionNode(context);
try {
XObject score = m_mainExp.execute(xctxt);
if (DEBUG_MATCHES) {
DTM dtm = xctxt.getDTM(context);
System.out.println("score: " + score.num() + " for " + dtm.getNodeName(context) + " for xpath " + this.getPatternString());
}
return score.num();
} finally {
xctxt.popCurrentNode();
xctxt.popCurrentExpressionNode();
}
// return XPath.MATCH_SCORE_NONE;
}
use of org.apache.xml.dtm.DTM in project robovm by robovm.
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 robovm by robovm.
the class FuncDoclocation 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 {
int whereNode = getArg0AsNode(xctxt);
String fileLocation = null;
if (DTM.NULL != whereNode) {
DTM dtm = xctxt.getDTM(whereNode);
// %REVIEW%
if (DTM.DOCUMENT_FRAGMENT_NODE == dtm.getNodeType(whereNode)) {
whereNode = dtm.getFirstChild(whereNode);
}
if (DTM.NULL != whereNode) {
fileLocation = dtm.getDocumentBaseURI();
// int owner = dtm.getDocument();
// fileLocation = xctxt.getSourceTreeManager().findURIFromDoc(owner);
}
}
return new XString((null != fileLocation) ? fileLocation : "");
}
use of org.apache.xml.dtm.DTM in project robovm by robovm.
the class FuncId 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 {
int context = xctxt.getCurrentNode();
DTM dtm = xctxt.getDTM(context);
int docContext = dtm.getDocument();
if (DTM.NULL == docContext)
error(xctxt, XPATHErrorResources.ER_CONTEXT_HAS_NO_OWNERDOC, null);
XObject arg = m_arg0.execute(xctxt);
int argType = arg.getType();
XNodeSet nodes = new XNodeSet(xctxt.getDTMManager());
NodeSetDTM nodeSet = nodes.mutableNodeset();
if (XObject.CLASS_NODESET == argType) {
DTMIterator ni = arg.iter();
StringVector usedrefs = null;
int pos = ni.nextNode();
while (DTM.NULL != pos) {
DTM ndtm = ni.getDTM(pos);
String refval = ndtm.getStringValue(pos).toString();
pos = ni.nextNode();
usedrefs = getNodesByID(xctxt, docContext, refval, usedrefs, nodeSet, DTM.NULL != pos);
}
// ni.detach();
} else if (XObject.CLASS_NULL == argType) {
return nodes;
} else {
String refval = arg.str();
getNodesByID(xctxt, docContext, refval, null, nodeSet, false);
}
return nodes;
}
use of org.apache.xml.dtm.DTM in project robovm by robovm.
the class FuncId method getNodesByID.
/**
* Fill in a list with nodes that match a space delimited list if ID
* ID references.
*
* @param xctxt The runtime XPath context.
* @param docContext The document where the nodes are being looked for.
* @param refval A space delimited list of ID references.
* @param usedrefs List of references for which nodes were found.
* @param nodeSet Node set where the nodes will be added to.
* @param mayBeMore true if there is another set of nodes to be looked for.
*
* @return The usedrefs value.
*/
private StringVector getNodesByID(XPathContext xctxt, int docContext, String refval, StringVector usedrefs, NodeSetDTM nodeSet, boolean mayBeMore) {
if (null != refval) {
String ref = null;
// DOMHelper dh = xctxt.getDOMHelper();
StringTokenizer tokenizer = new StringTokenizer(refval);
boolean hasMore = tokenizer.hasMoreTokens();
DTM dtm = xctxt.getDTM(docContext);
while (hasMore) {
ref = tokenizer.nextToken();
hasMore = tokenizer.hasMoreTokens();
if ((null != usedrefs) && usedrefs.contains(ref)) {
ref = null;
continue;
}
int node = dtm.getElementById(ref);
if (DTM.NULL != node)
nodeSet.addNodeInDocOrder(node, xctxt);
if ((null != ref) && (hasMore || mayBeMore)) {
if (null == usedrefs)
usedrefs = new StringVector();
usedrefs.addElement(ref);
}
}
}
return usedrefs;
}
Aggregations