1 16 package org.apache.cocoon.generation; 17 18 import java.io.File ; 19 import java.io.FileNotFoundException ; 20 import java.io.IOException ; 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 ; 27 28 47 final public class ImageDirectoryGenerator extends DirectoryGenerator { 48 49 protected final static String IMAGE_WIDTH_ATTR_NAME = "width"; 50 protected final static String IMAGE_HEIGHT_ATTR_NAME = "height"; 51 protected final static String IMAGE_COMMENT_ATTR_NAME = "comment"; 52 53 58 protected void setNodeAttributes(File path) throws SAXException { 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 (e); 76 } 77 catch (FileNotFoundException e) { 78 throw new SAXException (e); 79 } 80 catch (IOException e) { 81 throw new SAXException (e); 82 } 83 } 84 85 } 86 | Popular Tags |