01: /*
02: * Copyright 2004 Outerthought bvba and Schaubroeck nv
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.outerj.daisy.tools.importexport.import_.fs.local;
17:
18: import org.outerj.daisy.tools.importexport.import_.fs.ImportFile;
19: import org.outerj.daisy.tools.importexport.import_.fs.ImportFileEntry;
20: import org.outerj.daisy.tools.importexport.import_.fs.ImportFileNotFoundException;
21: import org.outerj.daisy.tools.importexport.import_.fs.FsUtil;
22:
23: import java.io.File;
24:
25: public class LocalImportFile implements ImportFile {
26: private ImportFileEntry root;
27:
28: public LocalImportFile(File root) {
29: this .root = new LocalImportFileEntry(root, null);
30: }
31:
32: public ImportFileEntry getPath(String path)
33: throws ImportFileNotFoundException {
34: String nameParts[] = FsUtil.parsePath(path);
35:
36: ImportFileEntry current = root;
37:
38: for (String namePart : nameParts) {
39: if (!current.hasChild(namePart))
40: throw new ImportFileNotFoundException(path);
41: current = current.getChild(namePart);
42: }
43:
44: return current;
45: }
46:
47: public boolean exists(String path) {
48: String nameParts[] = FsUtil.parsePath(path);
49:
50: ImportFileEntry current = root;
51:
52: for (String namePart : nameParts) {
53: if (!current.hasChild(namePart))
54: return false;
55: try {
56: current = current.getChild(namePart);
57: } catch (ImportFileNotFoundException e) {
58: // should not occur as we just tested for it
59: return false;
60: }
61: }
62:
63: return true;
64: }
65:
66: public ImportFileEntry getRoot() {
67: return root;
68: }
69: }
|