1 2 58 59 package org.enhydra.apache.xerces.dom; 60 61 import org.w3c.dom.DOMException ; 62 63 64 71 public class ElementNSImpl 72 extends ElementImpl { 73 74 78 79 static final long serialVersionUID = -9142310625494392642L; 80 static final String xmlURI = "http://www.w3.org/XML/1998/namespace"; 81 82 86 87 protected String namespaceURI; 88 89 90 protected String localName; 91 92 93 96 protected ElementNSImpl(CoreDocumentImpl ownerDocument, 97 String namespaceURI, 98 String qualifiedName) 99 throws DOMException 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 else { 110 prefix = qualifiedName.substring(0, index); 111 localName = qualifiedName.substring(index+1); 112 113 if (ownerDocument.errorChecking) { 114 if (namespaceURI == null 115 || (localName.length() == 0) 116 || (localName.indexOf(':') >= 0)) { 117 throw new DOMException (DOMException.NAMESPACE_ERR, 118 "DOM003 Namespace error"); 119 } 120 else if (prefix.equals("xml")) { 121 if (!namespaceURI.equals(xmlURI)) { 122 throw new DOMException (DOMException.NAMESPACE_ERR, 123 "DOM003 Namespace error"); 124 } 125 } else if (index == 0) { 126 throw new DOMException (DOMException.NAMESPACE_ERR, 127 "DOM003 Namespace error"); 128 } 129 } 130 } 131 this.namespaceURI = namespaceURI; 132 } 133 134 protected ElementNSImpl(CoreDocumentImpl ownerDocument, 136 String value) { 137 super(ownerDocument, value); 138 } 139 140 144 145 149 162 public String getNamespaceURI() 163 { 164 if (needsSyncData()) { 165 synchronizeData(); 166 } 167 return namespaceURI; 168 } 169 170 180 public String getPrefix() 181 { 182 if (needsSyncData()) { 183 synchronizeData(); 184 } 185 int index = name.indexOf(':'); 186 return index < 0 ? null : name.substring(0, index); 187 } 188 189 201 public void setPrefix(String prefix) 202 throws DOMException 203 { 204 if (needsSyncData()) { 205 synchronizeData(); 206 } 207 if (ownerDocument().errorChecking) { 208 if (isReadOnly()) { 209 throw new DOMException ( 210 DOMException.NO_MODIFICATION_ALLOWED_ERR, 211 "DOM001 Modification not allowed"); 212 } 213 if (!CoreDocumentImpl.isXMLName(prefix)) { 214 throw new DOMException (DOMException.INVALID_CHARACTER_ERR, 215 "DOM002 Illegal character"); 216 } 217 if (namespaceURI == null || prefix.indexOf(':') >=0) { 218 throw new DOMException (DOMException.NAMESPACE_ERR, 219 "DOM003 Namespace error"); 220 } else if (prefix != null) { 221 if (prefix.equals("xml")) { 222 if (!namespaceURI.equals(xmlURI)) { 223 throw new DOMException (DOMException.NAMESPACE_ERR, 224 "DOM003 Namespace error"); 225 } 226 } 227 } 228 } 229 name = prefix + ":" + localName; 231 } 232 233 239 public String getLocalName() 240 { 241 if (needsSyncData()) { 242 synchronizeData(); 243 } 244 return localName; 245 } 246 } 247 | Popular Tags |