Exemplo 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;
  }
Exemplo 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);
    }
  }
  public DTMAxisIterator setStartNode(int node) {
    if (_isRestartable) {
      _source.setStartNode(_startNode = node);

      _nodes.clear();
      while ((node = _source.next()) != END) {
        _nodes.add(node);
      }
      _currentIndex = 0;
      resetPosition();
    }
    return this;
  }
 public int getNode(int index) {
   if (index < _numCachedNodes) {
     return _nodes.at(index);
   } else if (!_isEnded) {
     int node = _source.next();
     if (node != END) {
       _nodes.add(node);
       _numCachedNodes++;
     } else {
       _isEnded = true;
     }
     return node;
   } else return END;
 }