Mercurial > hg > digilib-old
comparison servlet/src/digilib/io/DocuDirentImpl.java @ 576:dad720e9b12b stream
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
author | robcast |
---|---|
date | Wed, 22 Dec 2010 20:19:06 +0100 |
parents | servlet/src/digilib/io/DocuDirent.java@790cbfb58b52 |
children | c7034d166a24 |
comparison
equal
deleted
inserted
replaced
574:790cbfb58b52 | 576:dad720e9b12b |
---|---|
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 * | |
20 * Created on 15.09.2003 by casties | |
21 * | |
22 */ | |
23 package digilib.io; | |
24 | |
25 import java.io.File; | |
26 import java.util.Map; | |
27 | |
28 import org.apache.log4j.Logger; | |
29 | |
30 import digilib.io.FileOps.FileClass; | |
31 | |
32 /** | |
33 * Abstract directory entry in a DocuDirectory. | |
34 * | |
35 * @author casties | |
36 * | |
37 */ | |
38 public abstract class DocuDirentImpl implements DocuDirent { | |
39 | |
40 /** the file class of this file */ | |
41 protected static FileClass fileClass = FileClass.NONE; | |
42 /** HashMap with metadata */ | |
43 protected MetadataMap fileMeta = null; | |
44 /** Is the Metadata valid */ | |
45 protected boolean metaChecked = false; | |
46 /** the parent directory */ | |
47 protected Directory parent = null; | |
48 | |
49 /* (non-Javadoc) | |
50 * @see digilib.io.DocuDirent#checkMeta() | |
51 */ | |
52 public abstract void checkMeta(); | |
53 | |
54 /* (non-Javadoc) | |
55 * @see digilib.io.DocuDirent#getInput() | |
56 */ | |
57 public abstract File getInput(); | |
58 | |
59 /* (non-Javadoc) | |
60 * @see digilib.io.DocuDirent#readMeta() | |
61 */ | |
62 public void readMeta() { | |
63 if ((fileMeta != null) || (getInput() == null)) { | |
64 // there is already metadata or there is no file | |
65 return; | |
66 } | |
67 // metadata is in the file {filename}.meta | |
68 String fn = getInput().getAbsolutePath(); | |
69 File mf = new File(fn + ".meta"); | |
70 if (mf.canRead()) { | |
71 XMLMetaLoader ml = new XMLMetaLoader(); | |
72 try { | |
73 // read meta file | |
74 Map<String, MetadataMap> meta = ml.loadURL(mf.getAbsolutePath()); | |
75 if (meta == null) { | |
76 return; | |
77 } | |
78 fileMeta = meta.get(getName()); | |
79 } catch (Exception e) { | |
80 Logger.getLogger(this.getClass()).warn("error reading file .meta", e); | |
81 } | |
82 } | |
83 } | |
84 | |
85 /* (non-Javadoc) | |
86 * @see digilib.io.DocuDirent#getName() | |
87 */ | |
88 public String getName() { | |
89 File f = getInput(); | |
90 return (f != null) ? f.getName() : null; | |
91 } | |
92 | |
93 /* (non-Javadoc) | |
94 * @see digilib.io.DocuDirent#getParent() | |
95 */ | |
96 public Directory getParent() { | |
97 return parent; | |
98 } | |
99 | |
100 /* (non-Javadoc) | |
101 * @see digilib.io.DocuDirent#setParent(digilib.io.Directory) | |
102 */ | |
103 public void setParent(Directory parent) { | |
104 this.parent = parent; | |
105 } | |
106 | |
107 /* (non-Javadoc) | |
108 * @see digilib.io.DocuDirent#getFileMeta() | |
109 */ | |
110 public MetadataMap getFileMeta() { | |
111 return fileMeta; | |
112 } | |
113 | |
114 /* (non-Javadoc) | |
115 * @see digilib.io.DocuDirent#setFileMeta(digilib.io.MetadataMap) | |
116 */ | |
117 public void setFileMeta(MetadataMap fileMeta) { | |
118 this.fileMeta = fileMeta; | |
119 } | |
120 | |
121 /* (non-Javadoc) | |
122 * @see digilib.io.DocuDirent#isMetaChecked() | |
123 */ | |
124 public boolean isMetaChecked() { | |
125 return metaChecked; | |
126 } | |
127 | |
128 /** | |
129 * @return | |
130 */ | |
131 public static FileClass getFileClass() { | |
132 return fileClass; | |
133 } | |
134 | |
135 /* (non-Javadoc) | |
136 * @see digilib.io.DocuDirent#compareTo(java.lang.Object) | |
137 */ | |
138 public int compareTo(Object arg0) { | |
139 if (arg0 instanceof DocuDirentImpl) { | |
140 return getName().compareTo(((DocuDirent) arg0).getName()); | |
141 } else { | |
142 return getName().compareTo((String) arg0); | |
143 } | |
144 } | |
145 | |
146 | |
147 } |