Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
rbri committed Nov 21, 2024
1 parent 3557483 commit 117753a
Show file tree
Hide file tree
Showing 17 changed files with 113 additions and 178 deletions.
15 changes: 7 additions & 8 deletions src/main/java/org/htmlunit/cyberneko/xerces/dom/AttrImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ Node internalInsertBefore(final Node newChild, Node refChild, final boolean repl
kid != null; kid = kid.getNextSibling()) {

if (!ownerDocument.isKidOK(this, kid)) {
final String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "HIERARCHY_REQUEST_ERR", null);
final String msg = DOMMessageFormatter.formatMessage("HIERARCHY_REQUEST_ERR", null);
throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, msg);
}
}
Expand All @@ -543,16 +543,16 @@ Node internalInsertBefore(final Node newChild, Node refChild, final boolean repl

if (errorChecking) {
if (newChild.getOwnerDocument() != ownerDocument) {
final String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "WRONG_DOCUMENT_ERR", null);
final String msg = DOMMessageFormatter.formatMessage("WRONG_DOCUMENT_ERR", null);
throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, msg);
}
if (!ownerDocument.isKidOK(this, newChild)) {
final String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "HIERARCHY_REQUEST_ERR", null);
final String msg = DOMMessageFormatter.formatMessage("HIERARCHY_REQUEST_ERR", null);
throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, msg);
}
// refChild must be a child of this node (or null)
if (refChild != null && refChild.getParentNode() != this) {
final String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NOT_FOUND_ERR", null);
final String msg = DOMMessageFormatter.formatMessage("NOT_FOUND_ERR", null);
throw new DOMException(DOMException.NOT_FOUND_ERR, msg);
}

