Ejemplo n.º 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;
  }
Ejemplo n.º 2
0
  /**
   * Adds a node to the node list for a given value. Nodes will always be added in document order.
   */
  public void add(Object value, int node, int rootNode) {
    if (_currentDocumentNode != rootNode) {
      _currentDocumentNode = rootNode;
      _index = new Hashtable();
      _rootToIndexMap.put(new Integer(rootNode), _index);
    }

    IntegerArray nodes = (IntegerArray) _index.get(value);

    if (nodes == null) {
      nodes = new IntegerArray();
      _index.put(value, nodes);
      nodes.add(node);

      // Because nodes are added in document order,
      // duplicates can be eliminated easily at this stage.
    } else if (node != nodes.at(nodes.cardinality() - 1)) {
      nodes.add(node);
    }
  }