Skip to content
Permalink
Browse files
minor refactor: remove Sonar warning
  • Loading branch information
paulk-asert committed Mar 25, 2022
1 parent 0905af8 commit 240d33057243a6d7a03fdc502b1e72e0c0c59bd6
Showing 1 changed file with 37 additions and 31 deletions.
@@ -114,17 +114,19 @@ public static Document parse(final File file) throws Exception {
}

public static Document parse(final Reader input) throws Exception {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
return builder.parse(new InputSource(input));
return parse(new InputSource(input));
}

public static Document parse(final InputStream input) throws Exception {
return parse(new InputSource(input));
}

private static Document parse(InputSource is) throws Exception {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
DocumentBuilder builder = factory.newDocumentBuilder();
return builder.parse(new InputSource(input));
return builder.parse(is);
}

protected void print(Node node, Map namespaces, boolean endWithComma) {
@@ -170,33 +172,37 @@ protected void printElement(Element element, Map namespaces, boolean endWithComm
if (length == 0) {
printEnd(")", endWithComma);
} else {
Node node = list.item(0);
if (length == 1 && node instanceof Text) {
Text textNode = (Text) node;
String text = getTextNodeData(textNode);
if (hasAttributes) print(", ");
printQuoted(text);
printEnd(")", endWithComma);
} else if (mixedContent(list)) {
println(") {");
out.incrementIndent();
boolean oldInMixed = inMixed;
inMixed = true;
for (node = element.getFirstChild(); node != null; node = node.getNextSibling()) {
print(node, namespaces, false);
}
inMixed = oldInMixed;
out.decrementIndent();
printIndent();
printEnd("}", endWithComma);
} else {
println(") {");
out.incrementIndent();
printChildren(element, namespaces);
out.decrementIndent();
printIndent();
printEnd("}", endWithComma);
printChildren(element, namespaces, endWithComma, hasAttributes, list, length);
}
}

private void printChildren(Element element, Map namespaces, boolean endWithComma, boolean hasAttributes, NodeList list, int length) {
Node node = list.item(0);
if (length == 1 && node instanceof Text) {
Text textNode = (Text) node;
String text = getTextNodeData(textNode);
if (hasAttributes) print(", ");
printQuoted(text);
printEnd(")", endWithComma);
} else if (mixedContent(list)) {
println(") {");
out.incrementIndent();
boolean oldInMixed = inMixed;
inMixed = true;
for (node = element.getFirstChild(); node != null; node = node.getNextSibling()) {
print(node, namespaces, false);
}
inMixed = oldInMixed;
out.decrementIndent();
printIndent();
printEnd("}", endWithComma);
} else {
println(") {");
out.incrementIndent();
printChildren(element, namespaces);
out.decrementIndent();
printIndent();
printEnd("}", endWithComma);
}
}

0 comments on commit 240d330

Please sign in to comment.