1 57 58 package com.sun.org.apache.xerces.internal.dom; 59 60 import com.sun.org.apache.xerces.internal.impl.dv.xs.XSSimpleTypeDecl; 61 import com.sun.org.apache.xerces.internal.xni.NamespaceContext; 62 import org.w3c.dom.DOMException ; 63 64 75 public class AttrNSImpl 76 extends AttrImpl { 77 78 82 83 static final long serialVersionUID = -781906615369795414L; 84 85 static final String xmlnsURI = "http://www.w3.org/2000/xmlns/"; 86 static final String xmlURI = "http://www.w3.org/XML/1998/namespace"; 87 88 92 93 protected String namespaceURI; 94 95 96 protected String localName; 97 98 101 public AttrNSImpl(){} 102 103 106 protected AttrNSImpl(CoreDocumentImpl ownerDocument, 107 String namespaceURI, 108 String qualifiedName) { 109 110 super(ownerDocument, qualifiedName); 111 setName(namespaceURI, qualifiedName); 112 } 113 114 private void setName(String namespaceURI, String qname){ 115 116 String prefix; 117 this.namespaceURI = namespaceURI; 119 if (namespaceURI !=null) { 120 this.namespaceURI = (namespaceURI.length() == 0)? null 121 : namespaceURI; 122 123 } 124 int colon1 = qname.indexOf(':'); 125 int colon2 = qname.lastIndexOf(':'); 126 ownerDocument().checkNamespaceWF(qname, colon1, colon2); 127 if (colon1 < 0) { 128 localName = qname; 130 ownerDocument().checkQName(null, localName); 131 if (ownerDocument().errorChecking) { 132 if (qname.equals("xmlns") 133 && (namespaceURI == null 134 || !namespaceURI.equals(NamespaceContext.XMLNS_URI)) 135 || (namespaceURI!=null && namespaceURI.equals(NamespaceContext.XMLNS_URI) 136 && !qname.equals("xmlns"))) { 137 String msg = 138 DOMMessageFormatter.formatMessage( 139 DOMMessageFormatter.DOM_DOMAIN, 140 "NAMESPACE_ERR", 141 null); 142 throw new DOMException (DOMException.NAMESPACE_ERR, msg); 143 } 144 } 145 } 146 else { 147 prefix = qname.substring(0, colon1); 148 localName = qname.substring(colon2+1); 149 ownerDocument().checkQName(prefix, localName); 150 ownerDocument().checkDOMNSErr(prefix, namespaceURI); 151 } 152 } 153 154 public AttrNSImpl(CoreDocumentImpl ownerDocument, 156 String namespaceURI, 157 String qualifiedName, 158 String localName) { 159 super(ownerDocument, qualifiedName); 160 161 this.localName = localName; 162 this.namespaceURI = namespaceURI; 163 } 164 165 protected AttrNSImpl(CoreDocumentImpl ownerDocument, 167 String value) { 168 super(ownerDocument, value); 169 } 170 171 void rename(String namespaceURI, String qualifiedName) { 176 if (needsSyncData()) { 177 synchronizeData(); 178 } 179 this.name = qualifiedName; 180 setName(namespaceURI, qualifiedName); 181 } 182 183 191 public void setValues (CoreDocumentImpl ownerDocument, 192 String namespaceURI, 193 String qualifiedName, 194 String localName){ 195 196 super.textNode = null; 197 super.flags = 0; 198 isSpecified(true); 199 hasStringValue(true); 200 super.setOwnerDocument(ownerDocument); 201 this.localName = localName; 202 this.namespaceURI = namespaceURI; 203 super.name = qualifiedName; 204 super.value = null; 205 } 206 207 211 224 public String getNamespaceURI() 225 { 226 if (needsSyncData()) { 227 synchronizeData(); 228 } 229 return namespaceURI; 233 } 234 235 245 public String getPrefix() 246 { 247 if (needsSyncData()) { 248 synchronizeData(); 249 } 250 int index = name.indexOf(':'); 251 return index < 0 ? null : name.substring(0, index); 252 } 253 254 269 public void setPrefix(String prefix) 270 throws DOMException 271 { 272 if (needsSyncData()) { 273 synchronizeData(); 274 } 275 if (ownerDocument().errorChecking) { 276 if (isReadOnly()) { 277 String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NO_MODIFICATION_ALLOWED_ERR", null); 278 throw new DOMException (DOMException.NO_MODIFICATION_ALLOWED_ERR, msg); 279 } 280 if (prefix != null && prefix.length() != 0) { 281 282 if (!CoreDocumentImpl.isXMLName(prefix,ownerDocument().isXML11Version())) { 283 String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_CHARACTER_ERR", null); 284 throw new DOMException (DOMException.INVALID_CHARACTER_ERR, msg); 285 } 286 if (namespaceURI == null || prefix.indexOf(':') >=0) { 287 String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NAMESPACE_ERR", null); 288 throw new DOMException (DOMException.NAMESPACE_ERR, msg); 289 290 } 291 if (prefix.equals("xmlns")) { 292 if (!namespaceURI.equals(xmlnsURI)){ 293 String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NAMESPACE_ERR", null); 294 throw new DOMException (DOMException.NAMESPACE_ERR, msg); 295 } 296 } else if (prefix.equals("xml")) { 297 if (!namespaceURI.equals(xmlURI)) { 298 String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NAMESPACE_ERR", null); 299 throw new DOMException (DOMException.NAMESPACE_ERR, msg); 300 } 301 }else if (name.equals("xmlns")) { 302 String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NAMESPACE_ERR", null); 303 throw new DOMException (DOMException.NAMESPACE_ERR, msg); 304 } 305 } 306 } 307 308 if (prefix !=null && prefix.length() != 0) { 310 name = prefix + ":" + localName; 311 } 312 else { 313 name = localName; 314 } 315 } 316 317 323 public String getLocalName() 324 { 325 if (needsSyncData()) { 326 synchronizeData(); 327 } 328 return localName; 329 } 330 331 336 public boolean isDerivedFrom(String typeNamespaceArg, 337 String typeNameArg, 338 int derivationMethod) { 339 340 if (type !=null){ 343 if (type instanceof XSSimpleTypeDecl){ 344 return ((XSSimpleTypeDecl)type).derivedFrom(typeNamespaceArg,typeNameArg,(short)derivationMethod); 345 } 346 } 347 return false; 348 } 349 350 353 public String getTypeNamespace() { 354 if (type !=null) { 355 if (type instanceof XSSimpleTypeDecl){ 356 return ((XSSimpleTypeDecl)type).getNamespace(); 357 } 358 return DTD_URI; 359 } 360 return null; 361 } 362 363 } 364 | Popular Tags |