/** * Replaces ${system.property[:default value]} references in all attributes * and text nodes of supplied node. If the system property is not defined and no * default value is provided, a runtime exception is thrown. * * @param node DOM node to walk for substitutions */ public static void substituteSystemProperties(Node node) { substituteProperties(node, null); }
/** * Replaces ${property[:default value]} references in all attributes * and text nodes of supplied node. If the property is not defined neither in the * given Properties instance nor in System.getProperty and no * default value is provided, a runtime exception is thrown. * * @param node DOM node to walk for substitutions * @param properties the Properties instance from which a value can be looked up */ public static void substituteProperties(Node node, Properties properties) { // loop through child nodes Node child; Node next = node.getFirstChild(); while ((child = next) != null) { // set next before we change anything next = child.getNextSibling(); // handle child by node type if (child.getNodeType() == Node.TEXT_NODE) { child.setNodeValue(substituteProperty(child.getNodeValue(), properties)); } else if (child.getNodeType() == Node.ELEMENT_NODE) { // handle child elements with recursive call NamedNodeMap attributes = child.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { Node attribute = attributes.item(i); attribute.setNodeValue(substituteProperty(attribute.getNodeValue(), properties)); } substituteProperties(child, properties); } } }
DOMUtil.substituteProperties(doc, loader.getCoreProperties()); } catch (ParserConfigurationException e) { SolrException.log(log, "Exception during parsing file: " + name, e);