Mercurial > hg > digilib-old
comparison servlet/src/digilib/io/DocuDirCache.java @ 151:bc8df0133c04
Servlet version 1.15b1
- information in index.meta works finally for files in subdirectories.
author | robcast |
---|---|
date | Mon, 01 Sep 2003 18:21:27 +0200 |
parents | 55bc0e928ac5 |
children | f4a5cfe37469 |
comparison
equal
deleted
inserted
replaced
150:84ddd05c95d5 | 151:bc8df0133c04 |
---|---|
66 System.out.println("Baah, duplicate key in DocuDirectory.put!"); | 66 System.out.println("Baah, duplicate key in DocuDirectory.put!"); |
67 } else { | 67 } else { |
68 map.put(s, newdir); | 68 map.put(s, newdir); |
69 numFiles += newdir.size(); | 69 numFiles += newdir.size(); |
70 } | 70 } |
71 } | |
72 | |
73 /** Add a directory to the cache and check its parents. | |
74 * | |
75 * @param newDir | |
76 */ | |
77 public void putDir(DocuDirectory newDir) { | |
78 put(newDir); | |
79 String parent = newDir.getParentDirName(); | |
80 if (parent != null) { | |
81 // check the parent in the cache | |
82 DocuDirectory pd = (DocuDirectory)map.get(parent); | |
83 if (pd == null) { | |
84 // the parent is unknown | |
85 pd = new DocuDirectory(parent, this); | |
86 putDir(pd); | |
87 } | |
88 newDir.setParent(pd); | |
89 } | |
90 // update dir in the end | |
91 newDir.readParentMeta(); | |
71 } | 92 } |
72 | 93 |
73 /** Returns the DocuFileset with the pathname <code>fn</code> and the | 94 /** Returns the DocuFileset with the pathname <code>fn</code> and the |
74 * index <code>in</code>. | 95 * index <code>in</code>. |
75 * | 96 * |
90 // cache miss | 111 // cache miss |
91 misses++; | 112 misses++; |
92 // see if it's a directory | 113 // see if it's a directory |
93 File f = new File(baseDirNames[0] + fn); | 114 File f = new File(baseDirNames[0] + fn); |
94 if (f.isDirectory()) { | 115 if (f.isDirectory()) { |
95 dd = new DocuDirectory(fn, baseDirNames); | 116 dd = new DocuDirectory(fn, this); |
96 if (dd.isValid()) { | 117 if (dd.isValid()) { |
97 // add to the cache | 118 // add to the cache |
98 put(dd); | 119 putDir(dd); |
99 } | 120 } |
100 } else { | 121 } else { |
101 // maybe it's a file | 122 // maybe it's a file |
102 if (f.canRead()) { | 123 if (f.canRead()) { |
103 // get the parent directory string (like we store it in the cache) | 124 // get the parent directory string (like we store it in the cache) |
104 String d = fn.substring(0, fn.lastIndexOf("/")); | 125 String d = fn.substring(0, fn.lastIndexOf("/")); |
105 // try it in the cache | 126 // try it in the cache |
106 dd = (DocuDirectory) map.get(d); | 127 dd = (DocuDirectory) map.get(d); |
107 if (dd == null) { | 128 if (dd == null) { |
108 // try to read from disk | 129 // try to read from disk |
109 dd = new DocuDirectory(d, baseDirNames); | 130 dd = new DocuDirectory(d, this); |
110 if (dd.isValid()) { | 131 if (dd.isValid()) { |
111 // add to the cache | 132 // add to the cache |
112 put(dd); | 133 putDir(dd); |
113 } else { | 134 } else { |
114 // invalid path | 135 // invalid path |
115 return null; | 136 return null; |
116 } | 137 } |
117 } else { | 138 } else { |
154 // cache miss | 175 // cache miss |
155 misses++; | 176 misses++; |
156 // see if it's a directory | 177 // see if it's a directory |
157 File f = new File(baseDirNames[0] + fn); | 178 File f = new File(baseDirNames[0] + fn); |
158 if (f.isDirectory()) { | 179 if (f.isDirectory()) { |
159 dd = new DocuDirectory(fn, baseDirNames); | 180 dd = new DocuDirectory(fn, this); |
160 if (dd.isValid()) { | 181 if (dd.isValid()) { |
161 // add to the cache | 182 // add to the cache |
162 put(dd); | 183 putDir(dd); |
163 } | 184 } |
164 } else { | 185 } else { |
165 // maybe it's a file | 186 // maybe it's a file |
166 if (f.canRead()) { | 187 if (f.canRead()) { |
167 // try the parent directory in the cache | 188 // try the parent directory in the cache |
168 dd = (DocuDirectory) map.get(f.getParent()); | 189 dd = (DocuDirectory) map.get(f.getParent()); |
169 if (dd == null) { | 190 if (dd == null) { |
170 // try to read from disk | 191 // try to read from disk |
171 dd = new DocuDirectory(f.getParent(), baseDirNames); | 192 dd = new DocuDirectory(f.getParent(), this); |
172 if (dd.isValid()) { | 193 if (dd.isValid()) { |
173 // add to the cache | 194 // add to the cache |
174 put(dd); | 195 putDir(dd); |
175 } else { | 196 } else { |
176 // invalid path | 197 // invalid path |
177 return null; | 198 return null; |
178 } | 199 } |
179 } else { | 200 } else { |