1 29 30 package nextapp.echo2.app.componentxml.propertypeer; 31 32 import org.w3c.dom.Element ; 33 34 import nextapp.echo2.app.Extent; 35 import nextapp.echo2.app.ResourceImageReference; 36 import nextapp.echo2.app.componentxml.InvalidPropertyException; 37 import nextapp.echo2.app.componentxml.PropertyXmlPeer; 38 import nextapp.echo2.app.util.DomUtil; 39 40 44 public class ResourceImageReferencePeer 45 implements PropertyXmlPeer { 46 47 51 public Object getValue(ClassLoader classLoader, Class objectClass, Element propertyElement) 52 throws InvalidPropertyException { 53 if (propertyElement.hasAttribute("value")) { 54 return new ResourceImageReference(propertyElement.getAttribute("value")); 55 } else { 56 Element resourceImageReferenceElement = DomUtil.getChildElementByTagName(propertyElement, 57 "resource-image-reference"); 58 if (!resourceImageReferenceElement.hasAttribute("resource")) { 59 throw new InvalidPropertyException("Invalid ResourceImageReference property (resource not specified).", null); 60 } 61 String resource = resourceImageReferenceElement.getAttribute("resource"); 62 String contentType = null; 63 if (resourceImageReferenceElement.hasAttribute("content-type")) { 64 contentType = resourceImageReferenceElement.getAttribute("content-type"); 65 } 66 Extent width = null; 67 if (resourceImageReferenceElement.hasAttribute("width")) { 68 width = ExtentPeer.toExtent(resourceImageReferenceElement.getAttribute("width")); 69 } 70 Extent height = null; 71 if (resourceImageReferenceElement.hasAttribute("height")) { 72 height = ExtentPeer.toExtent(resourceImageReferenceElement.getAttribute("height")); 73 } 74 return new ResourceImageReference(resource, contentType, width, height); 75 } 76 } 77 } 78 | Popular Tags |