cziegeler 01/11/21 05:36:14 Modified: src/org/apache/cocoon/components/store MRUMemoryStore.java Log: Implemented keys() method Revision Changes Path 1.24 +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.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- MRUMemoryStore.java 2001/11/21 10:45:40 1.23 +++ MRUMemoryStore.java 2001/11/21 13:36:14 1.24 @@ -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: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]