diff --git a/src/main/java/com/github/underscore/Xml.java b/src/main/java/com/github/underscore/Xml.java index 74d5b286..a24d5eb7 100644 --- a/src/main/java/com/github/underscore/Xml.java +++ b/src/main/java/com/github/underscore/Xml.java @@ -38,7 +38,7 @@ import java.util.function.BiFunction; import java.util.function.Function; -@SuppressWarnings({"java:S107", "java:S1119", "java:S3740", "java:S3776", "java:S4276"}) +@SuppressWarnings({"java:S107", "java:S1119", "java:S2583", "java:S3740", "java:S3776", "java:S4276"}) public final class Xml { private Xml() {} @@ -96,7 +96,7 @@ public enum Step { FOUR_SPACES(4), COMPACT(0), TABS(1); - private int ident; + private final int ident; Step(int ident) { this.ident = ident; @@ -1030,7 +1030,7 @@ private static void escape(String s, StringBuilder sb) { case '\t': sb.append("\t"); break; - case '\u20AC': + case '€': sb.append("€"); break; default: @@ -1316,8 +1316,7 @@ private static Object createMap( final int[] sourceIndex, final Set namespaces, final FromType fromType) { - final Map map = new LinkedHashMap<>(); - map.putAll(attrMap); + final Map map = new LinkedHashMap<>(attrMap); final org.w3c.dom.NodeList nodeList = node.getChildNodes(); for (int index = 0; index < nodeList.getLength(); index++) { final org.w3c.dom.Node currentNode = nodeList.item(index); @@ -1760,14 +1759,12 @@ private static Map getHeaderAttributes(final String xml) { XML_HEADER.length(), Math.max(XML_HEADER.length(), xml.indexOf("?>", XML_HEADER.length()))); final Map attributes = parseAttributes(xmlLocal); - for (Map.Entry attribute : attributes.entrySet()) { - result.put(attribute.getKey(), attribute.getValue()); - } + result.putAll(attributes); } return result; } - protected static String getDoctypeValue(final String xml) { + static String getDoctypeValue(final String xml) { int startIndex = xml.indexOf(DOCTYPE_HEADER) + DOCTYPE_HEADER.length(); char charToFind = '>'; int endIndexPlus = 0; @@ -1819,7 +1816,7 @@ private static org.w3c.dom.Document createDocument() { final javax.xml.parsers.DocumentBuilder builder = factory.newDocumentBuilder(); return builder.newDocument(); } catch (javax.xml.parsers.ParserConfigurationException ex) { - return null; + throw new IllegalArgumentException(ex); } } @@ -1888,17 +1885,18 @@ public static Object fromXmlWithoutNamespaces(final String xml) { (object, namespaces) -> { final String localString = String.valueOf(object); final String result; + String substring = localString.substring( + Math.max(0, localString.indexOf(':') + 1)); if (localString.startsWith("-") && namespaces.contains( localString.substring( 1, Math.max(1, localString.indexOf(':'))))) { result = "-" - + localString.substring( - Math.max(0, localString.indexOf(':') + 1)); + + substring; } else if (namespaces.contains( localString.substring(0, Math.max(0, localString.indexOf(':'))))) { - result = localString.substring(Math.max(0, localString.indexOf(':') + 1)); + result = substring; } else { result = String.valueOf(object); }