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