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() {
|
|
65 if ((fileMeta != null) || (getFile() != null)) {
|
|
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) {
|
181
|
82 Logger.getLogger(this.getClass()).warn("error reading index.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;
|
181
|
98 } /**
|
|
99 * The filename sans extension.
|
|
100 *
|
|
101 * @return
|
|
102 */
|
176
|
103 public String getBasename() {
|
|
104 File f = getFile();
|
|
105 if (f == null) {
|
|
106 return null;
|
|
107 }
|
|
108 return FileOps.basename(f.getName());
|
181
|
109 } /**
|
|
110 * Returns the parent Directory.
|
|
111 *
|
|
112 * @return DocuDirectory
|
|
113 */
|
159
|
114 public Directory getParent() {
|
|
115 return parent;
|
181
|
116 } /**
|
|
117 * Sets the parent Directory.
|
|
118 *
|
|
119 * @param parent
|
|
120 * The parent to set
|
|
121 */
|
159
|
122 public void setParent(Directory parent) {
|
|
123 this.parent = parent;
|
181
|
124 } /**
|
|
125 * Returns the meta-data for this file(set).
|
|
126 *
|
|
127 * @return HashMap
|
|
128 */
|
159
|
129 public HashMap getFileMeta() {
|
|
130 return fileMeta;
|
181
|
131 } /**
|
|
132 * Sets the meta-data for this file(set) .
|
|
133 *
|
|
134 * @param fileMeta
|
|
135 * The fileMeta to set
|
|
136 */
|
159
|
137 public void setFileMeta(HashMap fileMeta) {
|
|
138 this.fileMeta = fileMeta;
|
181
|
139 } /**
|
|
140 * @return
|
|
141 */
|
159
|
142 public boolean isMetaChecked() {
|
|
143 return metaChecked;
|
181
|
144 } /**
|
|
145 * @return
|
|
146 */
|
159
|
147 public static int getFileClass() {
|
|
148 return fileClass;
|
|
149 }
|
|
150
|
|
151 }
|