use of org.apache.xpath.objects.XNodeSet in project j2objc by google.
the class KeyTable method getRefsTable.
/**
* @return lazy initialized refs table associating evaluation of key function
* with a XNodeSet
*/
private Hashtable getRefsTable() {
if (m_refsTable == null) {
// initial capacity set to a prime number to improve hash performance
m_refsTable = new Hashtable(89);
KeyIterator ki = (KeyIterator) (m_keyNodes).getContainedIter();
XPathContext xctxt = ki.getXPathContext();
Vector keyDecls = getKeyDeclarations();
int nKeyDecls = keyDecls.size();
int currentNode;
m_keyNodes.reset();
while (DTM.NULL != (currentNode = m_keyNodes.nextNode())) {
try {
for (int keyDeclIdx = 0; keyDeclIdx < nKeyDecls; keyDeclIdx++) {
KeyDeclaration keyDeclaration = (KeyDeclaration) keyDecls.elementAt(keyDeclIdx);
XObject xuse = keyDeclaration.getUse().execute(xctxt, currentNode, ki.getPrefixResolver());
if (xuse.getType() != xuse.CLASS_NODESET) {
XMLString exprResult = xuse.xstr();
addValueInRefsTable(xctxt, exprResult, currentNode);
} else {
DTMIterator i = ((XNodeSet) xuse).iterRaw();
int currentNodeInUseClause;
while (DTM.NULL != (currentNodeInUseClause = i.nextNode())) {
DTM dtm = xctxt.getDTM(currentNodeInUseClause);
XMLString exprResult = dtm.getStringValue(currentNodeInUseClause);
addValueInRefsTable(xctxt, exprResult, currentNode);
}
}
}
} catch (TransformerException te) {
throw new WrappedRuntimeException(te);
}
}
}
return m_refsTable;
}
use of org.apache.xpath.objects.XNodeSet in project j2objc by google.
the class KeyTable method getNodeSetDTMByKey.
/**
* Given a valid element key, return the corresponding node list.
*
* @param name The name of the key, which must match the 'name' attribute on xsl:key.
* @param ref The value that must match the value found by the 'match' attribute on xsl:key.
* @return a set of nodes referenced by the key named <CODE>name</CODE> and the reference <CODE>ref</CODE>. If no node is referenced by this key, an empty node set is returned.
*/
public XNodeSet getNodeSetDTMByKey(QName name, XMLString ref) {
XNodeSet refNodes = (XNodeSet) getRefsTable().get(ref);
// clone wiht reset the node set
try {
if (refNodes != null) {
refNodes = (XNodeSet) refNodes.cloneWithReset();
}
} catch (CloneNotSupportedException e) {
refNodes = null;
}
if (refNodes == null) {
// create an empty XNodeSet
KeyIterator ki = (KeyIterator) (m_keyNodes).getContainedIter();
XPathContext xctxt = ki.getXPathContext();
refNodes = new XNodeSet(xctxt.getDTMManager()) {
public void setRoot(int nodeHandle, Object environment) {
// Root cannot be set on non-iterated node sets. Ignore it.
}
};
refNodes.reset();
}
return refNodes;
}
use of org.apache.xpath.objects.XNodeSet in project robovm by robovm.
the class KeyManager method getNodeSetDTMByKey.
/**
* Given a valid element key, return the corresponding node list.
*
* @param xctxt The XPath runtime state
* @param doc The document node
* @param name The key element name
* @param ref The key value we're looking for
* @param nscontext The prefix resolver for the execution context
*
* @return A nodelist of nodes mathing the given key
*
* @throws javax.xml.transform.TransformerException
*/
public XNodeSet getNodeSetDTMByKey(XPathContext xctxt, int doc, QName name, XMLString ref, PrefixResolver nscontext) throws javax.xml.transform.TransformerException {
XNodeSet nl = null;
// yuck -sb
ElemTemplateElement template = (ElemTemplateElement) nscontext;
if ((null != template) && null != template.getStylesheetRoot().getKeysComposed()) {
boolean foundDoc = false;
if (null == m_key_tables) {
m_key_tables = new Vector(4);
} else {
int nKeyTables = m_key_tables.size();
for (int i = 0; i < nKeyTables; i++) {
KeyTable kt = (KeyTable) m_key_tables.elementAt(i);
if (kt.getKeyTableName().equals(name) && doc == kt.getDocKey()) {
nl = kt.getNodeSetDTMByKey(name, ref);
if (nl != null) {
foundDoc = true;
break;
}
}
}
}
if ((null == nl) && !foundDoc) /* && m_needToBuildKeysTable */
{
KeyTable kt = new KeyTable(doc, nscontext, name, template.getStylesheetRoot().getKeysComposed(), xctxt);
m_key_tables.addElement(kt);
if (doc == kt.getDocKey()) {
foundDoc = true;
nl = kt.getNodeSetDTMByKey(name, ref);
}
}
}
return nl;
}
use of org.apache.xpath.objects.XNodeSet in project robovm by robovm.
the class KeyTable method getRefsTable.
/**
* @return lazy initialized refs table associating evaluation of key function
* with a XNodeSet
*/
private Hashtable getRefsTable() {
if (m_refsTable == null) {
// initial capacity set to a prime number to improve hash performance
m_refsTable = new Hashtable(89);
KeyIterator ki = (KeyIterator) (m_keyNodes).getContainedIter();
XPathContext xctxt = ki.getXPathContext();
Vector keyDecls = getKeyDeclarations();
int nKeyDecls = keyDecls.size();
int currentNode;
m_keyNodes.reset();
while (DTM.NULL != (currentNode = m_keyNodes.nextNode())) {
try {
for (int keyDeclIdx = 0; keyDeclIdx < nKeyDecls; keyDeclIdx++) {
KeyDeclaration keyDeclaration = (KeyDeclaration) keyDecls.elementAt(keyDeclIdx);
XObject xuse = keyDeclaration.getUse().execute(xctxt, currentNode, ki.getPrefixResolver());
if (xuse.getType() != xuse.CLASS_NODESET) {
XMLString exprResult = xuse.xstr();
addValueInRefsTable(xctxt, exprResult, currentNode);
} else {
DTMIterator i = ((XNodeSet) xuse).iterRaw();
int currentNodeInUseClause;
while (DTM.NULL != (currentNodeInUseClause = i.nextNode())) {
DTM dtm = xctxt.getDTM(currentNodeInUseClause);
XMLString exprResult = dtm.getStringValue(currentNodeInUseClause);
addValueInRefsTable(xctxt, exprResult, currentNode);
}
}
}
} catch (TransformerException te) {
throw new WrappedRuntimeException(te);
}
}
}
return m_refsTable;
}
use of org.apache.xpath.objects.XNodeSet in project robovm by robovm.
the class FuncKey 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 {
// TransformerImpl transformer = (TransformerImpl)xctxt;
TransformerImpl transformer = (TransformerImpl) xctxt.getOwnerObject();
XNodeSet nodes = null;
int context = xctxt.getCurrentNode();
DTM dtm = xctxt.getDTM(context);
int docContext = dtm.getDocumentRoot(context);
if (DTM.NULL == docContext) {
// path.error(context, XPATHErrorResources.ER_CONTEXT_HAS_NO_OWNERDOC); //"context does not have an owner document!");
}
String xkeyname = getArg0().execute(xctxt).str();
QName keyname = new QName(xkeyname, xctxt.getNamespaceContext());
XObject arg = getArg1().execute(xctxt);
boolean argIsNodeSetDTM = (XObject.CLASS_NODESET == arg.getType());
KeyManager kmgr = transformer.getKeyManager();
// Don't bother with nodeset logic if the thing is only one node.
if (argIsNodeSetDTM) {
XNodeSet ns = (XNodeSet) arg;
ns.setShouldCacheNodes(true);
int len = ns.getLength();
if (len <= 1)
argIsNodeSetDTM = false;
}
if (argIsNodeSetDTM) {
Hashtable usedrefs = null;
DTMIterator ni = arg.iter();
int pos;
UnionPathIterator upi = new UnionPathIterator();
upi.exprSetParent(this);
while (DTM.NULL != (pos = ni.nextNode())) {
dtm = xctxt.getDTM(pos);
XMLString ref = dtm.getStringValue(pos);
if (null == ref)
continue;
if (null == usedrefs)
usedrefs = new Hashtable();
if (usedrefs.get(ref) != null) {
// We already have 'em.
continue;
} else {
// ISTRUE being used as a dummy value.
usedrefs.put(ref, ISTRUE);
}
XNodeSet nl = kmgr.getNodeSetDTMByKey(xctxt, docContext, keyname, ref, xctxt.getNamespaceContext());
nl.setRoot(xctxt.getCurrentNode(), xctxt);
// try
// {
upi.addIterator(nl);
// }
// catch(CloneNotSupportedException cnse)
// {
// // will never happen.
// }
//mnodeset.addNodesInDocOrder(nl, xctxt); needed??
}
int current = xctxt.getCurrentNode();
upi.setRoot(current, xctxt);
nodes = new XNodeSet(upi);
} else {
XMLString ref = arg.xstr();
nodes = kmgr.getNodeSetDTMByKey(xctxt, docContext, keyname, ref, xctxt.getNamespaceContext());
nodes.setRoot(xctxt.getCurrentNode(), xctxt);
}
return nodes;
}
Aggregations