XMLUtil { @Pure @SuppressWarnings("checkstyle:cyclomaticcomplexity") private static String getAttributeValue(Node document, boolean caseSensitive, int idxStart, String... path) { assert document != null : AssertMessages.notNullParameter(0); assert path != null && (path.length - idxStart) >= 0 : AssertMessages.invalidValue(2); if ((path.length - idxStart) > 1) { final NodeList nodes = document.getChildNodes(); final int len = nodes.getLength(); for (int i = 0; i < len; ++i) { final Node node = nodes.item(i); if (node != null) { final String name = node.getNodeName(); if (name != null && ((caseSensitive && name.equals(path[idxStart])) || (!caseSensitive && name.equalsIgnoreCase(path[idxStart])))) { final String value = getAttributeValue(node, caseSensitive, idxStart + 1, path); if (value != null) { return value; } } } } } else if (document instanceof Element) { if (caseSensitive) { return ((Element) document).getAttribute(path[idxStart]); } final NamedNodeMap map = ((Element) document).getAttributes(); final int len = map.getLength(); for (int i = 0; i < len; ++i) { final Node node = map.item(i); if (node instanceof Attr) { final Attr attr = (Attr) node; final String name = attr.getName(); if (name != null && name.equalsIgnoreCase(path[idxStart])) { final String value = attr.getValue(); if (value != null) { return value; } } } } } else { final NamedNodeMap attrs = document.getAttributes(); if (attrs != null) { final int len = attrs.getLength(); for (int idxAttr = 0; idxAttr < len; ++idxAttr) { final Node node = attrs.item(idxAttr); final String name = node.getNodeName(); if (name != null && ((caseSensitive && name.equals(path[idxStart])) || (!caseSensitive && name.equalsIgnoreCase(path[idxStart])))) { return node.getNodeValue(); } } } } return null; } private  XMLUtil(); @Pure static boolean getAttributeBoolean(Node document, boolean caseSensitive, String... path); @Pure static boolean getAttributeBoolean(Node document, String... path); @Pure static Boolean getAttributeBooleanWithDefault(Node document, boolean caseSensitive,
			Boolean defaultValue, String... path); @Pure static Boolean getAttributeBooleanWithDefault(Node document, Boolean defaultValue, String... path); @Pure static Class<?> getAttributeClass(Node document, boolean caseSensitive, String... path); @Pure static Class<?> getAttributeClass(Node document, String... path); @Pure static Class<?> getAttributeClassWithDefault(Node document, boolean caseSensitive,
			Class<?> defaultValue, String... path); @Pure static Class<?> getAttributeClassWithDefault(Node document, Class<?> defaultValue, String... path); @Pure static int getAttributeColor(Node document, boolean caseSensitive, String... path); @Pure static int getAttributeColor(Node document, String... path); @Pure static Integer getAttributeColorWithDefault(Node document, boolean caseSensitive, Integer defaultValue,
			String... path); @Pure static Integer getAttributeColorWithDefault(Node document, Integer defaultValue, String... path); @Pure static Date getAttributeDate(Node document, boolean caseSensitive, String... path); @Pure static Date getAttributeDate(Node document, String... path); @Pure static Date getAttributeDateWithDefault(Node document, boolean caseSensitive, Date defaultValue, String... path); @Pure static Date getAttributeDateWithDefault(Node document, Date defaultValue, String... path); @Pure static double getAttributeDouble(Node document, boolean caseSensitive, String... path); @Pure static double getAttributeDouble(Node document, String... path); @Pure static Double getAttributeDoubleWithDefault(Node document, boolean caseSensitive, Double defaultValue,
			String... path); @Pure static Double getAttributeDoubleWithDefault(Node document, Double defaultValue, String... path); @Pure static T getAttributeEnum(Node document, Class<T> type, boolean caseSensitive, String... path); @Pure static T getAttributeEnum(Node document, Class<T> type, String... path); @Pure static T getAttributeEnumWithDefault(Node document, Class<T> type,
			boolean caseSensitive, T defaultValue, String... path); @Pure static T getAttributeEnumWithDefault(Node document, Class<T> type,
			T defaultValue, String... path); @Pure static float getAttributeFloat(Node document, boolean caseSensitive, String... path); @Pure static float getAttributeFloat(Node document, String... path); @Pure static Float getAttributeFloatWithDefault(Node document, boolean caseSensitive, Float defaultValue, String... path); @Pure static Float getAttributeFloatWithDefault(Node document, Float defaultValue, String... path); @Pure static int getAttributeInt(Node document, boolean caseSensitive, String... path); @Pure static int getAttributeInt(Node document, String... path); @Pure static Integer getAttributeIntWithDefault(Node document, boolean caseSensitive, Integer defaultValue, String... path); @Pure static Integer getAttributeIntWithDefault(Node document, Integer defaultValue, String... path); @Pure static long getAttributeLong(Node document, boolean caseSensitive, String... path); @Pure static long getAttributeLong(Node document, String... path); @Pure static Long getAttributeLongWithDefault(Node document, boolean caseSensitive, Long defaultValue, String... path); @Pure static Long getAttributeLongWithDefault(Node document, Long defaultValue, String... path); @Pure static URL getAttributeURL(Node document, boolean caseSensitive, String... path); @Pure static URL getAttributeURL(Node document, String... path); @Pure static URL getAttributeURLWithDefault(Node document, boolean caseSensitive, URL defaultValue, String... path); @Pure static URL getAttributeURLWithDefault(Node document, URL defaultValue, String... path); @Pure static UUID getAttributeUUID(Node document, boolean caseSensitive, String... path); @Pure static UUID getAttributeUUID(Node document, String... path); @Pure static List<UUID> getAttributeUUIDs(Node document, boolean caseSensitive, String... path); @Pure static List<UUID> getAttributeUUIDs(Node document, String... path); @Pure static UUID getAttributeUUIDWithDefault(Node document, boolean caseSensitive, UUID defaultValue, String... path); @Pure static UUID getAttributeUUIDWithDefault(Node document, UUID defaultValue, String... path); @Pure static String getAttributeValue(Node document, boolean casesSensitive, String... path); @Pure static String getAttributeValue(Node document, String... path); @Pure static String getAttributeValueWithDefault(Node document, boolean caseSensitive, String defaultValue,
			String... path); @Pure static String getAttributeValueWithDefault(Node document, String defaultValue, String... path); @Pure static T getChild(Node parent, Class<T> type); @Pure static Document getDocumentFor(Node node); @Pure static Element getElementFromPath(Node document, boolean caseSensitive, String... path); @Pure static Element getElementFromPath(Node document, String... path); @Pure static Element getElementMatching(Node document, XMLConstraint constraint, boolean caseSensitive, String... path); @Pure static Element getElementMatching(Node document, XMLConstraint constraint, String... path); @Pure static List<Element> getElementsFromPath(Node document, boolean caseSensitive, String... path); @Pure static List<Element> getElementsFromPath(Node document, String... path); @Pure static Node getNodeFromPath(Node document, boolean caseSensitive, String... path); @Pure static Node getNodeFromPath(Node document, String... path); @Pure static List<Node> getNodesFromPath(Node document, boolean caseSensitive, String... path); @Pure static List<Node> getNodesFromPath(Node document, String... path); @Pure static String getText(Node document, String... path); @Pure static Iterator<Node> iterate(Node parent, String nodeName); @Pure @SuppressWarnings({"checkstyle:magicnumber", "checkstyle:npathcomplexity"}) static int parseColor(String xmlColor); @Pure static Date parseDate(String xmlDate); @Pure static Object parseObject(String xmlSerializedObject); @Pure static byte[] parseString(String text); @Pure static Document parseXML(String xmlString); static Document readXML(File file); static Document readXML(InputStream stream); static Document readXML(Reader reader); static Document readXML(String file); static Document readXML(URL file); static DocumentFragment readXMLFragment(File file); static DocumentFragment readXMLFragment(File file, boolean skipRoot); static DocumentFragment readXMLFragment(InputStream stream); static DocumentFragment readXMLFragment(InputStream stream, boolean skipRoot); static DocumentFragment readXMLFragment(Reader reader); static DocumentFragment readXMLFragment(Reader reader, boolean skipRoot); static DocumentFragment readXMLFragment(String file); static DocumentFragment readXMLFragment(String file, boolean skipRoot); static DocumentFragment readXMLFragment(URL file); static DocumentFragment readXMLFragment(URL file, boolean skipRoot); static boolean setAttributeEnum(Node document, Class<T> type,
			boolean caseSensitive, T value, String... path); static boolean setAttributeEnum(Node document, Class<T> type, T value, String... path); @Pure @SuppressWarnings("checkstyle:magicnumber") static String toColor(int rgba); @Pure static String toColor(int red, int green, int blue, int alpha); @Pure static String toString(byte[] array); @Pure static String toString(Date date); @Pure static String toString(Node node); @Pure static String toString(Serializable object); static void writeXML(Document xmldocument, File file); static void writeXML(Document xmldocument, OutputStream stream); static void writeXML(Document xmldocument, String file); static void writeXML(Document xmldocument, Writer writer); static void writeXML(DocumentFragment fragment, File file); static void writeXML(DocumentFragment fragment, OutputStream stream); static void writeXML(DocumentFragment fragment, String file); static void writeXML(DocumentFragment fragment, Writer writer); static void writeXML(Node node, OutputStream stream); static void writeXML(Node node, Writer writer); static void writeResources(Element node, XMLResources resources, XMLBuilder builder); @SuppressWarnings({"checkstyle:nestedifdepth"}) static int readResources(Element node, XMLResources resources); @Pure static URL readResourceURL(Element node, XMLResources resources, String... path); static final String NODE_RESOURCE; static final String NODE_RESOURCES; static final String DATE_FORMAT; static final String ATTR_ID; static final String ATTR_NAME; static final String ATTR_COLOR; static final String ATTR_URL; static final String ATTR_MIMETYPE; static final String ATTR_FILE; }
