/** * Check whether the allowed items are present in the current node as elements or attributes. * * @param node the current Node object * @param allowed the String array of the allowed items **/ public void allowedAttributesOrElements(Node node, String[] allowed) { allowedAttributes(node, allowed); allowedChildElements(node, allowed); }
public String getAttributeOrChildElement(Node node, String name) { String attr = evaluateExpression(node, "@" + name).toString().trim(); if (attr.length() == 0) { attr = evaluateExpression(node, name).toString().trim(); } return attr; }
private String getSourceFilename(Node node) { return getSourceFileOf(node); }
public void parse(String path, ConfigurationFileResolver fileResolver, ServicesConfiguration config) { this.config = config; this.fileResolver = fileResolver; Document doc = loadDocument(path, fileResolver.getConfigurationFile(path)); initializeExpressionQuery(); parseTopLevelConfig(doc); }
public void allowedAttributes(Node node, String[] allowed) { NodeList attributes = selectNodeList(node, "@*"); String unexpectedAttribute = unexpected(attributes, allowed); if (unexpectedAttribute != null) { //Unexpected attribute '{0}' found in '{1}'. ConfigurationException ex = new ConfigurationException(); Object[] args = {unexpectedAttribute, node.getNodeName(), getSourceFilename(node)}; ex.setMessage(UNEXPECTED_ATTRIBUTE, args); throw ex; } }
public void allowedChildElements(Node node, String[] allowed) { NodeList children = selectNodeList(node, "*"); String unexpected = unexpected(children, allowed); if (unexpected != null) { // Unexpected child element '{0}' found in '{1}'. ConfigurationException ex = new ConfigurationException(); Object[] args = {unexpected, node.getNodeName(), getSourceFilename(node)}; ex.setMessage(UNEXPECTED_ELEMENT, args); throw ex; } NodeList textNodes = selectNodeList(node, "text()"); for (int i = 0; i < textNodes.getLength(); i++) { String text = evaluateExpression(textNodes.item(i), ".").toString().trim(); if (text.length() > 0) { //Unexpected text '{0}' found in '{1}'. ConfigurationException ex = new ConfigurationException(); Object[] args = {text, node.getNodeName(), getSourceFilename(node)}; ex.setMessage(UNEXPECTED_TEXT, args); throw ex; } } }
if (prop.getNodeType() == Node.ELEMENT_NODE) NodeList attributes = selectNodeList(prop, "@*"); NodeList children = selectNodeList(prop, "*"); if (children.getLength() > 0 || attributes.getLength() > 0) childMap.addProperties(properties(children, sourceFileName)); childMap.addProperties(properties(attributes, sourceFileName)); String propValue = evaluateExpression(prop, ".").toString(); map.addProperty(propName, propValue);
/** * @return Name of the first missing item from the list of required attributes, or null if all required * items were present. */ public String required(NodeList attributes, List required) { for (int i = 0; i < required.size(); i++) { boolean found = false; String req = (String)required.get(i); Node attrib = null; for (int j = 0; j < attributes.getLength(); j++) { attrib = attributes.item(j); String attribName = attrib.getNodeName(); if (req.equals(attribName)) { found = true; break; } } if (!found) { return req; } // Go ahead and replace tokens in node values. tokenReplacer.replaceToken(attrib, getSourceFilename(attrib)); } return null; }
protected AbstractConfigurationParser() { initializeDocumentBuilder(); tokenReplacer = new TokenReplacer(); }
addFileByDocument(path, doc); doc.getDocumentElement().normalize(); return doc;
NodeList children = selectNodeList(node, "*"); String unexpected = unexpected(children, allowed); if (unexpected != null) Object[] args = {unexpected, node.getNodeName(), getSourceFilename(node)}; ex.setMessage(UNEXPECTED_ELEMENT, args); throw ex; NodeList textNodes = selectNodeList(node, "text()"); for (int i = 0; i < textNodes.getLength(); i++) String text = evaluateExpression(textNodes.item(i), ".").toString().trim(); if (text.length() > 0) Object[] args = {text, node.getNodeName(), getSourceFilename(node)}; ex.setMessage(UNEXPECTED_TEXT, args); throw ex;
/** * Parse the configurations in the configuration file. * * @param path the configuration file path * @param fileResolver the ConfigurationFileResolver object * @param config the ServicesConfiguration object **/ public void parse(String path, ConfigurationFileResolver fileResolver, ServicesConfiguration config) { this.config = config; this.fileResolver = fileResolver; Document doc = loadDocument(path, fileResolver.getConfigurationFile(path)); initializeExpressionQuery(); parseTopLevelConfig(doc); }
/** * Check whether the required items are present in the current node as attributes. * * @param node the current Node object * @param allowed the String array of the allowed items **/ public void allowedAttributes(Node node, String[] allowed) { NodeList attributes = selectNodeList(node, "@*"); String unexpectedAttribute = unexpected(attributes, allowed); if (unexpectedAttribute != null) { //Unexpected attribute '{0}' found in '{1}'. ConfigurationException ex = new ConfigurationException(); Object[] args = {unexpectedAttribute, node.getNodeName(), getSourceFilename(node)}; ex.setMessage(UNEXPECTED_ATTRIBUTE, args); throw ex; } }
if (prop.getNodeType() == Node.ELEMENT_NODE) NodeList attributes = selectNodeList(prop, "@*"); NodeList children = selectNodeList(prop, "*"); if (children.getLength() > 0 || attributes.getLength() > 0) childMap.addProperties(properties(children, sourceFileName)); childMap.addProperties(properties(attributes, sourceFileName)); String propValue = evaluateExpression(prop, ".").toString(); map.addProperty(propName, propValue);
/** * @return Name of the first unexpected item from the list of allowed attributes, or null if all * items present were allowed. */ public String unexpected(NodeList attributes, String[] allowed) { for (int i = 0; i < attributes.getLength(); i++) { Node attrib = attributes.item(i); String attribName = attrib.getNodeName(); boolean match = false; for (int j = 0; j < allowed.length; j++) { String a = allowed[j]; if (a.equals(attribName)) { match = true; break; } } if (!match) { return attribName; } // Go ahead and replace tokens in node values. tokenReplacer.replaceToken(attrib, getSourceFilename(attrib)); } return null; }
protected AbstractConfigurationParser() { initializeDocumentBuilder(); tokenReplacer = new TokenReplacer(); }
addFileByDocument(path, doc); doc.getDocumentElement().normalize(); return doc;
NodeList children = selectNodeList(node, "*"); String unexpected = unexpected(children, allowed); if (unexpected != null) Object[] args = {unexpected, node.getNodeName(), getSourceFilename(node)}; ex.setMessage(UNEXPECTED_ELEMENT, args); throw ex; NodeList textNodes = selectNodeList(node, "text()"); for (int i = 0; i < textNodes.getLength(); i++) String text = evaluateExpression(textNodes.item(i), ".").toString().trim(); if (text.length() > 0) Object[] args = {text, node.getNodeName(), getSourceFilename(node)}; ex.setMessage(UNEXPECTED_TEXT, args); throw ex;
/** * Parse the configurations in the configuration file. * * @param path the configuration file path * @param fileResolver the ConfigurationFileResolver object * @param config the ServicesConfiguration object **/ public void parse(String path, ConfigurationFileResolver fileResolver, ServicesConfiguration config) { this.config = config; this.fileResolver = fileResolver; Document doc = loadDocument(path, fileResolver.getConfigurationFile(path)); initializeExpressionQuery(); parseTopLevelConfig(doc); }
/** * Check whether the required items are present in the current node as attributes. * * @param node the current Node object * @param allowed the String array of the allowed items **/ public void allowedAttributes(Node node, String[] allowed) { NodeList attributes = selectNodeList(node, "@*"); String unexpectedAttribute = unexpected(attributes, allowed); if (unexpectedAttribute != null) { //Unexpected attribute '{0}' found in '{1}'. ConfigurationException ex = new ConfigurationException(); Object[] args = {unexpectedAttribute, node.getNodeName(), getSourceFilename(node)}; ex.setMessage(UNEXPECTED_ATTRIBUTE, args); throw ex; } }