01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.generation;
18:
19: import java.io.File;
20: import java.io.FileNotFoundException;
21: import java.io.IOException;
22:
23: import org.apache.cocoon.util.FileFormatException;
24: import org.apache.cocoon.util.ImageProperties;
25: import org.apache.cocoon.util.ImageUtils;
26:
27: import org.xml.sax.SAXException;
28:
29: /**
30: * @cocoon.sitemap.component.documentation
31: * Generates an XML directory listing. This is an extension of
32: * the <link href="directory-generator.html">Directory Generator</link> that
33: * adds extra attributes for image files.
34: *
35: * @cocoon.sitemap.component.name imagedirectory
36: * @cocoon.sitemap.component.label content
37: * @cocoon.sitemap.component.logger sitemap.generator.imagedirectory
38: * @cocoon.sitemap.component.documentation.caching
39: * Uses the last modification date of the directory and the contained files
40: *
41: * @cocoon.sitemap.component.pooling.max 16
42: *
43: *
44: * @author <a href="mailto:balld@webslingerZ.com">Donald A. Ball Jr.</a>
45: * @author <a href="mailto:tcurdt@apache.org">Torsten Curdt</a>
46: * @version CVS $Id: ImageDirectoryGenerator.java 433543 2006-08-22 06:22:54Z crossley $
47: */
48: final public class ImageDirectoryGenerator extends DirectoryGenerator {
49:
50: protected final static String IMAGE_WIDTH_ATTR_NAME = "width";
51: protected final static String IMAGE_HEIGHT_ATTR_NAME = "height";
52: protected final static String IMAGE_COMMENT_ATTR_NAME = "comment";
53:
54: /**
55: * Extends the <code>setNodeAttributes</code> method from the
56: * <code>DirectoryGenerator</code> by adding width, height and comment attributes
57: * if the path is a GIF or a JPEG file.
58: */
59: protected void setNodeAttributes(File path) throws SAXException {
60: super .setNodeAttributes(path);
61: if (path.isDirectory()) {
62: return;
63: }
64: try {
65: ImageProperties p = ImageUtils.getImageProperties(path);
66: if (p != null) {
67: if (getLogger().isDebugEnabled()) {
68: getLogger().debug(
69: String.valueOf(path) + " = "
70: + String.valueOf(p));
71: }
72: attributes.addAttribute("", IMAGE_WIDTH_ATTR_NAME,
73: IMAGE_WIDTH_ATTR_NAME, "CDATA", String
74: .valueOf(p.width));
75: attributes.addAttribute("", IMAGE_HEIGHT_ATTR_NAME,
76: IMAGE_HEIGHT_ATTR_NAME, "CDATA", String
77: .valueOf(p.height));
78: if (p.comment != null)
79: attributes.addAttribute("",
80: IMAGE_COMMENT_ATTR_NAME,
81: IMAGE_COMMENT_ATTR_NAME, "CDATA", String
82: .valueOf(p.comment));
83: }
84: } catch (FileFormatException e) {
85: throw new SAXException(e);
86: } catch (FileNotFoundException e) {
87: throw new SAXException(e);
88: } catch (IOException e) {
89: throw new SAXException(e);
90: }
91: }
92:
93: }
|