Example #1
0
  /**
   * Return an IntegerArray for the DOM Node which has the given id.
   *
   * @param id The id
   * @return A IntegerArray representing the Node whose id is the given value.
   */
  public IntegerArray getDOMNodeById(String id) {
    IntegerArray nodes = null;

    if (_enhancedDOM != null) {
      int ident = _enhancedDOM.getElementById(id);

      if (ident != DTM.NULL) {
        Integer root = new Integer(_enhancedDOM.getDocument());
        Hashtable index = (Hashtable) _rootToIndexMap.get(root);

        if (index == null) {
          index = new Hashtable();
          _rootToIndexMap.put(root, index);
        } else {
          nodes = (IntegerArray) index.get(id);
        }

        if (nodes == null) {
          nodes = new IntegerArray();
          index.put(id, nodes);
        }

        nodes.add(_enhancedDOM.getNodeHandle(ident));
      }
    }

    return nodes;
  }
Example #2
0
  /**
   * Given a context node and the argument to the XPath <code>id</code> function, checks whether the
   * context node is in the set of nodes that results from that reference to the <code>id</code>
   * function. This is used in the implementation of <code>id</code> patterns.
   *
   * @param node The context node
   * @param value The argument to the <code>id</code> function
   * @return <code>1</code> if the context node is in the set of nodes returned by the reference to
   *     the <code>id</code> function; <code>0</code>, otherwise
   */
  public int containsID(int node, Object value) {
    final String string = (String) value;
    int rootHandle = _dom.getAxisIterator(Axis.ROOT).setStartNode(node).next();

    // Get the mapping table for the document containing the context node
    Hashtable index = (Hashtable) _rootToIndexMap.get(new Integer(rootHandle));

    // Split argument to id function into XML whitespace separated tokens
    final StringTokenizer values = new StringTokenizer(string, " \n\t");

    while (values.hasMoreElements()) {
      final String token = (String) values.nextElement();
      IntegerArray nodes = null;

      if (index != null) {
        nodes = (IntegerArray) index.get(token);
      }

      // If input was from W3C DOM, use DOM's getElementById to do
      // the look-up.
      if (nodes == null && _enhancedDOM != null && _enhancedDOM.hasDOMSource()) {
        nodes = getDOMNodeById(token);
      }

      // Did we find the context node in the set of nodes?
      if (nodes != null && nodes.indexOf(node) >= 0) {
        return 1;
      }
    }

    // Didn't find the context node in the set of nodes returned by id
    return 0;
  }
Example #3
0
  /**
   * This method must be called by the code generated by the id() function prior to returning the
   * node iterator. The lookup code for key() and id() differ in the way the lookup value can be
   * whitespace separated list of tokens for the id() function, but a single string for the key()
   * function.
   *
   * @deprecated
   */
  public void lookupId(Object value) {
    // Clear _nodes array
    _nodes = null;

    final StringTokenizer values = new StringTokenizer((String) value, " \n\t");
    while (values.hasMoreElements()) {
      final String token = (String) values.nextElement();
      IntegerArray nodes = (IntegerArray) _index.get(token);

      if (nodes == null && _enhancedDOM != null && _enhancedDOM.hasDOMSource()) {
        nodes = getDOMNodeById(token);
      }

      if (nodes == null) continue;

      if (_nodes == null) {
        nodes = (IntegerArray) nodes.clone();
        _nodes = nodes;
      } else {
        _nodes.merge(nodes);
      }
    }
  }