Mercurial > hg > digilib-old
annotate common/src/main/java/digilib/io/ImageFileSet.java @ 1156:4f84a635a820
read metadata from page1.jpg.meta also without file-tag.
author | robcast |
---|---|
date | Tue, 19 Feb 2013 17:25:57 +0100 |
parents | 7779b37d1d05 |
children |
rev | line source |
---|---|
576
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
1 /** |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
2 * |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
3 */ |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
4 package digilib.io; |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
5 |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
6 import java.io.File; |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
7 import java.util.ArrayList; |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
8 import java.util.Arrays; |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
9 import java.util.Map; |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
10 |
582 | 11 import org.apache.log4j.Logger; |
12 | |
576
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
13 import digilib.io.FileOps.FileClass; |
590 | 14 import digilib.meta.MetadataMap; |
15 import digilib.meta.XMLMetaLoader; | |
576
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
16 |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
17 /** |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
18 * @author casties |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
19 * |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
20 */ |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
21 public class ImageFileSet extends ImageSet implements DocuDirent { |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
22 |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
23 /** this is an image file */ |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
24 protected static FileClass fileClass = FileClass.IMAGE; |
582 | 25 /** the (main) file */ |
26 protected File file = null; | |
581 | 27 /** the file name */ |
582 | 28 protected String name = null; |
581 | 29 /** HashMap with metadata */ |
30 protected MetadataMap fileMeta = null; | |
31 /** Is the Metadata valid */ | |
32 protected boolean metaChecked = false; | |
33 /** the parent directory */ | |
583 | 34 protected Directory parentDir = null; |
576
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
35 |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
36 /** |
583 | 37 * Constructor with a File and Directories. |
576
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
38 * |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
39 * @param file |
583 | 40 * @param scaleDirs |
576
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
41 */ |
583 | 42 public ImageFileSet(File file, Directory[] scaleDirs) { |
43 int nb = scaleDirs.length; | |
576
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
44 list = new ArrayList<ImageInput>(nb); |
583 | 45 // first dir is our parent |
46 parentDir = scaleDirs[0]; | |
582 | 47 this.file = file; |
48 this.name = file.getName(); | |
583 | 49 fill(scaleDirs, file); |
576
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
50 } |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
51 |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
52 /* (non-Javadoc) |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
53 * @see digilib.io.DocuDirent#getName() |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
54 */ |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
55 public String getName() { |
582 | 56 return this.name; |
576
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
57 } |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
58 |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
59 /* (non-Javadoc) |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
60 * @see digilib.io.DocuDirent#getParent() |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
61 */ |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
62 public Directory getParent() { |
583 | 63 return this.parentDir; |
576
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
64 } |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
65 |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
66 /* (non-Javadoc) |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
67 * @see digilib.io.DocuDirent#setParent(digilib.io.Directory) |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
68 */ |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
69 public void setParent(Directory parent) { |
583 | 70 this.parentDir = parent; |
576
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
71 } |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
72 |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
73 /* (non-Javadoc) |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
74 * @see digilib.io.DocuDirent#getFileMeta() |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
75 */ |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
76 public MetadataMap getFileMeta() { |
582 | 77 return this.fileMeta; |
576
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
78 } |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
79 |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
80 /* (non-Javadoc) |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
81 * @see digilib.io.DocuDirent#setFileMeta(digilib.io.MetadataMap) |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
82 */ |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
83 public void setFileMeta(MetadataMap fileMeta) { |
582 | 84 this.fileMeta = fileMeta; |
576
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
85 } |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
86 |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
87 /* (non-Javadoc) |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
88 * @see digilib.io.DocuDirent#isMetaChecked() |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
89 */ |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
90 public boolean isMetaChecked() { |
582 | 91 return this.metaChecked; |
576
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
92 } |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
93 |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
94 /* (non-Javadoc) |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
95 * @see digilib.io.DocuDirent#compareTo(java.lang.Object) |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
96 */ |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
97 public int compareTo(Object arg0) { |
582 | 98 if (arg0 instanceof DocuDirent) { |
99 return name.compareTo(((DocuDirent) arg0).getName()); | |
100 } else { | |
101 return getName().compareTo((String) arg0); | |
102 } | |
576
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
103 } |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
104 |
582 | 105 /* (non-Javadoc) |
106 * @see digilib.io.DocuDirent#getFile() | |
107 */ | |
108 public File getFile() { | |
109 return file; | |
576
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
110 } |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
111 |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
112 /** |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
113 * Adds an ImageFile to this Fileset. |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
114 * |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
115 * The files should be added in the order of higher to lower resolutions. |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
116 * The first file is considered the hires "original". |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
117 * |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
118 * |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
119 * @param f |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
120 * file to add |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
121 * @return true (always) |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
122 */ |
588 | 123 public boolean add(ImageInput f) { |
576
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
124 f.setParent(this); |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
125 return list.add(f); |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
126 } |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
127 |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
128 /** |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
129 * Fill the ImageSet with files from different base directories. |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
130 * |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
131 * |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
132 * @param dirs |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
133 * list of base directories |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
134 * @param fl |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
135 * file (from first base dir) |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
136 * @param hints |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
137 * |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
138 */ |
582 | 139 void fill(Directory[] dirs, File fl) { |
576
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
140 String fn = fl.getName(); |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
141 String baseFn = FileOps.basename(fn); |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
142 // add the first ImageFile to the ImageSet |
583 | 143 add(new ImageFile(fl, this, parentDir)); |
576
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
144 // iterate the remaining base directories |
585 | 145 for (int i = 1; i < dirs.length; ++i) { |
146 Directory dir = dirs[i]; | |
583 | 147 if (dir == null) { |
576
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
148 continue; |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
149 } |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
150 // read the directory |
583 | 151 if (dir.getFilenames() == null) { |
152 dir.readDir(); | |
576
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
153 } |
583 | 154 String[] dirFiles = dir.getFilenames(); |
576
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
155 // try the same filename as the original |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
156 int fileIdx = Arrays.binarySearch(dirFiles, fn); |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
157 if (fileIdx < 0) { |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
158 // try closest matches without extension |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
159 fileIdx = -fileIdx - 1; |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
160 // try idx |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
161 if ((fileIdx < dirFiles.length) |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
162 && (FileOps.basename(dirFiles[fileIdx]).equals(baseFn))) { |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
163 // idx ok |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
164 } else if ((fileIdx > 0) |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
165 && (FileOps.basename(dirFiles[fileIdx - 1]) |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
166 .equals(baseFn))) { |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
167 // idx-1 ok |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
168 fileIdx = fileIdx - 1; |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
169 } else if ((fileIdx+1 < dirFiles.length) |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
170 && (FileOps.basename(dirFiles[fileIdx + 1]) |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
171 .equals(baseFn))) { |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
172 // idx+1 ok |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
173 fileIdx = fileIdx + 1; |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
174 } else { |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
175 // basename doesn't match |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
176 continue; |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
177 } |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
178 } |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
179 if (FileOps.classForFilename(dirFiles[fileIdx]) == fileClass) { |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
180 /* logger.debug("adding file " + dirFiles[fileIdx] |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
181 + " to Fileset " + this.getName()); */ |
583 | 182 add(new ImageFile(dirFiles[fileIdx], this, dir)); |
576
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
183 } |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
184 } |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
185 } |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
186 |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
187 /** |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
188 * Checks metadata and sets resolution in resX and resY. |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
189 * |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
190 */ |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
191 public void checkMeta() { |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
192 if (metaChecked) { |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
193 return; |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
194 } |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
195 if (fileMeta == null) { |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
196 // try to read metadata file |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
197 readMeta(); |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
198 if (fileMeta == null) { |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
199 // try directory metadata |
583 | 200 ((DocuDirectory) parentDir).checkMeta(); |
201 if (((DocuDirectory) parentDir).getDirMeta() != null) { | |
202 fileMeta = ((DocuDirectory) parentDir).getDirMeta(); | |
576
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
203 } else { |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
204 // try parent directory metadata |
583 | 205 DocuDirectory gp = (DocuDirectory) parentDir.getParent(); |
576
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
206 if (gp != null) { |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
207 gp.checkMeta(); |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
208 if (gp.getDirMeta() != null) { |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
209 fileMeta = gp.getDirMeta(); |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
210 } |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
211 } |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
212 } |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
213 } |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
214 } |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
215 if (fileMeta == null) { |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
216 // no metadata available |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
217 metaChecked = true; |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
218 return; |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
219 } |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
220 metaChecked = true; |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
221 float dpi = 0; |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
222 float dpix = 0; |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
223 float dpiy = 0; |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
224 float sizex = 0; |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
225 float sizey = 0; |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
226 float pixx = 0; |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
227 float pixy = 0; |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
228 // DPI is valid for X and Y |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
229 if (fileMeta.containsKey("original-dpi")) { |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
230 try { |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
231 dpi = Float.parseFloat((String) fileMeta.get("original-dpi")); |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
232 } catch (NumberFormatException e) { |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
233 } |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
234 if (dpi != 0) { |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
235 resX = dpi; |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
236 resY = dpi; |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
237 return; |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
238 } |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
239 } |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
240 // DPI-X and DPI-Y |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
241 if (fileMeta.containsKey("original-dpi-x") |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
242 && fileMeta.containsKey("original-dpi-y")) { |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
243 try { |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
244 dpix = Float.parseFloat((String) fileMeta |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
245 .get("original-dpi-x")); |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
246 dpiy = Float.parseFloat((String) fileMeta |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
247 .get("original-dpi-y")); |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
248 } catch (NumberFormatException e) { |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
249 } |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
250 if ((dpix != 0) && (dpiy != 0)) { |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
251 resX = dpix; |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
252 resY = dpiy; |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
253 return; |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
254 } |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
255 } |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
256 // SIZE-X and SIZE-Y and PIXEL-X and PIXEL-Y |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
257 if (fileMeta.containsKey("original-size-x") |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
258 && fileMeta.containsKey("original-size-y") |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
259 && fileMeta.containsKey("original-pixel-x") |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
260 && fileMeta.containsKey("original-pixel-y")) { |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
261 try { |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
262 sizex = Float.parseFloat((String) fileMeta |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
263 .get("original-size-x")); |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
264 sizey = Float.parseFloat((String) fileMeta |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
265 .get("original-size-y")); |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
266 pixx = Float.parseFloat((String) fileMeta |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
267 .get("original-pixel-x")); |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
268 pixy = Float.parseFloat((String) fileMeta |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
269 .get("original-pixel-y")); |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
270 } catch (NumberFormatException e) { |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
271 } |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
272 if ((sizex != 0) && (sizey != 0) && (pixx != 0) && (pixy != 0)) { |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
273 resX = pixx / (sizex * 100 / 2.54f); |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
274 resY = pixy / (sizey * 100 / 2.54f); |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
275 return; |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
276 } |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
277 } |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
278 } |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
279 |
582 | 280 /* (non-Javadoc) |
281 * @see digilib.io.DocuDirent#readMeta() | |
282 */ | |
283 public void readMeta() { | |
284 if ((fileMeta != null) || (file == null)) { | |
285 // there is already metadata or there is no file | |
286 return; | |
287 } | |
288 // metadata is in the file {filename}.meta | |
289 String fn = file.getAbsolutePath(); | |
290 File mf = new File(fn + ".meta"); | |
291 if (mf.canRead()) { | |
292 XMLMetaLoader ml = new XMLMetaLoader(); | |
293 try { | |
294 // read meta file | |
295 Map<String, MetadataMap> meta = ml.loadURL(mf.getAbsolutePath()); | |
296 if (meta == null) { | |
297 return; | |
298 } | |
1156
4f84a635a820
read metadata from page1.jpg.meta also without file-tag.
robcast
parents:
903
diff
changeset
|
299 // file meta should be inside file tag |
582 | 300 fileMeta = meta.get(name); |
1156
4f84a635a820
read metadata from page1.jpg.meta also without file-tag.
robcast
parents:
903
diff
changeset
|
301 if (fileMeta == null) { |
4f84a635a820
read metadata from page1.jpg.meta also without file-tag.
robcast
parents:
903
diff
changeset
|
302 // or there is only a meta tag |
4f84a635a820
read metadata from page1.jpg.meta also without file-tag.
robcast
parents:
903
diff
changeset
|
303 fileMeta = meta.get(""); |
4f84a635a820
read metadata from page1.jpg.meta also without file-tag.
robcast
parents:
903
diff
changeset
|
304 } |
582 | 305 } catch (Exception e) { |
306 Logger.getLogger(this.getClass()).warn("error reading file .meta", e); | |
307 } | |
308 } | |
309 } | |
310 | |
576
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
311 |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
diff
changeset
|
312 } |