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;
|
|
26 import java.util.HashMap;
|
|
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 */
|
|
36 public abstract class DocuDirent {
|
|
37
|
|
38 /** the file class of this file */
|
181
|
39 protected static int fileClass = FileOps.CLASS_NONE;
|
159
|
40 /** HashMap with metadata */
|
|
41 protected HashMap fileMeta = null;
|
|
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
|
|
76 HashMap meta = ml.loadURL(mf.getAbsolutePath());
|
|
77 if (meta == null) {
|
|
78 return;
|
|
79 }
|
|
80 fileMeta = (HashMap) meta.get(getName());
|
|
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 */
|
159
|
124 public HashMap getFileMeta() {
|
|
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 */
|
159
|
134 public void setFileMeta(HashMap fileMeta) {
|
|
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
|
|
152 }
|