38 |
package gnu.xml.dom; |
package gnu.xml.dom; |
39 |
|
|
40 |
import javax.xml.XMLConstants; |
import javax.xml.XMLConstants; |
41 |
|
import org.w3c.dom.DOMException; |
42 |
|
|
43 |
/** |
/** |
44 |
* <p> Abstract implemention of namespace support. This facilitates |
* <p> Abstract implemention of namespace support. This facilitates |
136 |
{ |
{ |
137 |
if (readonly) |
if (readonly) |
138 |
{ |
{ |
139 |
throw new DomEx(DomEx.NO_MODIFICATION_ALLOWED_ERR); |
throw new DomDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR); |
140 |
} |
} |
141 |
|
|
142 |
if (prefix == null) |
if (prefix == null) |
146 |
} |
} |
147 |
else if (namespace == null) |
else if (namespace == null) |
148 |
{ |
{ |
149 |
throw new DomEx(DomEx.NAMESPACE_ERR, |
throw new DomDOMException(DOMException.NAMESPACE_ERR, |
150 |
"can't set prefix, node has no namespace URI", |
"can't set prefix, node has no namespace URI", |
151 |
this, 0); |
this, 0); |
152 |
} |
} |
153 |
|
|
154 |
DomDocument.checkName(prefix, "1.1".equals(owner.getXmlVersion())); |
DomDocument.checkName(prefix, "1.1".equals(owner.getXmlVersion())); |
155 |
if (prefix.indexOf (':') != -1) |
if (prefix.indexOf (':') != -1) |
156 |
{ |
{ |
157 |
throw new DomEx(DomEx.NAMESPACE_ERR, |
throw new DomDOMException(DOMException.NAMESPACE_ERR, |
158 |
"illegal prefix " + prefix, this, 0); |
"illegal prefix " + prefix, this, 0); |
159 |
} |
} |
160 |
|
|
161 |
if (XMLConstants.XML_NS_PREFIX.equals(prefix) |
if (XMLConstants.XML_NS_PREFIX.equals(prefix) |
162 |
&& !XMLConstants.XML_NS_URI.equals(namespace)) |
&& !XMLConstants.XML_NS_URI.equals(namespace)) |
163 |
{ |
{ |
164 |
throw new DomEx(DomEx.NAMESPACE_ERR, |
throw new DomDOMException(DOMException.NAMESPACE_ERR, |
165 |
"xml namespace is always " + |
"xml namespace is always " + |
166 |
XMLConstants.XML_NS_URI, this, 0); |
XMLConstants.XML_NS_URI, this, 0); |
167 |
} |
} |
168 |
|
|
169 |
if (XMLConstants.XMLNS_ATTRIBUTE.equals(prefix)) |
if (XMLConstants.XMLNS_ATTRIBUTE.equals(prefix)) |
170 |
{ |
{ |
171 |
if (namespace != null || getNodeType() != ATTRIBUTE_NODE) |
if (namespace != null || getNodeType() != ATTRIBUTE_NODE) |
172 |
{ |
{ |
173 |
throw new DomEx(DomEx.NAMESPACE_ERR, |
throw new DomDOMException(DOMException.NAMESPACE_ERR, |
174 |
"xmlns attribute prefix is reserved", this, 0); |
"xmlns attribute prefix is reserved", |
175 |
|
this, 0); |
176 |
} |
} |
177 |
} |
} |
178 |
else if (getNodeType () == ATTRIBUTE_NODE |
else if (getNodeType () == ATTRIBUTE_NODE |
179 |
&& (XMLConstants.XMLNS_ATTRIBUTE.equals(name) || |
&& (XMLConstants.XMLNS_ATTRIBUTE.equals(name) || |
180 |
name.startsWith("xmlns:"))) |
name.startsWith("xmlns:"))) |
181 |
{ |
{ |
182 |
throw new DomEx(DomEx.NAMESPACE_ERR, |
throw new DomDOMException(DOMException.NAMESPACE_ERR, |
183 |
"namespace declarations can't change names", this, 0); |
"namespace declarations can't change names", |
184 |
|
this, 0); |
185 |
} |
} |
186 |
|
|
187 |
this.prefix = prefix.intern(); |
this.prefix = prefix.intern(); |