Mercurial > hg > digilib-old
annotate servlet/src/digilib/io/DocuDirent.java @ 567:70c135bd17aa stream
Starting 'stream' branch
author | robcast |
---|---|
date | Tue, 21 Dec 2010 10:05:54 +0100 |
parents | 686086d6e6d6 |
children | 790cbfb58b52 a7e157d258e8 |
rev | line source |
---|---|
181 | 1 /* |
2 * DocuDirent.java -- Abstract directory entry in a DocuDirectory | |
3 * | |
4 * Digital Image Library servlet components | |
5 * | |
6 * Copyright (C) 2003 Robert Casties (robcast@mail.berlios.de) | |
7 * | |
8 * This program is free software; you can redistribute it and/or modify it | |
9 * under the terms of the GNU General Public License as published by the Free | |
10 * Software Foundation; either version 2 of the License, or (at your option) | |
11 * any later version. | |
12 * | |
13 * Please read license.txt for the full details. A copy of the GPL may be found | |
14 * at http://www.gnu.org/copyleft/lgpl.html | |
15 * | |
16 * You should have received a copy of the GNU General Public License along with | |
17 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple | |
18 * Place, Suite 330, Boston, MA 02111-1307 USA | |
19 * | |
159 | 20 * Created on 15.09.2003 by casties |
181 | 21 * |
159 | 22 */ |
23 package digilib.io; | |
24 | |
25 import java.io.File; | |
271 | 26 import java.util.Map; |
159 | 27 |
181 | 28 import org.apache.log4j.Logger; |
29 | |
563 | 30 import digilib.io.FileOps.FileClass; |
31 | |
181 | 32 /** |
33 * Abstract directory entry in a DocuDirectory. | |
159 | 34 * |
35 * @author casties | |
181 | 36 * |
159 | 37 */ |
531 | 38 public abstract class DocuDirent implements Comparable<Object> { |
159 | 39 |
40 /** the file class of this file */ | |
563 | 41 protected static FileClass fileClass = FileClass.NONE; |
159 | 42 /** HashMap with metadata */ |
531 | 43 protected MetadataMap fileMeta = null; |
159 | 44 /** Is the Metadata valid */ |
45 protected boolean metaChecked = false; | |
46 /** the parent directory */ | |
47 protected Directory parent = null; | |
48 | |
181 | 49 /** |
50 * Checks metadata and does something with it. | |
51 * | |
159 | 52 */ |
53 public abstract void checkMeta(); | |
54 | |
55 /** | |
56 * gets the (default) File | |
181 | 57 * |
159 | 58 * @return |
59 */ | |
60 public abstract File getFile(); | |
61 | |
181 | 62 /** |
63 * Reads meta-data for this Fileset if there is any. | |
64 * | |
159 | 65 */ |
66 public void readMeta() { | |
195 | 67 if ((fileMeta != null) || (getFile() == null)) { |
159 | 68 // there is already metadata or there is no file |
69 return; | |
70 } | |
71 // metadata is in the file {filename}.meta | |
72 String fn = getFile().getAbsolutePath(); | |
73 File mf = new File(fn + ".meta"); | |
74 if (mf.canRead()) { | |
75 XMLMetaLoader ml = new XMLMetaLoader(); | |
76 try { | |
77 // read meta file | |
531 | 78 Map<String, MetadataMap> meta = ml.loadURL(mf.getAbsolutePath()); |
159 | 79 if (meta == null) { |
80 return; | |
81 } | |
531 | 82 fileMeta = meta.get(getName()); |
159 | 83 } catch (Exception e) { |
195 | 84 Logger.getLogger(this.getClass()).warn("error reading file .meta", e); |
159 | 85 } |
86 } | |
87 } | |
88 | |
181 | 89 /** |
90 * The name of the file. | |
176 | 91 * |
181 | 92 * If this is a Fileset, the method returns the name of the default file |
176 | 93 * (for image filesets the highest resolution file). |
159 | 94 * |
95 * @return | |
96 */ | |
97 public String getName() { | |
98 File f = getFile(); | |
99 return (f != null) ? f.getName() : null; | |
259 | 100 } |
101 | |
102 /** | |
103 * Returns the parent Directory. | |
104 * | |
105 * @return DocuDirectory | |
106 */ | |
159 | 107 public Directory getParent() { |
108 return parent; | |
259 | 109 } |
110 | |
111 /** | |
112 * Sets the parent Directory. | |
113 * | |
114 * @param parent | |
115 * The parent to set | |
116 */ | |
159 | 117 public void setParent(Directory parent) { |
118 this.parent = parent; | |
259 | 119 } |
120 | |
121 /** | |
122 * Returns the meta-data for this file(set). | |
123 * | |
124 * @return HashMap | |
125 */ | |
531 | 126 public MetadataMap getFileMeta() { |
159 | 127 return fileMeta; |
259 | 128 } |
129 | |
130 /** | |
131 * Sets the meta-data for this file(set) . | |
132 * | |
133 * @param fileMeta | |
134 * The fileMeta to set | |
135 */ | |
531 | 136 public void setFileMeta(MetadataMap fileMeta) { |
159 | 137 this.fileMeta = fileMeta; |
259 | 138 } |
139 | |
140 /** | |
141 * @return | |
142 */ | |
159 | 143 public boolean isMetaChecked() { |
144 return metaChecked; | |
259 | 145 } |
146 | |
147 /** | |
148 * @return | |
149 */ | |
563 | 150 public static FileClass getFileClass() { |
159 | 151 return fileClass; |
152 } | |
153 | |
271 | 154 /** Comparator using the file name. |
475
1fc30116efc3
modified DocuDirent.compareTo instead of ImageFileset.compareTo
hertzhaft
parents:
371
diff
changeset
|
155 * Compares to a String (for binarySearch) |
1fc30116efc3
modified DocuDirent.compareTo instead of ImageFileset.compareTo
hertzhaft
parents:
371
diff
changeset
|
156 * or to another DocuDirent (for sort) |
271 | 157 * |
158 * @see java.lang.Comparable#compareTo(java.lang.Object) | |
159 */ | |
160 public int compareTo(Object arg0) { | |
531 | 161 if (arg0 instanceof DocuDirent) { |
162 return getName().compareTo(((DocuDirent) arg0).getName()); | |
163 } else { | |
164 return getName().compareTo((String) arg0); | |
165 } | |
271 | 166 } |
475
1fc30116efc3
modified DocuDirent.compareTo instead of ImageFileset.compareTo
hertzhaft
parents:
371
diff
changeset
|
167 |
271 | 168 |
159 | 169 } |