Mercurial > hg > digilib-old
comparison servlet/src/digilib/io/ImageFileset.java @ 233:e40d8b2e3978
Servlet version 1.19b1 -- with context metadata
- reads and caches context tags from index meta file
- for use in dlContext-xml.jsp
author | robcast |
---|---|
date | Sat, 17 Jul 2004 19:25:26 +0200 |
parents | afe7ff98bb71 |
children | beed92ee6022 |
comparison
equal
deleted
inserted
replaced
232:69b616b50431 | 233:e40d8b2e3978 |
---|---|
34 /** this is an image file */ | 34 /** this is an image file */ |
35 protected static int fileClass = FileOps.CLASS_IMAGE; | 35 protected static int fileClass = FileOps.CLASS_IMAGE; |
36 | 36 |
37 /** list of files (ImageFile) */ | 37 /** list of files (ImageFile) */ |
38 private ArrayList list = null; | 38 private ArrayList list = null; |
39 | |
39 /** aspect ratio (width/height) */ | 40 /** aspect ratio (width/height) */ |
40 private double aspect = 0; | 41 private double aspect = 0; |
42 | |
41 /** resolution of the biggest image (DPI) */ | 43 /** resolution of the biggest image (DPI) */ |
42 private double resX = 0; | 44 private double resX = 0; |
45 | |
43 /** resolution of the biggest image (DPI) */ | 46 /** resolution of the biggest image (DPI) */ |
44 private double resY = 0; | 47 private double resY = 0; |
45 | 48 |
46 /** | 49 /** |
47 * Creator for empty fileset with size for file list. | 50 * Creator for empty fileset with size for file list. |
60 * other base directories. First entry in dirs is the parent of this | 63 * other base directories. First entry in dirs is the parent of this |
61 * fileset. | 64 * fileset. |
62 * | 65 * |
63 * | 66 * |
64 * @see fill | 67 * @see fill |
65 * | 68 * |
66 * @param dirs | 69 * @param dirs |
67 * array of base directories | 70 * array of base directories |
68 * @param file | 71 * @param file |
69 * first file to read | 72 * first file to read |
70 * @param scalext | 73 * @param scalext |
71 * extension for scaled images | 74 * extension for scaled images |
72 */ | 75 */ |
73 public ImageFileset(Directory[] dirs, File file, String scalext) { | 76 public ImageFileset(Directory[] dirs, File file, String scalext) { |
74 int nb = dirs.length; | 77 int nb = dirs.length; |
75 list = new ArrayList(nb); | 78 list = new ArrayList(nb); |
76 parent = dirs[0]; | 79 parent = dirs[0]; |
83 * The files should be added in the order of higher to lower resolutions. | 86 * The files should be added in the order of higher to lower resolutions. |
84 * The first file is considered the hires "original". | 87 * The first file is considered the hires "original". |
85 * | 88 * |
86 * | 89 * |
87 * @param f | 90 * @param f |
88 * file to add | 91 * file to add |
89 * @return true (always) | 92 * @return true (always) |
90 */ | 93 */ |
91 public boolean add(ImageFile f) { | 94 public boolean add(ImageFile f) { |
92 f.setParent(this); | 95 f.setParent(this); |
93 return list.add(f); | 96 return list.add(f); |
123 } | 126 } |
124 | 127 |
125 /** | 128 /** |
126 * Get the next smaller ImageFile than the given size. | 129 * Get the next smaller ImageFile than the given size. |
127 * | 130 * |
128 * Returns the ImageFile from the set that has a width and height smaller | 131 * Returns the ImageFile from the set that has a width and height smaller or |
129 * or equal the given size. Returns null if there isn't any smaller image. | 132 * equal the given size. Returns null if there isn't any smaller image. |
130 * Needs DocuInfo instance to checkFile(). | 133 * Needs DocuInfo instance to checkFile(). |
131 * | 134 * |
132 * | 135 * |
133 * @param size | 136 * @param size |
134 * @param info | 137 * @param info |
152 | 155 |
153 /** | 156 /** |
154 * Get the next bigger ImageFile than the given size. | 157 * Get the next bigger ImageFile than the given size. |
155 * | 158 * |
156 * Returns the ImageFile from the set that has a width or height bigger or | 159 * Returns the ImageFile from the set that has a width or height bigger or |
157 * equal the given size. Returns null if there isn't any bigger image. | 160 * equal the given size. Returns null if there isn't any bigger image. Needs |
158 * Needs DocuInfo instance to checkFile(). | 161 * DocuInfo instance to checkFile(). |
159 * | 162 * |
160 * | 163 * |
161 * @param size | 164 * @param size |
162 * @param info | 165 * @param info |
163 * @return | 166 * @return |
226 /** | 229 /** |
227 * Fill the ImageFileset with files from different base directories. | 230 * Fill the ImageFileset with files from different base directories. |
228 * | 231 * |
229 * | 232 * |
230 * @param dirs | 233 * @param dirs |
231 * list of base directories | 234 * list of base directories |
232 * @param fl | 235 * @param fl |
233 * file (from first base dir) | 236 * file (from first base dir) |
234 * @param scalext | 237 * @param scalext |
235 * first extension to try in other base dirs | 238 * first extension to try in other base dirs |
236 */ | 239 */ |
237 void fill(Directory[] dirs, File fl, String scalext) { | 240 void fill(Directory[] dirs, File fl, String scalext) { |
238 int nb = dirs.length; | 241 int nb = dirs.length; |
239 String fn = fl.getName(); | 242 String fn = fl.getName(); |
240 String fnx = fn.substring(0, fn.lastIndexOf('.') + 1); | 243 String fnx = fn.substring(0, fn.lastIndexOf('.') + 1); |
284 if (fileMeta == null) { | 287 if (fileMeta == null) { |
285 // try to read metadata file | 288 // try to read metadata file |
286 readMeta(); | 289 readMeta(); |
287 if (fileMeta == null) { | 290 if (fileMeta == null) { |
288 // try directory metadata | 291 // try directory metadata |
292 ((DocuDirectory) parent).checkMeta(); | |
289 if (((DocuDirectory) parent).getDirMeta() != null) { | 293 if (((DocuDirectory) parent).getDirMeta() != null) { |
290 fileMeta = ((DocuDirectory) parent).getDirMeta(); | 294 fileMeta = ((DocuDirectory) parent).getDirMeta(); |
291 } else { | 295 } else { |
292 // no metadata available | 296 // try parent directory metadata |
293 metaChecked = true; | 297 DocuDirectory gp = (DocuDirectory) parent.getParent(); |
294 return; | 298 if (gp != null) { |
299 gp.checkMeta(); | |
300 if (gp.getDirMeta() != null) { | |
301 fileMeta = gp.getDirMeta(); | |
302 } else { | |
303 // no metadata available | |
304 metaChecked = true; | |
305 return; | |
306 } | |
307 } | |
295 } | 308 } |
296 } | 309 } |
297 } | 310 } |
298 metaChecked = true; | 311 metaChecked = true; |
299 String s; | 312 String s; |
316 return; | 329 return; |
317 } | 330 } |
318 } | 331 } |
319 // DPI-X and DPI-Y | 332 // DPI-X and DPI-Y |
320 if (fileMeta.containsKey("original-dpi-x") | 333 if (fileMeta.containsKey("original-dpi-x") |
321 && fileMeta.containsKey("original-dpi-y")) { | 334 && fileMeta.containsKey("original-dpi-y")) { |
322 try { | 335 try { |
323 dpix = | 336 dpix = Double.parseDouble((String) fileMeta |
324 Double.parseDouble((String) fileMeta.get("original-dpi-x")); | 337 .get("original-dpi-x")); |
325 dpiy = | 338 dpiy = Double.parseDouble((String) fileMeta |
326 Double.parseDouble((String) fileMeta.get("original-dpi-y")); | 339 .get("original-dpi-y")); |
327 } catch (NumberFormatException e) { | 340 } catch (NumberFormatException e) { |
328 } | 341 } |
329 if ((dpix != 0) && (dpiy != 0)) { | 342 if ((dpix != 0) && (dpiy != 0)) { |
330 resX = dpix; | 343 resX = dpix; |
331 resY = dpiy; | 344 resY = dpiy; |
332 return; | 345 return; |
333 } | 346 } |
334 } | 347 } |
335 // SIZE-X and SIZE-Y and PIXEL-X and PIXEL-Y | 348 // SIZE-X and SIZE-Y and PIXEL-X and PIXEL-Y |
336 if (fileMeta.containsKey("original-size-x") | 349 if (fileMeta.containsKey("original-size-x") |
337 && fileMeta.containsKey("original-size-y") | 350 && fileMeta.containsKey("original-size-y") |
338 && fileMeta.containsKey("original-pixel-x") | 351 && fileMeta.containsKey("original-pixel-x") |
339 && fileMeta.containsKey("original-pixel-y")) { | 352 && fileMeta.containsKey("original-pixel-y")) { |
340 try { | 353 try { |
341 sizex = | 354 sizex = Double.parseDouble((String) fileMeta |
342 Double.parseDouble( | 355 .get("original-size-x")); |
343 (String) fileMeta.get("original-size-x")); | 356 sizey = Double.parseDouble((String) fileMeta |
344 sizey = | 357 .get("original-size-y")); |
345 Double.parseDouble( | 358 pixx = Double.parseDouble((String) fileMeta |
346 (String) fileMeta.get("original-size-y")); | 359 .get("original-pixel-x")); |
347 pixx = | 360 pixy = Double.parseDouble((String) fileMeta |
348 Double.parseDouble( | 361 .get("original-pixel-y")); |
349 (String) fileMeta.get("original-pixel-x")); | |
350 pixy = | |
351 Double.parseDouble( | |
352 (String) fileMeta.get("original-pixel-y")); | |
353 } catch (NumberFormatException e) { | 362 } catch (NumberFormatException e) { |
354 } | 363 } |
355 if ((sizex != 0) && (sizey != 0) && (pixx != 0) && (pixy != 0)) { | 364 if ((sizex != 0) && (sizey != 0) && (pixx != 0) && (pixy != 0)) { |
356 resX = pixx / (sizex * 100 / 2.54); | 365 resX = pixx / (sizex * 100 / 2.54); |
357 resY = pixy / (sizey * 100 / 2.54); | 366 resY = pixy / (sizey * 100 / 2.54); |
385 } | 394 } |
386 | 395 |
387 /** | 396 /** |
388 * Returns the aspect ratio. | 397 * Returns the aspect ratio. |
389 * | 398 * |
390 * Aspect ratio is (width/height). So it's <1 for portrait and >1 for | 399 * Aspect ratio is (width/height). So it's <1 for portrait and >1 for |
391 * landscape. | 400 * landscape. |
392 * | 401 * |
393 * | 402 * |
394 * @return | 403 * @return |
395 */ | 404 */ |