1 28 29 package com.caucho.xml; 30 31 import org.w3c.dom.Attr ; 32 import org.w3c.dom.Element ; 33 import org.w3c.dom.Node ; 34 import org.w3c.dom.TypeInfo ; 35 36 import java.io.IOException ; 37 38 public class QAttr extends QNode implements Attr { 39 QName _name; 40 private String _value; 41 private boolean _specified = true; 42 43 public QAttr(String name) 44 { 45 _name = new QName(name); 46 } 47 48 public QAttr(QName name) 49 { 50 _name = name; 51 } 52 53 protected QAttr(QName name, String value) 54 { 55 _name = name; 56 _value = value; 57 } 58 59 protected QAttr(QDocument owner, QName name) 60 { 61 super(owner); 62 63 _name = name; 64 } 65 66 public Element getOwnerElement() 67 { 68 return (Element ) getParentNode(); 69 } 70 71 public short getNodeType() 72 { 73 return ATTRIBUTE_NODE; 74 } 75 76 79 public QName getQName() 80 { 81 return _name; 82 } 83 84 public String getNodeName() 85 { 86 return _name.getName(); 87 } 88 89 public boolean isId() 90 { 91 return false; 92 } 93 94 public String getName() 95 { 96 return _name.getName(); 97 } 98 99 public String getPrefix() 100 { 101 return _name.getPrefix(); 102 } 103 104 public String getLocalName() 105 { 106 return _name.getLocalName(); 107 } 108 109 public String getCanonicalName() 110 { 111 return _name.getCanonicalName(); 112 } 113 114 public String getNamespaceURI() 115 { 116 return _name.getNamespace(); 117 } 118 119 public String getNodeValue() 120 { 121 return _value; 122 } 123 124 public TypeInfo getSchemaTypeInfo() 125 { 126 return null; 127 } 128 129 public void setNodeValue(String value) 130 { 131 _value = value; 132 } 133 134 public String getValue() 135 { 136 return _value; 137 } 138 139 public void setValue(String value) 140 { 141 _value = value; 142 } 143 144 public boolean getSpecified() 145 { 146 return _specified; 147 } 148 149 public void setSpecified(boolean specified) 150 { 151 _specified = specified; 152 } 153 154 Node importNode(QDocument owner, boolean deep) 155 { 156 QNode node = new QAttr(_name, _value); 157 node._owner = owner; 158 return node; 159 } 160 161 public void print(XmlPrinter out) throws IOException 162 { 163 if (! _specified) 164 return; 165 166 out.attribute(getNamespaceURI(), getLocalName(), 167 getNodeName(), getNodeValue()); 168 } 169 170 private Object writeReplace() 171 { 172 return new SerializedXml(this); 173 } 174 175 public String toString() 176 { 177 if (_value != null) 178 return "Attr[" + _name + " " + _value + "]"; 179 else 180 return "Attr[" + _name + "]"; 181 } 182 } 183 | Popular Tags |