1 16 package org.apache.commons.jelly.impl; 17 18 import org.apache.commons.jelly.DynaTagSupport; 19 import org.apache.commons.jelly.JellyTagException; 20 import org.apache.commons.jelly.XMLOutput; 21 22 import org.xml.sax.SAXException ; 23 import org.xml.sax.helpers.AttributesImpl ; 24 25 32 33 public class StaticTag extends DynaTagSupport { 34 35 36 private String uri; 37 38 39 private String qname; 40 41 42 private String localName; 43 44 45 private AttributesImpl attributes = new AttributesImpl (); 46 47 public StaticTag() { 48 } 49 50 public StaticTag(String uri, String localName, String qname) { 51 this.uri = uri; 52 this.localName = localName; 53 this.qname = qname; 54 } 55 56 public String toString() { 57 return super.toString() + "[qname=" + qname + ";attributes=" + attributes + "]"; 58 } 59 60 public void doTag(XMLOutput output) throws JellyTagException { 63 try { 64 output.startElement(uri, localName, qname, attributes); 65 invokeBody(output); 66 output.endElement(uri, localName, qname); 67 } catch (SAXException e) { 68 throw new JellyTagException(e); 69 } finally { 70 attributes.clear(); 71 } 72 } 73 74 public void setAttribute(String name, String prefix, String nsURI, Object value) { 75 if(value==null) 76 return; 77 if(prefix!=null && prefix.length()>0) 78 attributes.addAttribute(nsURI,name,prefix+":"+name,"CDATA",value.toString()); 79 else 80 attributes.addAttribute("",name,name,"CDATA",value.toString()); 81 } 82 83 public void setAttribute(String name, Object value) throws JellyTagException { 86 int index = attributes.getIndex("", name); 90 if (index >= 0) { 91 attributes.removeAttribute(index); 92 } 93 if (value != null) { 95 attributes.addAttribute("", name, name, "CDATA", value.toString()); 96 } 97 } 98 99 public String getUri() { 102 return uri; 103 } 104 105 public void setUri(String uri) { 106 this.uri = uri; 107 } 108 109 public String getQName() { 110 return qname; 111 } 112 113 public void setQName(String qname) { 114 this.qname = qname; 115 int idx = qname.indexOf(':'); 116 if (idx >= 0) { 117 this.localName = qname.substring(idx + 1); 118 } 119 else { 120 this.localName = qname; 121 } 122 } 123 124 public String getLocalName() { 125 return localName; 126 } 127 128 public void setLocalName(String localName) { 129 this.localName = localName; 130 if (qname == null || !qname.endsWith(localName)) { 132 localName = qname; 133 } 134 } 135 } 136 | Popular Tags |