/** * Gets the single node. * * @param filename the filename * @param parent the parent * @param name the name * @return the single node * @throws Exception the exception */ public static Node getSingleNode(String filename, Element parent, String name) throws Exception { NodeList nodes = getImmediateChildrenByTagName(parent, name); if (nodes.getLength() == 0) { return null; } if (nodes.getLength() > 1) { throwError(filename, "Extra element values seen for element " + name); } return nodes.item(0); }
/** * Gets the required attribute. * * @param filename the filename * @param element the element * @param name the name * @return the required attribute * @throws Exception the exception */ public static String getRequiredAttribute(String filename, Element element, String name) throws Exception { String value = element.getAttribute(name); if (value == null || value.length() == 0) { throwError( filename, "Missing required attribute '" + name + "' on element '" + element.getTagName() + "'"); } return value; }
/** * Gets the element text. * * @param filename the filename * @param parent the parent * @param name the name * @param isRequired the is required * @return the element text * @throws Exception the exception */ public static String getElementText( String filename, Element parent, String name, boolean isRequired) throws Exception { Element node = getSingleElement(filename, parent, name); if (node == null) { if (!isRequired) { return null; } throwError(filename, "Missing required element: '" + name + "'"); } return getText(node); }
/** * Put nv list. * * @param filename the filename * @param containerName the container name * @param optionContainer the option container * @param outList the out list * @throws Exception the exception */ public static void putNVList( String filename, String containerName, Element optionContainer, List<NameValue> outList) throws Exception { NodeList childElements = DomParseUtil.getImmediateChildrenByTagName(optionContainer, "option"); if (childElements == null) { return; } for (int i = 0; i < childElements.getLength(); i++) { Element option = (Element) childElements.item(i); String name = option.getAttribute("name"); if (name == null || name.length() == 0) { throwError(filename, "Missing option name in option list: '" + containerName + "'"); } String value = DomParseUtil.getText(option); if (value == null) { throwError(filename, "Missing option value for option list: '" + containerName + "'"); } NameValue nv = new NameValue(); nv.setName(name); nv.setValue(value); outList.add(nv); } }