01: /*
02: * Copyright 2007 Gerd Ziegler (www.gerdziegler.de)
03: * Licensed under the Apache License, Version 2.0 (the "License");
04: * you may not use this file except in compliance with the License.
05: * You may obtain a copy of the License at
06: * http://www.apache.org/licenses/LICENSE-2.0
07: * Unless required by applicable law or agreed to in writing,
08: * software distributed under the License is distributed on an
09: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
10: * either express or implied. See the License for the specific
11: * language governing permissions and limitations under the License.
12: * @author www.gerdziegler.de
13: */
14: package org.ztemplates.classpath;
15:
16: import java.io.File;
17: import java.io.FileInputStream;
18: import java.io.IOException;
19: import java.io.InputStream;
20:
21: public class ZClassPathItemFile implements ZClassPathItem {
22: private File file;
23:
24: public ZClassPathItemFile(File file) {
25: this .file = file;
26: }
27:
28: /**
29: * list
30: *
31: * @return ClassPathItem[]
32: */
33: public ZClassPathItem[] list() {
34: File[] content = file.listFiles();
35: if (content == null) {
36: return new ZClassPathItem[0];
37: }
38: ZClassPathItem[] ret = new ZClassPathItem[content.length];
39: for (int i = 0; i < content.length; i++) {
40: ret[i] = new ZClassPathItemFile(content[i]);
41: }
42: return ret;
43: }
44:
45: /**
46: * getRelativePath
47: *
48: * @param root
49: * ClassPathItem
50: * @return String
51: */
52: public String getRelativePath(ZClassPathItem root) throws Exception {
53: String p = getName();
54: String rp = root.getName();
55: String name = p.substring(rp.length() + 1);
56: return name;
57: }
58:
59: /**
60: * getName
61: *
62: * @return String
63: */
64: public String getName() throws IOException {
65: return file.getCanonicalPath();
66: }
67:
68: public boolean isDirectory() {
69: return file.isDirectory();
70: }
71:
72: public boolean isFile() {
73: return file.isFile();
74: }
75:
76: public InputStream getInputStream() throws IOException {
77: return new FileInputStream(file);
78: }
79: }
|