Skip to content

Commit 5c7cd1d

Browse files
committed
small optimization
1 parent cfb6df7 commit 5c7cd1d

1 file changed

Lines changed: 24 additions & 27 deletions

File tree

src/main/java/org/htmlunit/cyberneko/xerces/dom/AttrNSImpl.java

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -160,44 +160,41 @@ public String getPrefix() {
160160
*/
161161
@Override
162162
public void setPrefix(final String prefix) throws DOMException {
163+
// update node name with new qualifiedName
164+
if (prefix == null || prefix.isEmpty()) {
165+
name = localName_;
166+
return;
167+
}
168+
163169
if (ownerDocument().errorChecking) {
164-
if (prefix != null && !prefix.isEmpty()) {
170+
if (!CoreDocumentImpl.isXMLName(prefix, ownerDocument().isXML11Version())) {
171+
final String msg = DOMMessageFormatter.formatMessage("INVALID_CHARACTER_ERR", null);
172+
throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
173+
}
174+
if (namespaceURI_ == null || prefix.indexOf(':') >= 0) {
175+
final String msg = DOMMessageFormatter.formatMessage("NAMESPACE_ERR", null);
176+
throw new DOMException(DOMException.NAMESPACE_ERR, msg);
165177

166-
if (!CoreDocumentImpl.isXMLName(prefix, ownerDocument().isXML11Version())) {
167-
final String msg = DOMMessageFormatter.formatMessage("INVALID_CHARACTER_ERR", null);
168-
throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
169-
}
170-
if (namespaceURI_ == null || prefix.indexOf(':') >= 0) {
178+
}
179+
if ("xmlns".equals(prefix)) {
180+
if (!namespaceURI_.equals(xmlnsURI)) {
171181
final String msg = DOMMessageFormatter.formatMessage("NAMESPACE_ERR", null);
172182
throw new DOMException(DOMException.NAMESPACE_ERR, msg);
173-
174-
}
175-
if ("xmlns".equals(prefix)) {
176-
if (!namespaceURI_.equals(xmlnsURI)) {
177-
final String msg = DOMMessageFormatter.formatMessage("NAMESPACE_ERR", null);
178-
throw new DOMException(DOMException.NAMESPACE_ERR, msg);
179-
}
180183
}
181-
else if ("xml".equals(prefix)) {
182-
if (!namespaceURI_.equals(xmlURI)) {
183-
final String msg = DOMMessageFormatter.formatMessage("NAMESPACE_ERR", null);
184-
throw new DOMException(DOMException.NAMESPACE_ERR, msg);
185-
}
186-
}
187-
else if ("xmlns".equals(name)) {
184+
}
185+
else if ("xml".equals(prefix)) {
186+
if (!namespaceURI_.equals(xmlURI)) {
188187
final String msg = DOMMessageFormatter.formatMessage("NAMESPACE_ERR", null);
189188
throw new DOMException(DOMException.NAMESPACE_ERR, msg);
190189
}
191190
}
191+
else if ("xmlns".equals(name)) {
192+
final String msg = DOMMessageFormatter.formatMessage("NAMESPACE_ERR", null);
193+
throw new DOMException(DOMException.NAMESPACE_ERR, msg);
194+
}
192195
}
193196

194-
// update node name with new qualifiedName
195-
if (prefix != null && !prefix.isEmpty()) {
196-
name = prefix + ":" + localName_;
197-
}
198-
else {
199-
name = localName_;
200-
}
197+
name = prefix + ":" + localName_;
201198
}
202199

203200
/**

0 commit comments

Comments
 (0)