comparison common/src/main/java/digilib/io/Directory.java @ 903:7779b37d1d05

refactored into maven modules per servlet type. can build servlet-api 2.3 and 3.0 via profile now!
author robcast
date Tue, 26 Apr 2011 20:24:31 +0200
parents servlet/src/main/java/digilib/io/Directory.java@ba1eb2d821a2
children
comparison
equal deleted inserted replaced
902:89ba3ffcf552 903:7779b37d1d05
1 /* Directory -- Filesystem directory object
2
3 Digital Image Library servlet components
4
5 Copyright (C) 2003 Robert Casties (robcast@mail.berlios.de)
6
7 This program is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 2 of the License, or (at your
10 option) any later version.
11
12 Please read license.txt for the full details. A copy of the GPL
13 may be found at http://www.gnu.org/copyleft/lgpl.html
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
19 * Created on 26.08.2003
20 *
21 */
22 package digilib.io;
23
24 import java.io.File;
25 import java.util.Arrays;
26
27 import org.apache.log4j.Logger;
28
29 /** Class for filesystem directories
30 * @author casties
31 *
32 */
33 public class Directory {
34
35 protected Logger logger = Logger.getLogger(this.getClass());
36
37 /** File object pointing to the directory */
38 protected File dir = null;
39 /** parent directory */
40 protected Directory parent = null;
41 /** list of filenames in the directory */
42 protected String[] list = null;
43
44 /** Default constructor.
45 *
46 */
47 public Directory() {
48 super();
49 }
50
51 /** Constructor taking a File object.
52 *
53 * @param d
54 */
55 public Directory(File d) {
56 dir = d;
57 }
58
59 /** Constructor taking a File object and a parent.
60 *
61 * @param dir
62 * @param parent
63 */
64 public Directory(File dir, Directory parent) {
65 this.dir = dir;
66 this.parent = parent;
67 }
68
69 /** Constructor taking a directory name.
70 *
71 * @param d
72 */
73 public Directory(String dn) {
74 dir = new File(dn);
75 }
76
77
78 /** Reads the names of the files in the directory.
79 * Fills the filenames array. Returns if the operation was successful.
80 *
81 * @return
82 */
83 public boolean readDir() {
84 if (dir != null) {
85 //logger.debug("reading dir: "+dir.getPath());
86 list = dir.list();
87 if (list != null) {
88 Arrays.sort(list);
89 }
90 //logger.debug(" done");
91 }
92 return (list != null);
93 }
94
95 /**
96 * @return
97 */
98 public File getDir() {
99 return dir;
100 }
101
102 /**
103 * @param dir
104 */
105 public void setDir(File dir) {
106 this.dir = dir;
107 }
108
109 /**
110 * @return
111 */
112 Directory getParent() {
113 return parent;
114 }
115
116 /**
117 * @param parent
118 */
119 void setParent(Directory parent) {
120 this.parent = parent;
121 }
122
123
124 /**
125 * @return Returns the filenames.
126 */
127 public String[] getFilenames() {
128 return list;
129 }
130
131 /**
132 * @param filenames The filenames to set.
133 */
134 public void setFilenames(String[] filenames) {
135 this.list = filenames;
136 }
137
138 public void clearFilenames() {
139 this.list = null;
140 }
141 }