/** * Returns a NodeSet containing one text node for each token in the first argument. * Delimiters are specified in the second argument. * Tokens are determined by a call to <code>StringTokenizer</code>. * If the first argument is an empty string or contains only delimiters, the result * will be an empty NodeSet. * * Contributed to XalanJ1 by <a href="mailto:benoit.cerrina@writeme.com">Benoit Cerrina</a>. * * @param toTokenize The string to be split into text tokens. * @param delims The delimiters to use. * @return a NodeSet as described above. */ public static NodeList tokenize(String toTokenize, String delims) { Document doc = DocumentHolder.m_doc; StringTokenizer lTokenizer = new StringTokenizer(toTokenize, delims); NodeSet resultSet = new NodeSet(); synchronized (doc) { while (lTokenizer.hasMoreTokens()) { resultSet.addNode(doc.createTextNode(lTokenizer.nextToken())); } } return resultSet; }
int size = size(), i; Node child = (Node) elementAt(i); insertElementAt(node, insertIndex); insertIndex = this.size(); if (this.item(i).equals(node)) addElement(node);
/** * Create a NodeSet, and copy the members of the * given nodelist into it. * * @param nodelist List of Nodes to be made members of the new set. */ public NodeSet(NodeList nodelist) { this(32); addNodes(nodelist); }
/** * Get a cloned Iterator, and reset its state to the beginning of the * iteration. * * @return a new NodeSet of the same type, having the same state... * except that the reset() operation has been called. * * @throws CloneNotSupportedException if this subclass of NodeSet * does not support the clone() operation. */ public NodeIterator cloneWithReset() throws CloneNotSupportedException { NodeSet clone = (NodeSet) clone(); clone.reset(); return clone; }
/** * Returns the <code>index</code>th item in the collection. If * <code>index</code> is greater than or equal to the number of nodes in * the list, this returns <code>null</code>. * * TODO: What happens if index is out of range? * * @param index Index into the collection. * @return The node at the <code>index</code>th position in the * <code>NodeList</code>, or <code>null</code> if that is not a valid * index. */ public Node item(int index) { runTo(index); return (Node) this.elementAt(index); }
/** * Returns the next node in the set and advances the position of the * iterator in the set. After a NodeIterator is created, the first call * to nextNode() returns the first node in the set. * @return The next <code>Node</code> in the set being iterated over, or * <code>null</code> if there are no more members in that set. * @throws DOMException * INVALID_STATE_ERR: Raised if this method is called after the * <code>detach</code> method was invoked. */ public Node nextNode() throws DOMException { if ((m_next) < this.size()) { Node next = this.elementAt(m_next); m_next++; return next; } else return null; }
Node child = (Node) elementAt(i); insertElementAt(node, i + 1); boolean foundPrev = addNodesInDocOrder(0, i, testIndex, nodelist, support); addNodesInDocOrder(i, size() - 1, testIndex, nodelist, support); insertElementAt(node, 0);
/** * The set:intersection function returns a node set comprising the nodes that are within * both the node sets passed as arguments to it. * * @param nl1 NodeList for first node-set. * @param nl2 NodeList for second node-set. * @return a NodeList containing the nodes in nl1 that are also * in nl2. * * @see <a href="http://www.exslt.org/">EXSLT</a> */ public static NodeList intersection(NodeList nl1, NodeList nl2) { NodeSet ns1 = new NodeSet(nl1); NodeSet ns2 = new NodeSet(nl2); NodeSet inter = new NodeSet(); inter.setShouldCacheNodes(true); for (int i = 0; i < ns1.getLength(); i++) { Node n = ns1.elementAt(i); if (ns2.contains(n)) inter.addElement(n); } return inter; }
NodeSet dist = new NodeSet(); dist.setShouldCacheNodes(true); dist.addElement(currNode); else if (!stringTable.containsKey(key)) dist.addElement(currNode);
/** * Returns true if both node-sets contain the same set of nodes. * * @param nl1 NodeList for first node-set * @param nl2 NodeList for second node-set * @return true if nl1 and nl2 contain exactly the same set of nodes. */ public static boolean hasSameNodes(NodeList nl1, NodeList nl2) { NodeSet ns1 = new NodeSet(nl1); NodeSet ns2 = new NodeSet(nl2); if (ns1.getLength() != ns2.getLength()) return false; for (int i = 0; i < ns1.getLength(); i++) { Node n = ns1.elementAt(i); if (!ns2.contains(n)) return false; } return true; }
NodeSet resultSet = new NodeSet(); resultSet.setShouldCacheNodes(true); Text text = doc.createTextNode(token); element.appendChild(text); resultSet.addNode(element);
return nl1; NodeSet ns1 = new NodeSet(nl1); NodeSet leadNodes = new NodeSet(); Node endNode = nl2.item(0); if (!ns1.contains(endNode)) return leadNodes; // empty NodeSet if (DOMHelper.isNodeAfter(testNode, endNode) && !DOMHelper.isNodeTheSame(testNode, endNode)) leadNodes.addElement(testNode);
/** * Add the node into a vector of nodes where it should occur in * document order. * @param node The node to be added. * @param support The XPath runtime context. * * @return The index where it was inserted. * @throws RuntimeException thrown if this NodeSet is not of * a mutable type. */ public int addNodeInDocOrder(Node node, XPathContext support) { if (!m_mutable) throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_NOT_MUTABLE, null)); //"This NodeSet is not mutable!"); return addNodeInDocOrder(node, true, support); } // end addNodeInDocOrder(Vector v, Object obj)
/** * Insert a node at a given position. * * @param n Node to be added * @param pos Offset at which the node is to be inserted, * with 0 being the first position. * @throws RuntimeException thrown if this NodeSet is not of * a mutable type. */ public void insertNode(Node n, int pos) { if (!m_mutable) throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_NOT_MUTABLE, null)); //"This NodeSet is not mutable!"); insertElementAt(n, pos); }
/** * Add a node to the NodeSet. Not all types of NodeSets support this * operation * * @param n Node to be added * @throws RuntimeException thrown if this NodeSet is not of * a mutable type. */ public void addNode(Node n) { if (!m_mutable) throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_NOT_MUTABLE, null)); //"This NodeSet is not mutable!"); this.addElement(n); }
/** * Create a NodeSet which contains the given Node. * * @param node Single node to be added to the new set. */ public NodeSet(Node node) { this(32); addNode(node); }
/** * Return the last fetched node. Needed to support the UnionPathIterator. * * @return the last fetched node. * @throws RuntimeException thrown if this NodeSet is not of * a cached type, and thus doesn't permit indexed access. */ public Node getCurrentNode() { if (!m_cacheNodes) throw new RuntimeException( XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_CANNOT_INDEX, null)); //"This NodeSet can not do indexing or counting functions!"); int saved = m_next; Node n = (m_next < m_firstFree) ? elementAt(m_next) : null; m_next = saved; // HACK: I think this is a bit of a hack. -sb return n; }
Node child = (Node) elementAt(i); insertElementAt(node, i + 1); boolean foundPrev = addNodesInDocOrder(0, i, testIndex, nodelist, support); addNodesInDocOrder(i, size() - 1, testIndex, nodelist, support); insertElementAt(node, 0);