Mercurial > hg > digilib-old
annotate common/src/main/java/digilib/io/Directory.java @ 1041:81c2378f12ff
put the child back into the bath :-)
| author | hertzhaft |
|---|---|
| date | Thu, 22 Mar 2012 17:51:52 +0100 |
| parents | 7779b37d1d05 |
| children |
| rev | line source |
|---|---|
| 151 | 1 /* Directory -- Filesystem directory object |
| 149 | 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; | |
| 259 | 25 import java.util.Arrays; |
| 26 | |
| 27 import org.apache.log4j.Logger; | |
| 149 | 28 |
| 29 /** Class for filesystem directories | |
| 30 * @author casties | |
| 31 * | |
| 32 */ | |
| 33 public class Directory { | |
| 259 | 34 |
| 35 protected Logger logger = Logger.getLogger(this.getClass()); | |
| 36 | |
| 37 /** File object pointing to the directory */ | |
| 282 | 38 protected File dir = null; |
| 259 | 39 /** parent directory */ |
| 282 | 40 protected Directory parent = null; |
| 259 | 41 /** list of filenames in the directory */ |
| 42 protected String[] list = null; | |
| 149 | 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 | |
| 151 | 59 /** Constructor taking a File object and a parent. |
| 60 * | |
| 159 | 61 * @param dir |
| 62 * @param parent | |
| 151 | 63 */ |
| 64 public Directory(File dir, Directory parent) { | |
| 65 this.dir = dir; | |
| 66 this.parent = parent; | |
| 67 } | |
| 68 | |
| 149 | 69 /** Constructor taking a directory name. |
| 70 * | |
| 71 * @param d | |
| 72 */ | |
| 73 public Directory(String dn) { | |
| 74 dir = new File(dn); | |
| 75 } | |
| 76 | |
| 259 | 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) { | |
|
295
90bab835fc25
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
282
diff
changeset
|
85 //logger.debug("reading dir: "+dir.getPath()); |
| 259 | 86 list = dir.list(); |
| 355 | 87 if (list != null) { |
| 88 Arrays.sort(list); | |
| 89 } | |
|
295
90bab835fc25
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
282
diff
changeset
|
90 //logger.debug(" done"); |
| 259 | 91 } |
| 92 return (list != null); | |
| 93 } | |
| 94 | |
| 149 | 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 } | |
| 151 | 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 | |
| 149 | 123 |
| 259 | 124 /** |
| 125 * @return Returns the filenames. | |
| 126 */ | |
| 127 public String[] getFilenames() { | |
| 128 return list; | |
| 129 } | |
| 270 | 130 |
| 259 | 131 /** |
| 132 * @param filenames The filenames to set. | |
| 133 */ | |
| 134 public void setFilenames(String[] filenames) { | |
| 135 this.list = filenames; | |
| 136 } | |
| 270 | 137 |
| 138 public void clearFilenames() { | |
| 139 this.list = null; | |
| 140 } | |
| 149 | 141 } |
