1 2 58 59 package org.enhydra.apache.xerces.dom; 60 61 import org.w3c.dom.DOMException ; 62 63 73 public class AttrNSImpl 74 extends AttrImpl { 75 76 80 81 static final long serialVersionUID = -781906615369795414L; 82 static final String xmlnsURI = "http://www.w3.org/2000/xmlns/"; 83 static final String xmlURI = "http://www.w3.org/XML/1998/namespace"; 84 85 89 90 protected String namespaceURI; 91 92 93 protected String localName; 94 97 protected AttrNSImpl(CoreDocumentImpl ownerDocument, 98 String namespaceURI, 99 String qualifiedName) { 100 101 super(ownerDocument, qualifiedName); 102 103 int index = qualifiedName.indexOf(':'); 104 String prefix; 105 if (index < 0) { 106 prefix = null; 107 localName = qualifiedName; 108 109 if (ownerDocument.errorChecking && 110 qualifiedName.equals("xmlns") && 111 (namespaceURI == null || !namespaceURI.equals(xmlnsURI))) { 112 113 throw new DOMException (DOMException.NAMESPACE_ERR, 114 "DOM003 Namespace error"); 115 } 116 } 117 else { 118 prefix = qualifiedName.substring(0, index); 119 localName = qualifiedName.substring(index+1); 120 121 if (ownerDocument.errorChecking) { 122 if (namespaceURI == null 123 || (localName.length() == 0) 124 || (localName.indexOf(':') >= 0)) { 125 throw new DOMException (DOMException.NAMESPACE_ERR, 126 "DOM003 Namespace error"); 127 } else if (prefix.equals("xml")) { 128 if (!namespaceURI.equals(xmlURI)) { 129 throw new DOMException (DOMException.NAMESPACE_ERR, 130 "DOM003 Namespace error"); 131 } 132 } else if (prefix.equals("xmlns")) { 133 if (!namespaceURI.equals(xmlnsURI)) { 134 throw new DOMException (DOMException.NAMESPACE_ERR, 135 "DOM003 Namespace error"); 136 } 137 } else if (index == 0) { 138 throw new DOMException (DOMException.NAMESPACE_ERR, 139 "DOM003 Namespace error"); 140 } 141 } 142 } 143 this.namespaceURI = namespaceURI; 144 } 145 146 protected AttrNSImpl(CoreDocumentImpl ownerDocument, 148 String value) { 149 super(ownerDocument, value); 150 } 151 152 156 169 public String getNamespaceURI() 170 { 171 if (needsSyncData()) { 172 synchronizeData(); 173 } 174 return namespaceURI; 178 } 179 180 190 public String getPrefix() 191 { 192 if (needsSyncData()) { 193 synchronizeData(); 194 } 195 int index = name.indexOf(':'); 196 return index < 0 ? null : name.substring(0, index); 197 } 198 199 211 public void setPrefix(String prefix) 212 throws DOMException 213 { 214 if (needsSyncData()) { 215 synchronizeData(); 216 } 217 if (ownerDocument().errorChecking) { 218 if (isReadOnly()) { 219 throw new DOMException ( 220 DOMException.NO_MODIFICATION_ALLOWED_ERR, 221 "DOM001 Modification not allowed"); 222 } 223 if (!CoreDocumentImpl.isXMLName(prefix)) { 224 throw new DOMException (DOMException.INVALID_CHARACTER_ERR, 225 "DOM002 Illegal character"); 226 } 227 if (namespaceURI == null || prefix.indexOf(':') >=0) { 228 throw new DOMException (DOMException.NAMESPACE_ERR, 229 "DOM003 Namespace error"); 230 } else if (prefix != null) { 231 if (prefix.equals("xmlns")) { 232 if (!namespaceURI.equals(xmlnsURI)){ 233 throw new DOMException (DOMException.NAMESPACE_ERR, 234 "DOM003 Namespace error"); 235 } 236 } else if (prefix.equals("xml")) { 237 if (!namespaceURI.equals(xmlURI)) { 238 throw new DOMException (DOMException.NAMESPACE_ERR, 239 "DOM003 Namespace error"); 240 } 241 } else if (name.equals("xmlns")) { 242 throw new DOMException (DOMException.NAMESPACE_ERR, 243 "DOM003 Namespace error"); 244 } 245 } 246 } 247 name = prefix + ":" + localName; 249 } 250 251 257 public String getLocalName() 258 { 259 if (needsSyncData()) { 260 synchronizeData(); 261 } 262 return localName; 263 } 264 } 265 | Popular Tags |