use of org.apache.xml.dtm.DTM in project robovm by robovm.
the class NodeSetDTM method addNodeInDocOrder.
// %TBD%
// /**
// * Add the node list to this node set in document order.
// *
// * @param start index.
// * @param end index.
// * @param testIndex index.
// * @param nodelist The nodelist to add.
// * @param support The XPath runtime context.
// *
// * @return false always.
// * @throws RuntimeException thrown if this NodeSetDTM is not of
// * a mutable type.
// */
// private boolean addNodesInDocOrder(int start, int end, int testIndex,
// NodeList nodelist, XPathContext support)
// {
//
// if (!m_mutable)
// throw new RuntimeException("This NodeSetDTM is not mutable!");
//
// boolean foundit = false;
// int i;
// int node = nodelist.item(testIndex);
//
// for (i = end; i >= start; i--)
// {
// int child = elementAt(i);
//
// if (child == node)
// {
// i = -2; // Duplicate, suppress insert
//
// break;
// }
//
// if (!support.getDOMHelper().isNodeAfter(node, child))
// {
// insertElementAt(node, i + 1);
//
// testIndex--;
//
// if (testIndex > 0)
// {
// boolean foundPrev = addNodesInDocOrder(0, i, testIndex, nodelist,
// support);
//
// if (!foundPrev)
// {
// addNodesInDocOrder(i, size() - 1, testIndex, nodelist, support);
// }
// }
//
// break;
// }
// }
//
// if (i == -1)
// {
// insertElementAt(node, 0);
// }
//
// return foundit;
// }
/**
* Add the node into a vector of nodes where it should occur in
* document order.
* @param node The node to be added.
* @param test true if we should test for doc order
* @param support The XPath runtime context.
* @return insertIndex.
* @throws RuntimeException thrown if this NodeSetDTM is not of
* a mutable type.
*/
public int addNodeInDocOrder(int node, boolean test, XPathContext support) {
if (!m_mutable)
//"This NodeSetDTM is not mutable!");
throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESETDTM_NOT_MUTABLE, null));
int insertIndex = -1;
if (test) {
// This needs to do a binary search, but a binary search
// is somewhat tough because the sequence test involves
// two nodes.
int size = size(), i;
for (i = size - 1; i >= 0; i--) {
int child = elementAt(i);
if (child == node) {
// Duplicate, suppress insert
i = -2;
break;
}
DTM dtm = support.getDTM(node);
if (!dtm.isNodeAfter(node, child)) {
break;
}
}
if (i != -2) {
insertIndex = i + 1;
insertElementAt(node, insertIndex);
}
} else {
insertIndex = this.size();
boolean foundit = false;
for (int i = 0; i < insertIndex; i++) {
if (i == node) {
foundit = true;
break;
}
}
if (!foundit)
addElement(node);
}
// checkDups();
return insertIndex;
}
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;
}
Aggregations