Expand All @@ -564,8 +564,7 @@ Node internalInsertBefore(final Node newChild, Node refChild, final boolean repl
treeSafe = newChild != a;
}
if (!treeSafe) {
final String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "HIERARCHY_REQUEST_ERR",
null);
final String msg = DOMMessageFormatter.formatMessage("HIERARCHY_REQUEST_ERR", null);
throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, msg);
}
}
Expand Down Expand Up @@ -654,7 +653,7 @@ public Node removeChild(final Node oldChild) throws DOMException {
// Tail-call, should be optimizable
if (hasStringValue()) {
// we don't have any child per say so it can't be one of them!
final String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NOT_FOUND_ERR", null);
final String msg = DOMMessageFormatter.formatMessage("NOT_FOUND_ERR", null);
throw new DOMException(DOMException.NOT_FOUND_ERR, msg);
}
return internalRemoveChild(oldChild, false);
Expand All @@ -670,7 +669,7 @@ Node internalRemoveChild(final Node oldChild, final boolean replace) throws DOME
final CoreDocumentImpl ownerDocument = ownerDocument();
if (ownerDocument.errorChecking) {
if (oldChild != null && oldChild.getParentNode() != this) {
final String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NOT_FOUND_ERR", null);
final String msg = DOMMessageFormatter.formatMessage("NOT_FOUND_ERR", null);
throw new DOMException(DOMException.NOT_FOUND_ERR, msg);
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/org/htmlunit/cyberneko/xerces/dom/AttrNSImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private void setName(final String namespaceURI, final String qname) {
if ("xmlns".equals(qname) && (namespaceURI == null || !namespaceURI.equals(NamespaceContext.XMLNS_URI))
|| (namespaceURI != null && namespaceURI.equals(NamespaceContext.XMLNS_URI)
&& !"xmlns".equals(qname))) {
final String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NAMESPACE_ERR", null);
final String msg = DOMMessageFormatter.formatMessage("NAMESPACE_ERR", null);
throw new DOMException(DOMException.NAMESPACE_ERR, msg);
}
}
Expand Down Expand Up @@ -162,28 +162,28 @@ public void setPrefix(final String prefix) throws DOMException {
if (prefix != null && prefix.length() != 0) {

if (!CoreDocumentImpl.isXMLName(prefix, ownerDocument().isXML11Version())) {
final String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_CHARACTER_ERR", null);
final String msg = DOMMessageFormatter.formatMessage("INVALID_CHARACTER_ERR", null);
throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
}
if (namespaceURI_ == null || prefix.indexOf(':') >= 0) {
final String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NAMESPACE_ERR", null);
final String msg = DOMMessageFormatter.formatMessage("NAMESPACE_ERR", null);
throw new DOMException(DOMException.NAMESPACE_ERR, msg);

}
if ("xmlns".equals(prefix)) {
if (!namespaceURI_.equals(xmlnsURI)) {
final String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NAMESPACE_ERR", null);
final String msg = DOMMessageFormatter.formatMessage("NAMESPACE_ERR", null);
throw new DOMException(DOMException.NAMESPACE_ERR, msg);
}
}
else if ("xml".equals(prefix)) {
if (!namespaceURI_.equals(xmlURI)) {
final String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NAMESPACE_ERR", null);
final String msg = DOMMessageFormatter.formatMessage("NAMESPACE_ERR", null);
throw new DOMException(DOMException.NAMESPACE_ERR, msg);
}
}
else if ("xmlns".equals(name)) {
final String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NAMESPACE_ERR", null);
final String msg = DOMMessageFormatter.formatMessage("NAMESPACE_ERR", null);
throw new DOMException(DOMException.NAMESPACE_ERR, msg);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,19 @@ public Node setNamedItem(final Node arg) throws DOMException {
final boolean errCheck = ownerNode.ownerDocument().errorChecking;
if (errCheck) {
if (arg.getOwnerDocument() != ownerNode.ownerDocument()) {
final String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "WRONG_DOCUMENT_ERR", null);
final String msg = DOMMessageFormatter.formatMessage("WRONG_DOCUMENT_ERR", null);
throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, msg);
}
if (arg.getNodeType() != Node.ATTRIBUTE_NODE) {
final String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "HIERARCHY_REQUEST_ERR", null);
final String msg = DOMMessageFormatter.formatMessage("HIERARCHY_REQUEST_ERR", null);
throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, msg);
}
}
final AttrImpl argn = (AttrImpl) arg;

if (argn.isOwned()) {
if (errCheck && argn.getOwnerElement() != ownerNode) {
final String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INUSE_ATTRIBUTE_ERR", null);
final String msg = DOMMessageFormatter.formatMessage("INUSE_ATTRIBUTE_ERR", null);
throw new DOMException(DOMException.INUSE_ATTRIBUTE_ERR, msg);
}
// replacing an Attribute with itself does nothing
Expand Down Expand Up @@ -129,19 +129,19 @@ public Node setNamedItemNS(final Node arg) throws DOMException {
final boolean errCheck = ownerNode.ownerDocument().errorChecking;
if (errCheck) {
if (arg.getOwnerDocument() != ownerNode.ownerDocument()) {
final String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "WRONG_DOCUMENT_ERR", null);
final String msg = DOMMessageFormatter.formatMessage("WRONG_DOCUMENT_ERR", null);
throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, msg);
}
if (arg.getNodeType() != Node.ATTRIBUTE_NODE) {
final String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "HIERARCHY_REQUEST_ERR", null);
final String msg = DOMMessageFormatter.formatMessage("HIERARCHY_REQUEST_ERR", null);
throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, msg);
}
}
final AttrImpl argn = (AttrImpl) arg;

if (argn.isOwned()) {
if (errCheck && argn.getOwnerElement() != ownerNode) {
final String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INUSE_ATTRIBUTE_ERR", null);
final String msg = DOMMessageFormatter.formatMessage("INUSE_ATTRIBUTE_ERR", null);
throw new DOMException(DOMException.INUSE_ATTRIBUTE_ERR, msg);
}
// replacing an Attribute with itself does nothing
Expand Down Expand Up @@ -235,7 +235,7 @@ protected Node removeItem(final Node item) throws DOMException {
}
}
if (index < 0) {
final String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NOT_FOUND_ERR", null);
final String msg = DOMMessageFormatter.formatMessage("NOT_FOUND_ERR", null);
throw new DOMException(DOMException.NOT_FOUND_ERR, msg);
}

Expand All @@ -254,7 +254,7 @@ protected final Node internalRemoveNamedItem(final String name, final boolean ra
final int i = findNamePoint(name);
if (i < 0) {
if (raiseEx) {
final String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NOT_FOUND_ERR", null);
final String msg = DOMMessageFormatter.formatMessage("NOT_FOUND_ERR", null);
throw new DOMException(DOMException.NOT_FOUND_ERR, msg);
}

Expand Down Expand Up @@ -322,7 +322,7 @@ protected final Node internalRemoveNamedItemNS(final String namespaceURI, final
final int i = findNamePoint(namespaceURI, name);
if (i < 0) {
if (raiseEx) {
final String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NOT_FOUND_ERR", null);
final String msg = DOMMessageFormatter.formatMessage("NOT_FOUND_ERR", null);
throw new DOMException(DOMException.NOT_FOUND_ERR, msg);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ void internalDeleteData(final int offset, final int count, final boolean replace
final CoreDocumentImpl ownerDocument = ownerDocument();
if (ownerDocument.errorChecking) {
if (count < 0) {
final String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INDEX_SIZE_ERR", null);
final String msg = DOMMessageFormatter.formatMessage("INDEX_SIZE_ERR", null);
throw new DOMException(DOMException.INDEX_SIZE_ERR, msg);
}
}
Expand All @@ -203,7 +203,7 @@ void internalDeleteData(final int offset, final int count, final boolean replace
ownerDocument.deletedText(this, offset, count);
}
catch (final StringIndexOutOfBoundsException e) {
final String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INDEX_SIZE_ERR", null);
final String msg = DOMMessageFormatter.formatMessage("INDEX_SIZE_ERR", null);
throw new DOMException(DOMException.INDEX_SIZE_ERR, msg);
}
}
Expand Down Expand Up @@ -239,7 +239,7 @@ void internalInsertData(final int offset, final String data, final boolean repla
ownerDocument.insertedText(this, offset, data.length());
}
catch (final StringIndexOutOfBoundsException e) {
final String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INDEX_SIZE_ERR", null);
final String msg = DOMMessageFormatter.formatMessage("INDEX_SIZE_ERR", null);
throw new DOMException(DOMException.INDEX_SIZE_ERR, msg);
}

Expand Down Expand Up @@ -314,7 +314,7 @@ public void setData(final String value) throws DOMException {
public String substringData(final int offset, final int count) throws DOMException {
final int length = data_.length();
if (count < 0 || offset < 0 || offset > length - 1) {
final String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INDEX_SIZE_ERR", null);
final String msg = DOMMessageFormatter.formatMessage("INDEX_SIZE_ERR", null);
throw new DOMException(DOMException.INDEX_SIZE_ERR, msg);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,20 +114,20 @@ final void checkQName(final String qname) {
// it is an error for NCName to have more than one ':'
// check if it is valid QName [Namespace in XML production 6]
if (index == 0 || index == length - 1 || lastIndex != index) {
final String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NAMESPACE_ERR", null);
final String msg = DOMMessageFormatter.formatMessage("NAMESPACE_ERR", null);
throw new DOMException(DOMException.NAMESPACE_ERR, msg);
}
int start = 0;
// Namespace in XML production [6]
if (index > 0) {
// check that prefix is NCName
if (!XMLChar.isNCNameStart(qname.charAt(start))) {
final String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_CHARACTER_ERR", null);
final String msg = DOMMessageFormatter.formatMessage("INVALID_CHARACTER_ERR", null);
throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
}
for (int i = 1; i < index; i++) {
if (!XMLChar.isNCName(qname.charAt(i))) {
final String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_CHARACTER_ERR", null);
final String msg = DOMMessageFormatter.formatMessage("INVALID_CHARACTER_ERR", null);
throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
}
}
Expand All @@ -137,12 +137,12 @@ final void checkQName(final String qname) {
// check local part
if (!XMLChar.isNCNameStart(qname.charAt(start))) {
// REVISIT: add qname parameter to the message
final String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_CHARACTER_ERR", null);
final String msg = DOMMessageFormatter.formatMessage("INVALID_CHARACTER_ERR", null);
throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
}
for (int i = start + 1; i < length; i++) {
if (!XMLChar.isNCName(qname.charAt(i))) {
final String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_CHARACTER_ERR", null);
final String msg = DOMMessageFormatter.formatMessage("INVALID_CHARACTER_ERR", null);
throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
}
}
Expand Down Expand Up @@ -173,7 +173,7 @@ final void checkQName(final String qname) {
public Document createDocument(final String namespaceURI, final String qualifiedName, final DocumentType doctype)
throws DOMException {
if (doctype != null && doctype.getOwnerDocument() != null) {
final String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "WRONG_DOCUMENT_ERR", null);
final String msg = DOMMessageFormatter.formatMessage("WRONG_DOCUMENT_ERR", null);
throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, msg);
}
final CoreDocumentImpl doc = createDocument(doctype);
Expand Down
Loading

0 comments on commit 117753a

Please sign in to comment.