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