@Test public void getAttributeValueNodeBooleanStringArray() { assertEquals("B", XMLUtil.getAttributeValue(this.document, true, "catalog", "book", "publish", "enum1")); assertEquals("", XMLUtil.getAttributeValue(this.document, true, "catalog", "book", "publish", "Enum1")); assertEquals("B", XMLUtil.getAttributeValue(this.document, false, "catalog", "book", "publish", "enum1")); assertEquals("B", XMLUtil.getAttributeValue(this.document, false, "catalog", "book", "publish", "Enum1")); assertEquals("b", XMLUtil.getAttributeValue(this.document, true, "catalog", "book", "genre", "enum2")); assertEquals("", XMLUtil.getAttributeValue(this.document, true, "catalog", "book", "genre", "Enum2")); assertEquals("b", XMLUtil.getAttributeValue(this.document, false, "catalog", "book", "genre", "enum2")); assertEquals("b", XMLUtil.getAttributeValue(this.document, false, "catalog", "book", "genre", "Enum2")); }
@Test public void getAttributeValueNodeStringArray() { assertEquals("B", XMLUtil.getAttributeValue(this.document, "catalog", "book", "publish", "enum1")); assertEquals("", XMLUtil.getAttributeValue(this.document, "catalog", "book", "publish", "Enum1")); assertEquals("b", XMLUtil.getAttributeValue(this.document, "catalog", "book", "genre", "enum2")); assertEquals("", XMLUtil.getAttributeValue(this.document, "catalog", "book", "genre", "Enum2")); }