List of usage examples for org.apache.commons.configuration.tree ConfigurationNode addChild
void addChild(ConfigurationNode node);
From source file:com.intuit.tank.proxy.config.CommonsProxyConfiguration.java
public static void updateRuleParentNode(Set<ConfigInclusionExclusionRule> rule, ConfigurationNode parentNode) { for (ConfigInclusionExclusionRule configInclusionExclusionRule : rule) { ConfigurationNode ruleNode = getConfNode("rule", configInclusionExclusionRule.getValue(), false); ConfigurationNode checkNode = getConfNode("check", configInclusionExclusionRule.getTransactionPart().toString(), true); ConfigurationNode matchNode = getConfNode("match", configInclusionExclusionRule.getMatch().toString(), true);//from ww w . j a v a 2 s .com ConfigurationNode headerNode = getConfNode("header", configInclusionExclusionRule.getHeader(), true); ruleNode.addAttribute(checkNode); ruleNode.addAttribute(matchNode); ruleNode.addAttribute(headerNode); parentNode.addChild(ruleNode); } }
From source file:com.intuit.tank.proxy.config.CommonsProxyConfiguration.java
public static boolean save(int port, boolean followRedirect, String outputFile, Set<ConfigInclusionExclusionRule> inclusions, Set<ConfigInclusionExclusionRule> exclusions, Set<ConfigInclusionExclusionRule> bodyInclusions, Set<ConfigInclusionExclusionRule> bodyExclusions, String fileName) {//from ww w .j a v a 2s . c o m ConfigurationNode node = getConfNode("recording-proxy-config", "", false); ConfigurationNode portNode = getConfNode("proxy-port", String.valueOf(port), false); ConfigurationNode followRedirectNode = getConfNode("follow-redirects", Boolean.toString(followRedirect), false); ConfigurationNode outputFileNode = getConfNode("output-file", outputFile, false); ConfigurationNode inclusionsNode = getConfNode("inclusions", "", false); ConfigurationNode exclusionsNode = getConfNode("exclusions", "", false); ConfigurationNode bodyInclusionsNode = getConfNode("body-inclusions", "", false); ConfigurationNode bodyExclusionsNode = getConfNode("body-exclusions", "", false); updateRuleParentNode(inclusions, inclusionsNode); updateRuleParentNode(exclusions, exclusionsNode); updateRuleParentNode(bodyInclusions, bodyInclusionsNode); updateRuleParentNode(bodyExclusions, bodyExclusionsNode); node.addChild(portNode); node.addChild(followRedirectNode); node.addChild(outputFileNode); node.addChild(inclusionsNode); node.addChild(exclusionsNode); node.addChild(bodyInclusionsNode); node.addChild(bodyExclusionsNode); HierarchicalConfiguration hc = new HierarchicalConfiguration(); hc.setRootNode(node); XMLConfiguration xmlConfiguration = new XMLConfiguration(hc); xmlConfiguration.setRootNode(node); try { xmlConfiguration.save(new File(fileName)); } catch (ConfigurationException e) { e.printStackTrace(); } return true; }
From source file:com.github.mbredel.commons.configuration.YAMLConfiguration.java
/** * Constructs the internal configuration nodes hierarchy. * * @param node The configuration node that is the root of the current configuration section. * @param map The map with the yaml configurations nodes, i.e. String -> Object. *//* w w w .j av a 2s . c om*/ @SuppressWarnings("unchecked") private void constructHierarchy(ConfigurationNode node, Map<String, Object> map) { for (Map.Entry<String, Object> entry : map.entrySet()) { String key = entry.getKey(); Object value = entry.getValue(); if (value instanceof Map) { ConfigurationNode treeNode = createNode(key); constructHierarchy(treeNode, (Map) value); node.addChild(treeNode); } else { ConfigurationNode leaveNode = createNode(key); leaveNode.setValue(value); node.addChild(leaveNode); } } }
From source file:org.apache.tinkerpop.gremlin.util.config.YamlConfiguration.java
protected void loadHierarchy(final ConfigurationNode parentNode, final Object obj) { final String parentName = parentNode.getName(); if (obj instanceof Map<?, ?>) { for (Map.Entry<String, Object> entry : ((Map<String, Object>) obj).entrySet()) { final Node childNode = new Node(entry.getKey()); // if parent node is look like "tableS", "userS" or "groupS" if (this.xmlCompatibility && parentName != null && parentName.endsWith("s")) { //this is done to have "users.user[@name='smith'] instead of "users.smith" childNode.setName(parentName.substring(0, parentName.length() - 1)); childNode.addAttribute(new Node("name", entry.getKey())); }//w w w . jav a 2 s . c o m childNode.setReference(entry); loadHierarchy(childNode, entry.getValue()); parentNode.addChild(childNode); } } else if (obj instanceof Collection) { for (Object child : (Collection) obj) { final Node childNode = new Node("item"); childNode.setReference(child); loadHierarchy(childNode, child); parentNode.addChild(childNode); } } parentNode.setValue(obj); }
From source file:org.lable.oss.dynamicconfig.serialization.yaml.YamlDeserializer.java
/** * Process a node in the object tree, and store it with its parent node in the Config tree. * <p>/* w w w . j ava 2 s . c om*/ * This method recursively calls itself to walk an object tree. * * @param parent Parent of the current node, as represented in the Config tree. * @param node Node to process. */ void traverseTreeAndLoad(ConfigurationNode parent, Object node) { if (node instanceof Map<?, ?>) { // It is not feasible for this class to check this cast, but it is guaranteed by the // yaml.load() call that it is a Map<String, Object>. @SuppressWarnings("unchecked") Map<String, Object> map = (Map<String, Object>) node; for (Map.Entry<String, Object> entry : map.entrySet()) { HierarchicalConfiguration.Node child = new HierarchicalConfiguration.Node(entry.getKey()); child.setReference(entry); // Walk the complete tree. traverseTreeAndLoad(child, entry.getValue()); parent.addChild(child); } } else { // This works for both primitives and lists. parent.setValue(node); } }