mkwan       2002/09/30 10:57:40

  Modified:    java/src/org/apache/xalan/xsltc/dom Tag: XSLTC_DTM
                        KeyIndex.java
  Log:
  Fix the id() function for DOM input. Changes are in the lookupId() and
  containsId() interfaces. A new interface getDOMNodeById() is introduced
  to return the DOM Node with the given id. The actual work is leveraged to
  the getElementById() interface in DOM2DTM.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.7.10.3  +62 -10    
xml-xalan/java/src/org/apache/xalan/xsltc/dom/KeyIndex.java
  
  Index: KeyIndex.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/dom/KeyIndex.java,v
  retrieving revision 1.7.10.2
  retrieving revision 1.7.10.3
  diff -u -r1.7.10.2 -r1.7.10.3
  --- KeyIndex.java     17 Sep 2002 21:08:52 -0000      1.7.10.2
  +++ KeyIndex.java     30 Sep 2002 17:57:40 -0000      1.7.10.3
  @@ -68,7 +68,7 @@
   import org.apache.xalan.xsltc.DOM;
   import org.apache.xalan.xsltc.NodeIterator;
   import org.apache.xalan.xsltc.runtime.Hashtable;
  -
  +import org.apache.xml.dtm.DTM;
   
   import org.apache.xml.dtm.DTMAxisIterator;
   
  @@ -137,6 +137,7 @@
        * key() function.
        */
       public void lookupId(Object value) {
  +        _nodes = null;
           if (value instanceof String) {
               boolean firstTime = true;
               final String string = (String)value;
  @@ -144,7 +145,12 @@
               if (string.indexOf(' ') > -1) {
                   StringTokenizer values = new StringTokenizer(string);
                   while (values.hasMoreElements()) {
  -                    BitArray nodes = 
(BitArray)_index.get(values.nextElement());
  +                    String token = (String)values.nextElement();
  +                    BitArray nodes = (BitArray)_index.get(token);
  +                    if (nodes == null && _dom instanceof DOMImpl) {
  +                     nodes = getDOMNodeById(token);
  +                    }
  +                    
                       if (nodes != null) {
                           if (firstTime) {
                               _nodes = nodes;
  @@ -154,13 +160,41 @@
                           }
                       }
                   }
  -                return;
               }
  +            else {
  +             _nodes = (BitArray)_index.get(value);
  +             if (_nodes == null && _dom instanceof DOMImpl) {
  +                 _nodes = getDOMNodeById(string);
  +             }
  +            }  
           }
  -        _nodes = (BitArray)_index.get(value);
  +        else    
  +            _nodes = (BitArray)_index.get(value);
       }
   
       /**
  +     * Return a BitArray for the DOM Node which has the given id.
  +     * 
  +     * @param id The id
  +     * @return A BitArray representing the Node whose id is the given value.
  +     */
  +    public BitArray getDOMNodeById(String id) {
  +        BitArray nodes = null;
  +        if (_dom instanceof DOMImpl) {
  +            DOMImpl domImpl = (DOMImpl)_dom;
  +            int node = domImpl.getElementById(id);
  +            int ident = domImpl.getNodeIdent(node);
  +            if (ident != DTM.NULL) {
  +             nodes = new BitArray(_arraySize);
  +             nodes.setMask(ident & 0xff000000);
  +             _index.put(id, nodes);
  +             nodes.setBit(ident & 0x00ffffff);
  +            }
  +        }
  +        return nodes;        
  +    }
  +    
  +    /**
        * This method must be called by the code generated by the key() function
        * prior to returning the node iterator.
        */
  @@ -184,16 +218,34 @@
            if (string.indexOf(' ') > -1) {
                StringTokenizer values = new StringTokenizer(string);
                while (values.hasMoreElements()) {
  -                 BitArray nodes = (BitArray)_index.get(values.nextElement());
  +                 String token = (String)values.nextElement();
  +                 BitArray nodes = (BitArray)_index.get(token);
  +                 if (nodes == null && _dom instanceof DOMImpl) {
  +                     nodes = getDOMNodeById(token);  
  +                 }
                    if ((nodes != null) && (nodes.getBit(node))) return(1);
                }
                return(0);
            }
  +            else {
  +             BitArray nodes = (BitArray)_index.get(value);
  +             if (nodes == null && _dom instanceof DOMImpl) {
  +                 nodes = getDOMNodeById(string);
  +             }
  +             
  +             if ((nodes != null) && (nodes.getBit(node)))
  +                 return(1);
  +             else
  +                 return(0);
  +            }  
  +     }
  +     else {
  +         BitArray nodes = (BitArray)_index.get(value);
  +         if ((nodes != null) && (nodes.getBit(node)))
  +             return(1);
  +         else
  +             return(0);
        }
  -
  -     BitArray nodes = (BitArray)_index.get(value);
  -     if ((nodes != null) && (nodes.getBit(node))) return(1);
  -     return(0);
       }
   
       public int containsKey(int node, Object value) { 
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to