1 16 package org.apache.cocoon.faces.taglib; 17 18 import org.apache.cocoon.taglib.TagSupport; 19 20 import org.apache.cocoon.faces.FacesUtils; 21 import org.xml.sax.Attributes ; 22 import org.xml.sax.SAXException ; 23 24 import javax.faces.component.UIComponent; 25 26 29 public class AttributeTag extends TagSupport { 30 31 private String name; 32 private String value; 33 34 public void setName(String name) { 35 this.name = name; 36 } 37 38 public void setValue(String value) { 39 this.value = value; 40 } 41 42 public int doStartTag(String namespaceURI, String localName, String qName, Attributes atts) 43 throws SAXException { 44 UIComponentTag tag = FacesUtils.findParentUIComponentTag(this); 45 if (tag == null) { 46 throw new SAXException ("Tag <" + getClass().getName() + "> have to be nested within a UIComponentTag"); 47 } 48 49 UIComponent component = tag.getComponentInstance(); 50 if (component == null) { 51 throw new SAXException ("Parent tag <" + tag.getClass(). getName() + "> has no component instance"); 52 } 53 54 String nameVal = (String ) tag.evaluate(name); 55 Object valueVal = tag.evaluate(value); 56 if (component.getAttributes().get(nameVal) == null) { 57 component.getAttributes().put(nameVal, valueVal); 58 } 59 60 return SKIP_BODY; 61 } 62 63 public void recycle() { 64 super.recycle(); 65 this.name = null; 66 this.value = null; 67 } 68 } 69 | Popular Tags |