KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > generation > ImageDirectoryGenerator


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.generation;
17
18 import java.io.File JavaDoc;
19 import java.io.FileNotFoundException JavaDoc;
20 import java.io.IOException JavaDoc;
21
22 import org.apache.cocoon.util.FileFormatException;
23 import org.apache.cocoon.util.ImageProperties;
24 import org.apache.cocoon.util.ImageUtils;
25
26 import org.xml.sax.SAXException JavaDoc;
27
28 /**
29  * @cocoon.sitemap.component.documentation
30  * Generates an XML directory listing. This is an extension of
31  * the <link HREF="directory-generator.html">Directory Generator</link> that
32  * adds extra attributes for image files.
33  *
34  * @cocoon.sitemap.component.name imagedirectory
35  * @cocoon.sitemap.component.label content
36  * @cocoon.sitemap.component.logger sitemap.generator.imagedirectory
37  * @cocoon.sitemap.component.documentation.caching
38  * Uses the last modification date of the directory and the contained files
39  *
40  * @cocoon.sitemap.component.pooling.max 16
41  *
42  *
43  * @author <a HREF="mailto:balld@webslingerZ.com">Donald A. Ball Jr.</a>
44  * @author <a HREF="mailto:tcurdt@apache.org">Torsten Curdt</a>
45  * @version CVS $Id: ImageDirectoryGenerator.java 153376 2005-02-11 08:50:21Z cziegeler $
46  */

47 final public class ImageDirectoryGenerator extends DirectoryGenerator {
48
49     protected final static String JavaDoc IMAGE_WIDTH_ATTR_NAME = "width";
50     protected final static String JavaDoc IMAGE_HEIGHT_ATTR_NAME = "height";
51     protected final static String JavaDoc IMAGE_COMMENT_ATTR_NAME = "comment";
52
53     /**
54      * Extends the <code>setNodeAttributes</code> method from the
55      * <code>DirectoryGenerator</code> by adding width, height and comment attributes
56      * if the path is a GIF or a JPEG file.
57      */

58     protected void setNodeAttributes(File JavaDoc path) throws SAXException JavaDoc {
59         super.setNodeAttributes(path);
60         if (path.isDirectory()) {
61             return;
62         }
63         try {
64             ImageProperties p = ImageUtils.getImageProperties(path);
65             if (p != null) {
66                 if (getLogger().isDebugEnabled()) {
67                     getLogger().debug(String.valueOf(path) + " = " + String.valueOf(p));
68                 }
69                 attributes.addAttribute("", IMAGE_WIDTH_ATTR_NAME, IMAGE_WIDTH_ATTR_NAME, "CDATA", String.valueOf(p.width));
70                 attributes.addAttribute("", IMAGE_HEIGHT_ATTR_NAME, IMAGE_HEIGHT_ATTR_NAME, "CDATA", String.valueOf(p.height));
71                 if (p.comment != null) attributes.addAttribute("", IMAGE_COMMENT_ATTR_NAME, IMAGE_COMMENT_ATTR_NAME, "CDATA", String.valueOf(p.comment));
72             }
73         }
74         catch (FileFormatException e) {
75             throw new SAXException JavaDoc(e);
76         }
77         catch (FileNotFoundException JavaDoc e) {
78             throw new SAXException JavaDoc(e);
79         }
80         catch (IOException JavaDoc e) {
81             throw new SAXException JavaDoc(e);
82         }
83     }
84
85 }
86
Popular Tags