cziegeler 01/11/21 01:17:27 Modified: src/org/apache/cocoon/components/store Tag: cocoon_20_branch FilesystemStore.java Log: Fixed keys() method Revision Changes Path No revision No revision 1.1.1.1.2.8 +37 -8 xml-cocoon2/src/org/apache/cocoon/components/store/FilesystemStore.java Index: FilesystemStore.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/components/store/FilesystemStore.java,v retrieving revision 1.1.1.1.2.7 retrieving revision 1.1.1.1.2.8 diff -u -r1.1.1.1.2.7 -r1.1.1.1.2.8 --- FilesystemStore.java 2001/11/19 13:27:04 1.1.1.1.2.7 +++ FilesystemStore.java 2001/11/21 09:17:27 1.1.1.1.2.8 @@ -161,24 +161,53 @@ * Returns the list of stored files as an Enumeration of Files */ public Enumeration keys() { - return new EnumerationFromFileArray(this.directoryFile.listFiles()); + FSEnumeration enum = new FSEnumeration(); + this.addKeys(enum, this.directoryFile); + return enum; } - final class EnumerationFromFileArray implements Enumeration { - private File[] array; - private int index; + protected void addKeys(FSEnumeration enum, + File directory) { + final int subStringBegin = this.directoryFile.getAbsolutePath().length() + 1; + final File[] files = directory.listFiles(); + for(int i=0; i<files.length; i++) { + if (files[i].isDirectory() == true) { + this.addKeys(enum, files[i]); + } else { + enum.add(files[i].getAbsolutePath().substring(subStringBegin)); + } + } + } - EnumerationFromFileArray(File[] array) { - this.array = array; + final class FSEnumeration implements Enumeration { + private String[] array; + private int index; + private int length; + + FSEnumeration() { + this.array = new String[16]; + this.length = 0; this.index = 0; } + + 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.array.length); + return (this.index < this.length); } + public Object nextElement() { if (this.hasMoreElements() == true) { this.index++; - return this.array[index-1].getName(); + 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]