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