Skip to content

Commit 514457a

Browse files
committed
cleanup
1 parent 5643524 commit 514457a

5 files changed

Lines changed: 61 additions & 122 deletions

File tree

src/main/java/org/htmlunit/cyberneko/parsers/DOMFragmentParser.java

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -422,58 +422,4 @@ public void setDocumentSource(final XMLDocumentSource source) {
422422
public XMLDocumentSource getDocumentSource() {
423423
return documentSource_;
424424
}
425-
426-
/*
427-
public static void print(Node node) {
428-
short type = node.getNodeType();
429-
switch (type) {
430-
case Node.ELEMENT_NODE: {
431-
System.out.print('<');
432-
System.out.print(node.getNodeName());
433-
org.w3c.dom.NamedNodeMap attrs = node.getAttributes();
434-
int attrCount = attrs != null ? attrs.getLength() : 0;
435-
for (int i = 0; i < attrCount; i++) {
436-
Node attr = attrs.item(i);
437-
System.out.print(' ');
438-
System.out.print(attr.getNodeName());
439-
System.out.print("='");
440-
System.out.print(attr.getNodeValue());
441-
System.out.print('\'');
442-
}
443-
System.out.print('>');
444-
break;
445-
}
446-
case Node.TEXT_NODE: {
447-
System.out.print(node.getNodeValue());
448-
break;
449-
}
450-
}
451-
Node child = node.getFirstChild();
452-
while (child != null) {
453-
print(child);
454-
child = child.getNextSibling();
455-
}
456-
if (type == Node.ELEMENT_NODE) {
457-
System.out.print("</");
458-
System.out.print(node.getNodeName());
459-
System.out.print('>');
460-
}
461-
else if (type == Node.DOCUMENT_NODE || type == Node.DOCUMENT_FRAGMENT_NODE) {
462-
System.out.println();
463-
}
464-
System.out.flush();
465-
}
466-
467-
public static void main(String[] argv) throws Exception {
468-
DOMFragmentParser parser = new DOMFragmentParser();
469-
HTMLDocument document = new org.htmlunit.cyberneko.html.dom.HTMLDocumentImpl();
470-
for (int i = 0; i < argv.length; i++) {
471-
String sysid = argv[i];
472-
System.err.println("# "+sysid);
473-
DocumentFragment fragment = document.createDocumentFragment();
474-
parser.parse(sysid, fragment);
475-
print(fragment);
476-
}
477-
}
478-
*/
479425
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ public class CoreDOMImplementationImpl implements DOMImplementation {
4343
private int docAndDoctypeCounter_ = 0;
4444

4545
/** Dom implementation singleton. */
46-
private static final CoreDOMImplementationImpl singleton = new CoreDOMImplementationImpl();
46+
private static final CoreDOMImplementationImpl INSTANCE = new CoreDOMImplementationImpl();
4747

4848
// NON-DOM: Obtain and return the single shared object
4949
public static DOMImplementation getDOMImplementation() {
50-
return singleton;
50+
return INSTANCE;
5151
}
5252

5353
/**
@@ -198,8 +198,8 @@ protected CoreDocumentImpl createDocument(final DocumentType doctype) {
198198
*/
199199
@Override
200200
public Object getFeature(final String feature, final String version) {
201-
if (singleton.hasFeature(feature, version)) {
202-
return singleton;
201+
if (INSTANCE.hasFeature(feature, version)) {
202+
return INSTANCE;
203203
}
204204
return null;
205205
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@
2929
public class DOMImplementationImpl extends CoreDOMImplementationImpl {
3030

3131
/** Dom implementation singleton. */
32-
private static final DOMImplementationImpl singleton = new DOMImplementationImpl();
32+
private static final DOMImplementationImpl INSTANCE = new DOMImplementationImpl();
3333

3434
// NON-DOM: Obtain and return the single shared object
3535
public static DOMImplementation getDOMImplementation() {
36-
return singleton;
36+
return INSTANCE;
3737
}
3838

3939
/**

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

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,14 @@ public Node cloneNode(final boolean deep) {
122122
*/
123123
@Override
124124
public String getBaseURI() {
125-
final DocumentType doctype;
126-
final NamedNodeMap entities;
127-
final EntityImpl entDef;
128-
if (null != (doctype = getOwnerDocument().getDoctype()) && null != (entities = doctype.getEntities())) {
129-
130-
entDef = (EntityImpl) entities.getNamedItem(getNodeName());
131-
if (entDef != null) {
132-
return entDef.getBaseURI();
125+
final DocumentType doctype = getOwnerDocument().getDoctype();
126+
if (null != doctype) {
127+
final NamedNodeMap entities = doctype.getEntities();
128+
if (null != entities) {
129+
final EntityImpl entDef = (EntityImpl) entities.getNamedItem(getNodeName());
130+
if (entDef != null) {
131+
return entDef.getBaseURI();
132+
}
133133
}
134134
}
135135

@@ -202,22 +202,22 @@ protected void synchronizeChildren() {
202202
// no need to synchronize again
203203
needsSyncChildren(false);
204204

205-
final DocumentType doctype;
206-
final NamedNodeMap entities;
207-
final EntityImpl entDef;
208-
if (null != (doctype = getOwnerDocument().getDoctype()) && null != (entities = doctype.getEntities())) {
209-
210-
entDef = (EntityImpl) entities.getNamedItem(getNodeName());
205+
final DocumentType doctype = getOwnerDocument().getDoctype();
206+
if (null != doctype) {
207+
final NamedNodeMap entities = doctype.getEntities();
208+
if (null != entities) {
209+
final EntityImpl entDef = (EntityImpl) entities.getNamedItem(getNodeName());
211210

212-
// No Entity by this name, stop here.
213-
if (entDef == null) {
214-
return;
215-
}
211+
// No Entity by this name, stop here.
212+
if (entDef == null) {
213+
return;
214+
}
216215

217-
// If entity's definition exists, clone its kids
218-
for (Node defkid = entDef.getFirstChild(); defkid != null; defkid = defkid.getNextSibling()) {
219-
final Node newkid = defkid.cloneNode(true);
220-
insertBefore(newkid, null);
216+
// If entity's definition exists, clone its kids
217+
for (Node defkid = entDef.getFirstChild(); defkid != null; defkid = defkid.getNextSibling()) {
218+
final Node newkid = defkid.cloneNode(true);
219+
insertBefore(newkid, null);
220+
}
221221
}
222222
}
223223
}

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

Lines changed: 33 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -261,10 +261,8 @@ protected void setOwnerDocument(final CoreDocumentImpl doc) {
261261
* @return the node number
262262
*/
263263
protected int getNodeNumber() {
264-
final int nodeNumber;
265-
final CoreDocumentImpl cd = (CoreDocumentImpl) (this.getOwnerDocument());
266-
nodeNumber = cd.getNodeNumber(this);
267-
return nodeNumber;
264+
final CoreDocumentImpl cd = (CoreDocumentImpl) getOwnerDocument();
265+
return cd.getNodeNumber(this);
268266
}
269267

270268
/**
@@ -691,11 +689,11 @@ public short compareDocumentPosition(final Node other) throws DOMException {
691689
final Document thisOwnerDoc;
692690
final Document otherOwnerDoc;
693691
// get the respective Document owners.
694-
if (this.getNodeType() == Node.DOCUMENT_NODE) {
692+
if (getNodeType() == Node.DOCUMENT_NODE) {
695693
thisOwnerDoc = (Document) this;
696694
}
697695
else {
698-
thisOwnerDoc = this.getOwnerDocument();
696+
thisOwnerDoc = getOwnerDocument();
699697
}
700698
if (other.getNodeType() == Node.DOCUMENT_NODE) {
701699
otherOwnerDoc = (Document) other;
@@ -1061,7 +1059,7 @@ public boolean isSameNode(final Node other) {
10611059
@Override
10621060
public boolean isDefaultNamespace(final String namespaceURI) {
10631061
// REVISIT: remove casts when DOM L3 becomes REC.
1064-
final short type = this.getNodeType();
1062+
final short type = getNodeType();
10651063
switch (type) {
10661064
case Node.ELEMENT_NODE: {
10671065
final String namespace = this.getNamespaceURI();
@@ -1074,7 +1072,7 @@ public boolean isDefaultNamespace(final String namespaceURI) {
10741072
}
10751073
return namespaceURI.equals(namespace);
10761074
}
1077-
if (this.hasAttributes()) {
1075+
if (hasAttributes()) {
10781076
final ElementImpl elem = (ElementImpl) this;
10791077
final NodeImpl attr = (NodeImpl) elem.getAttributeNodeNS("http://www.w3.org/2000/xmlns/", "xmlns");
10801078
if (attr != null) {
@@ -1107,7 +1105,7 @@ public boolean isDefaultNamespace(final String namespaceURI) {
11071105
// type is unknown
11081106
return false;
11091107
case Node.ATTRIBUTE_NODE: {
1110-
if (this.ownerNode_.getNodeType() == Node.ELEMENT_NODE) {
1108+
if (ownerNode_.getNodeType() == Node.ELEMENT_NODE) {
11111109
return ownerNode_.isDefaultNamespace(namespaceURI);
11121110

11131111
}
@@ -1142,11 +1140,10 @@ public String lookupPrefix(final String namespaceURI) {
11421140
return null;
11431141
}
11441142

1145-
final short type = this.getNodeType();
1146-
1143+
final short type = getNodeType();
11471144
switch (type) {
11481145
case Node.ELEMENT_NODE: {
1149-
this.getNamespaceURI(); // to flip out children
1146+
getNamespaceURI(); // to flip out children
11501147
return lookupNamespacePrefix(namespaceURI, (ElementImpl) this);
11511148
}
11521149
case Node.DOCUMENT_NODE: {
@@ -1164,7 +1161,7 @@ public String lookupPrefix(final String namespaceURI) {
11641161
// type is unknown
11651162
return null;
11661163
case Node.ATTRIBUTE_NODE: {
1167-
if (this.ownerNode_.getNodeType() == Node.ELEMENT_NODE) {
1164+
if (ownerNode_.getNodeType() == Node.ELEMENT_NODE) {
11681165
return ownerNode_.lookupPrefix(namespaceURI);
11691166

11701167
}
@@ -1189,13 +1186,11 @@ public String lookupPrefix(final String namespaceURI) {
11891186
*/
11901187
@Override
11911188
public String lookupNamespaceURI(final String specifiedPrefix) {
1192-
final short type = this.getNodeType();
1193-
switch (type) {
1194-
case Node.ELEMENT_NODE: {
1195-
1196-
String namespace = this.getNamespaceURI();
1197-
final String prefix = this.getPrefix();
1189+
switch (getNodeType()) {
1190+
case Node.ELEMENT_NODE:
1191+
String namespace = getNamespaceURI();
11981192
if (namespace != null) {
1193+
final String prefix = getPrefix();
11991194
// REVISIT: is it possible that prefix is empty string?
12001195
if (specifiedPrefix == null && prefix == null) {
12011196
// looking for default namespace
@@ -1206,8 +1201,8 @@ else if (prefix != null && prefix.equals(specifiedPrefix)) {
12061201
return namespace;
12071202
}
12081203
}
1209-
if (this.hasAttributes()) {
1210-
final NamedNodeMap map = this.getAttributes();
1204+
if (hasAttributes()) {
1205+
final NamedNodeMap map = getAttributes();
12111206
final int length = map.getLength();
12121207
for (int i = 0; i < length; i++) {
12131208
final Node attr = map.item(i);
@@ -1221,7 +1216,7 @@ else if (prefix != null && prefix.equals(specifiedPrefix)) {
12211216
return value.length() > 0 ? value : null;
12221217
}
12231218
else if ("xmlns".equals(attrPrefix)
1224-
&& attr.getLocalName().equals(specifiedPrefix)) {
1219+
&& attr.getLocalName().equals(specifiedPrefix)) {
12251220
// non default namespace
12261221
return value.length() > 0 ? value : null;
12271222
}
@@ -1235,34 +1230,33 @@ else if ("xmlns".equals(attrPrefix)
12351230

12361231
return null;
12371232

1238-
}
1239-
case Node.DOCUMENT_NODE: {
1233+
case Node.DOCUMENT_NODE:
12401234
final Element docElement = ((Document) this).getDocumentElement();
12411235
if (docElement != null) {
12421236
return docElement.lookupNamespaceURI(specifiedPrefix);
12431237
}
12441238
return null;
1245-
}
1239+
12461240
case Node.ENTITY_NODE:
12471241
case Node.NOTATION_NODE:
12481242
case Node.DOCUMENT_FRAGMENT_NODE:
12491243
case Node.DOCUMENT_TYPE_NODE:
12501244
// type is unknown
12511245
return null;
1252-
case Node.ATTRIBUTE_NODE: {
1253-
if (this.ownerNode_.getNodeType() == Node.ELEMENT_NODE) {
1246+
1247+
case Node.ATTRIBUTE_NODE:
1248+
if (ownerNode_.getNodeType() == Node.ELEMENT_NODE) {
12541249
return ownerNode_.lookupNamespaceURI(specifiedPrefix);
12551250

12561251
}
12571252
return null;
1258-
}
1259-
default: {
1260-
final NodeImpl ancestor = (NodeImpl) getElementAncestor(this);
1261-
if (ancestor != null) {
1262-
return ancestor.lookupNamespaceURI(specifiedPrefix);
1253+
1254+
default:
1255+
final NodeImpl ancestorDef = (NodeImpl) getElementAncestor(this);
1256+
if (ancestorDef != null) {
1257+
return ancestorDef.lookupNamespaceURI(specifiedPrefix);
12631258
}
12641259
return null;
1265-
}
12661260
}
12671261
}
12681262

@@ -1279,12 +1273,11 @@ Node getElementAncestor(final Node currentNode) {
12791273
}
12801274

12811275
String lookupNamespacePrefix(final String namespaceURI, final ElementImpl el) {
1282-
String namespace = this.getNamespaceURI();
1283-
// REVISIT: if no prefix is available is it null or empty string, or
1284-
// could be both?
1285-
final String prefix = this.getPrefix();
1286-
1276+
String namespace = getNamespaceURI();
12871277
if (namespace != null && namespace.equals(namespaceURI)) {
1278+
// REVISIT: if no prefix is available is it null or empty string, or
1279+
// could be both?
1280+
final String prefix = getPrefix();
12881281
if (prefix != null) {
12891282
final String foundNamespace = el.lookupNamespaceURI(prefix);
12901283
if (foundNamespace != null && foundNamespace.equals(namespaceURI)) {
@@ -1293,8 +1286,8 @@ String lookupNamespacePrefix(final String namespaceURI, final ElementImpl el) {
12931286

12941287
}
12951288
}
1296-
if (this.hasAttributes()) {
1297-
final NamedNodeMap map = this.getAttributes();
1289+
if (hasAttributes()) {
1290+
final NamedNodeMap map = getAttributes();
12981291
final int length = map.getLength();
12991292
for (int i = 0; i < length; i++) {
13001293
final Node attr = map.item(i);

0 commit comments

Comments
 (0)