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