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