You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by cz...@apache.org on 2001/11/21 14:35:57 UTC

cvs commit: xml-cocoon2/src/org/apache/cocoon/components/store MRUMemoryStore.java

cziegeler    01/11/21 05:35:56

  Modified:    src/org/apache/cocoon/components/store Tag: cocoon_20_branch
                        MRUMemoryStore.java
  Log:
  Implemented keys() method
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.2.2.22  +57 -3     xml-cocoon2/src/org/apache/cocoon/components/store/MRUMemoryStore.java
  
  Index: MRUMemoryStore.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/components/store/MRUMemoryStore.java,v
  retrieving revision 1.2.2.21
  retrieving revision 1.2.2.22
  diff -u -r1.2.2.21 -r1.2.2.22
  --- MRUMemoryStore.java	2001/11/21 10:45:16	1.2.2.21
  +++ MRUMemoryStore.java	2001/11/21 13:35:56	1.2.2.22
  @@ -25,6 +25,8 @@
   import org.apache.cocoon.Constants;
   import org.apache.cocoon.util.ClassUtils;
   import org.apache.cocoon.util.IOUtils;
  +import org.apache.regexp.RE;
  +import org.apache.regexp.RESyntaxException;
   
   import java.io.File;
   import java.io.IOException;
  @@ -195,7 +197,6 @@
        */
       public Object get(Object key) {
           this.getLogger().debug("Getting object from memory. Key: " + key);
  -
           Object tmpobject = this.cache.get(key);
           if ( tmpobject != null ) {
               /** put the accessed key on top of the linked list */
  @@ -266,8 +267,7 @@
        * @return the enumeration of the cache
        */
       public Enumeration keys() {
  -        /* Not yet implemented */
  -        return null;
  +        return new StoreEnumeration(this.cache.keys(), this.fsstore.keys(),this.cachedirstr);
       }
   
       /**
  @@ -326,4 +326,58 @@
             .append(URLEncoder.encode(key.toString()))
             .toString();
       }
  +
  +    final class StoreEnumeration implements Enumeration {
  +
  +        private String[] array;
  +        private int      index;
  +        private int      length;
  +
  +        StoreEnumeration(Enumeration cache, Enumeration fs, String cachedir) {
  +            this.array = new String[16];
  +            this.length = 0;
  +            this.index = 0;
  +
  +            while (cache.hasMoreElements() == true) {
  +                this.add(cache.nextElement().toString());
  +            }
  +            RE re = null;
  +
  +            try {
  +                re = new RE("^" + cachedir);
  +            } catch(RESyntaxException ree) {
  +                ree.printStackTrace();
  +            }
  +
  +            while (fs.hasMoreElements() == true) {
  +                final String key = fs.nextElement().toString();
  +                if (re.match(cachedir) == true) {
  +                    this.add(key);
  +                }
  +            }
  +        }
  +
  +        public void add(String key) {
  +            if (this.length == array.length) {
  +                String[] newarray = new String[this.length + 16];
  +                System.arraycopy(this.array, 0, newarray, 0, this.array.length);
  +                this.array = newarray;
  +            }
  +            this.array[this.length] = key;
  +            this.length++;
  +        }
  +
  +        public boolean hasMoreElements() {
  +            return (this.index < this.length);
  +        }
  +
  +        public Object nextElement() {
  +            if (this.hasMoreElements() == true) {
  +                this.index++;
  +                return this.array[index-1];
  +            }
  +            return null;
  +        }
  +
  +   }
   }
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org