Mercurial > hg > digilib-old
comparison servlet/src/main/java/digilib/io/DocuDirentImpl.java @ 892:ba1eb2d821a2 mvnify
rearrange sources to maven directory standard
author | robcast |
---|---|
date | Tue, 19 Apr 2011 18:44:25 +0200 |
parents | servlet/src/digilib/io/DocuDirentImpl.java@69bc69381ac4 |
children |
comparison
equal
deleted
inserted
replaced
891:6584af320296 | 892:ba1eb2d821a2 |
---|---|
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 import digilib.meta.MetadataMap; | |
32 import digilib.meta.XMLMetaLoader; | |
33 | |
34 /** | |
35 * Abstract directory entry in a DocuDirectory. | |
36 * | |
37 * @author casties | |
38 * | |
39 */ | |
40 public abstract class DocuDirentImpl implements DocuDirent { | |
41 | |
42 /** the file class of this file */ | |
43 protected static FileClass fileClass = FileClass.NONE; | |
44 /** HashMap with metadata */ | |
45 protected MetadataMap fileMeta = null; | |
46 /** Is the Metadata valid */ | |
47 protected boolean metaChecked = false; | |
48 /** the parent directory */ | |
49 protected Directory parent = null; | |
50 | |
51 /* (non-Javadoc) | |
52 * @see digilib.io.DocuDirent#checkMeta() | |
53 */ | |
54 public abstract void checkMeta(); | |
55 | |
56 /* (non-Javadoc) | |
57 * @see digilib.io.DocuDirent#getInput() | |
58 */ | |
59 public abstract File getFile(); | |
60 | |
61 /* (non-Javadoc) | |
62 * @see digilib.io.DocuDirent#readMeta() | |
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 Map<String, MetadataMap> meta = ml.loadURL(mf.getAbsolutePath()); | |
77 if (meta == null) { | |
78 return; | |
79 } | |
80 fileMeta = meta.get(getName()); | |
81 } catch (Exception e) { | |
82 Logger.getLogger(this.getClass()).warn("error reading file .meta", e); | |
83 } | |
84 } | |
85 } | |
86 | |
87 /* (non-Javadoc) | |
88 * @see digilib.io.DocuDirent#getName() | |
89 */ | |
90 public String getName() { | |
91 File f = getFile(); | |
92 return (f != null) ? f.getName() : null; | |
93 } | |
94 | |
95 /* (non-Javadoc) | |
96 * @see digilib.io.DocuDirent#getParent() | |
97 */ | |
98 public Directory getParent() { | |
99 return parent; | |
100 } | |
101 | |
102 /* (non-Javadoc) | |
103 * @see digilib.io.DocuDirent#setParent(digilib.io.Directory) | |
104 */ | |
105 public void setParent(Directory parent) { | |
106 this.parent = parent; | |
107 } | |
108 | |
109 /* (non-Javadoc) | |
110 * @see digilib.io.DocuDirent#getFileMeta() | |
111 */ | |
112 public MetadataMap getFileMeta() { | |
113 return fileMeta; | |
114 } | |
115 | |
116 /* (non-Javadoc) | |
117 * @see digilib.io.DocuDirent#setFileMeta(digilib.io.MetadataMap) | |
118 */ | |
119 public void setFileMeta(MetadataMap fileMeta) { | |
120 this.fileMeta = fileMeta; | |
121 } | |
122 | |
123 /* (non-Javadoc) | |
124 * @see digilib.io.DocuDirent#isMetaChecked() | |
125 */ | |
126 public boolean isMetaChecked() { | |
127 return metaChecked; | |
128 } | |
129 | |
130 /** | |
131 * @return | |
132 */ | |
133 public static FileClass getFileClass() { | |
134 return fileClass; | |
135 } | |
136 | |
137 /* (non-Javadoc) | |
138 * @see digilib.io.DocuDirent#compareTo(java.lang.Object) | |
139 */ | |
140 public int compareTo(Object arg0) { | |
141 if (arg0 instanceof DocuDirentImpl) { | |
142 return getName().compareTo(((DocuDirent) arg0).getName()); | |
143 } else { | |
144 return getName().compareTo((String) arg0); | |
145 } | |
146 } | |
147 | |
148 | |
149 } |