Mercurial > hg > digilib-old
annotate servlet/src/digilib/io/DocuDirent.java @ 494:43509321f9d2
Added getImage method to ImageLoaderDocuImage;
added pdf output
author | cmielack |
---|---|
date | Wed, 11 Feb 2009 16:36:57 +0100 |
parents | 1fc30116efc3 |
children | e758a49258e8 |
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 | |
30 /** | |
31 * Abstract directory entry in a DocuDirectory. | |
159 | 32 * |
33 * @author casties | |
181 | 34 * |
159 | 35 */ |
271 | 36 public abstract class DocuDirent implements Comparable { |
159 | 37 |
38 /** the file class of this file */ | |
181 | 39 protected static int fileClass = FileOps.CLASS_NONE; |
159 | 40 /** HashMap with metadata */ |
271 | 41 protected Map fileMeta = null; |
159 | 42 /** Is the Metadata valid */ |
43 protected boolean metaChecked = false; | |
44 /** the parent directory */ | |
45 protected Directory parent = null; | |
46 | |
181 | 47 /** |
48 * Checks metadata and does something with it. | |
49 * | |
159 | 50 */ |
51 public abstract void checkMeta(); | |
52 | |
53 /** | |
54 * gets the (default) File | |
181 | 55 * |
159 | 56 * @return |
57 */ | |
58 public abstract File getFile(); | |
59 | |
181 | 60 /** |
61 * Reads meta-data for this Fileset if there is any. | |
62 * | |
159 | 63 */ |
64 public void readMeta() { | |
195 | 65 if ((fileMeta != null) || (getFile() == null)) { |
159 | 66 // there is already metadata or there is no file |
67 return; | |
68 } | |
69 // metadata is in the file {filename}.meta | |
70 String fn = getFile().getAbsolutePath(); | |
71 File mf = new File(fn + ".meta"); | |
72 if (mf.canRead()) { | |
73 XMLMetaLoader ml = new XMLMetaLoader(); | |
74 try { | |
75 // read meta file | |
271 | 76 Map meta = ml.loadURL(mf.getAbsolutePath()); |
159 | 77 if (meta == null) { |
78 return; | |
79 } | |
271 | 80 fileMeta = (Map) meta.get(getName()); |
159 | 81 } catch (Exception e) { |
195 | 82 Logger.getLogger(this.getClass()).warn("error reading file .meta", e); |
159 | 83 } |
84 } | |
85 } | |
86 | |
181 | 87 /** |
88 * The name of the file. | |
176 | 89 * |
181 | 90 * If this is a Fileset, the method returns the name of the default file |
176 | 91 * (for image filesets the highest resolution file). |
159 | 92 * |
93 * @return | |
94 */ | |
95 public String getName() { | |
96 File f = getFile(); | |
97 return (f != null) ? f.getName() : null; | |
259 | 98 } |
99 | |
100 /** | |
101 * Returns the parent Directory. | |
102 * | |
103 * @return DocuDirectory | |
104 */ | |
159 | 105 public Directory getParent() { |
106 return parent; | |
259 | 107 } |
108 | |
109 /** | |
110 * Sets the parent Directory. | |
111 * | |
112 * @param parent | |
113 * The parent to set | |
114 */ | |
159 | 115 public void setParent(Directory parent) { |
116 this.parent = parent; | |
259 | 117 } |
118 | |
119 /** | |
120 * Returns the meta-data for this file(set). | |
121 * | |
122 * @return HashMap | |
123 */ | |
271 | 124 public Map getFileMeta() { |
159 | 125 return fileMeta; |
259 | 126 } |
127 | |
128 /** | |
129 * Sets the meta-data for this file(set) . | |
130 * | |
131 * @param fileMeta | |
132 * The fileMeta to set | |
133 */ | |
271 | 134 public void setFileMeta(Map fileMeta) { |
159 | 135 this.fileMeta = fileMeta; |
259 | 136 } |
137 | |
138 /** | |
139 * @return | |
140 */ | |
159 | 141 public boolean isMetaChecked() { |
142 return metaChecked; | |
259 | 143 } |
144 | |
145 /** | |
146 * @return | |
147 */ | |
159 | 148 public static int getFileClass() { |
149 return fileClass; | |
150 } | |
151 | |
271 | 152 /** Comparator using the file name. |
475
1fc30116efc3
modified DocuDirent.compareTo instead of ImageFileset.compareTo
hertzhaft
parents:
371
diff
changeset
|
153 * Compares to a String (for binarySearch) |
1fc30116efc3
modified DocuDirent.compareTo instead of ImageFileset.compareTo
hertzhaft
parents:
371
diff
changeset
|
154 * or to another DocuDirent (for sort) |
271 | 155 * |
156 * @see java.lang.Comparable#compareTo(java.lang.Object) | |
157 */ | |
158 public int compareTo(Object arg0) { | |
475
1fc30116efc3
modified DocuDirent.compareTo instead of ImageFileset.compareTo
hertzhaft
parents:
371
diff
changeset
|
159 return (arg0 instanceof DocuDirent) |
1fc30116efc3
modified DocuDirent.compareTo instead of ImageFileset.compareTo
hertzhaft
parents:
371
diff
changeset
|
160 ? getName().compareTo(((DocuDirent) arg0).getName()) |
1fc30116efc3
modified DocuDirent.compareTo instead of ImageFileset.compareTo
hertzhaft
parents:
371
diff
changeset
|
161 : getName().compareTo((String) arg0); |
271 | 162 } |
475
1fc30116efc3
modified DocuDirent.compareTo instead of ImageFileset.compareTo
hertzhaft
parents:
371
diff
changeset
|
163 |
271 | 164 |
159 | 165 } |