cziegeler 01/11/21 01:18:09
Modified: src/org/apache/cocoon/components/store FilesystemStore.java
Log:
Fixed keys() method
Revision Changes Path
1.9 +36 -7
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.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- FilesystemStore.java 2001/11/19 13:39:44 1.8
+++ FilesystemStore.java 2001/11/21 09:18:09 1.9
@@ -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;
+ 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));
+ }
+ }
+ }
+
+ final class FSEnumeration implements Enumeration {
+ private String[] array;
private int index;
+ private int length;
- EnumerationFromFileArray(File[] array) {
- this.array = array;
+ 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]