private void initProperties() { List<ConfigurationNode> nodes = getRootNode().getChildren(); if (nodes == null || nodes.isEmpty()) { return; } for (ConfigurationNode p : nodes) { String name = (String) p.getChildren("name").get(0).getValue(); String value = (String) p.getChildren("value").get(0).getValue(); if (!StringUtils.isEmpty(name)) { properties.put(name, value); } } }
protected Object saveHierarchy(final ConfigurationNode parentNode) { if (parentNode.getChildrenCount() == 0) return parentNode.getValue(); if (parentNode.getChildrenCount("item") == parentNode.getChildrenCount()) { return parentNode.getChildren().stream().map(this::saveHierarchy).collect(Collectors.toList()); } else { final Map<String, Object> map = new LinkedHashMap<>(); for (ConfigurationNode childNode : parentNode.getChildren()) { String nodeName = childNode.getName(); if (this.xmlCompatibility && childNode.getAttributes("name").size() > 0) nodeName = String.valueOf(childNode.getAttributes("name").get(0).getValue()); map.put(nodeName, saveHierarchy(childNode)); } return map; } } }
public static void main(String[] args) throws ConfigurationException, InterruptedException { E.checkArgument(args.length == 1, "Init store only accept one config file."); E.checkArgument(args[0].endsWith(".yaml"), "Init store only accept yaml config file."); String confFile = args[0]; RegisterUtil.registerBackends(); YamlConfiguration config = new YamlConfiguration(); config.load(confFile); List<ConfigurationNode> nodes = config.getRootNode() .getChildren(GRAPHS); E.checkArgument(nodes.size() == 1, "Must contain one '%s' in config file '%s'", GRAPHS, confFile); List<ConfigurationNode> graphNames = nodes.get(0).getChildren(); E.checkArgument(!graphNames.isEmpty(), "Must contain at least one graph"); for (ConfigurationNode graphName : graphNames) { String configPath = graphName.getValue().toString(); initGraph(configPath); } HugeGraph.shutdown(30L); }
protected ServiceEnvironmentImpl.MessagesProvider getMP() { if (messagesProvider == null) { if (0 < cn.getChildrenCount(OA4MPConfigTags.MESSAGES)) { messagesProvider = new ServiceEnvironmentImpl.MessagesProvider(((ConfigurationNode) cn.getChildren(OA4MPConfigTags.MESSAGES).get(0))); } } return messagesProvider; }
/** * Return the first named child configuration node of the given node or null if there is * no such named child. Very useful if your specification only allows for a single child node. * * @param node * @param name * @return */ public static ConfigurationNode getFirstNode(ConfigurationNode node, String name) { List list = node.getChildren(name); if (list.isEmpty()) { return null; } return ((ConfigurationNode) list.get(0)); }
protected MailUtilProvider getMailUtilProvider() { if (mup == null) { if (0 < cn.getChildrenCount(OA4MPConfigTags.MAIL)) { mup = new ServletMailUtilProvider(((ConfigurationNode) cn.getChildren(OA4MPConfigTags.MAIL).get(0))); } else { mup = new ServletMailUtilProvider(); } } return mup; }
/** * Does this have the named component? In other words, is there * a configuration of this name one level down? * * @param name * @return */ public boolean hasA(String name) { return 0 < getConfig().getChildren(name).size(); }
protected Object saveHierarchy(final ConfigurationNode parentNode) { if (parentNode.getChildrenCount() == 0) return parentNode.getValue(); if (parentNode.getChildrenCount("item") == parentNode.getChildrenCount()) { return parentNode.getChildren().stream().map(this::saveHierarchy).collect(Collectors.toList()); } else { final Map<String, Object> map = new LinkedHashMap<>(); for (ConfigurationNode childNode : parentNode.getChildren()) { String nodeName = childNode.getName(); if (this.xmlCompatibility && childNode.getAttributes("name").size() > 0) nodeName = String.valueOf(childNode.getAttributes("name").get(0).getValue()); map.put(nodeName, saveHierarchy(childNode)); } return map; } } }
/** * Return the given configuration * * @param name * @return */ public ConfigurationNode getConfigurationAt(String name) { List list = getConfig().getChildren(name); if(list.isEmpty()){ return null; } return (ConfigurationNode) list.get(0); }
protected Object saveHierarchy(final ConfigurationNode parentNode) { if (parentNode.getChildrenCount() == 0) return parentNode.getValue(); if (parentNode.getChildrenCount("item") == parentNode.getChildrenCount()) { return parentNode.getChildren().stream().map(this::saveHierarchy).collect(Collectors.toList()); } else { final Map<String, Object> map = new LinkedHashMap<>(); for (ConfigurationNode childNode : parentNode.getChildren()) { String nodeName = childNode.getName(); if (this.xmlCompatibility && childNode.getAttributes("name").size() > 0) nodeName = String.valueOf(childNode.getAttributes("name").get(0).getValue()); map.put(nodeName, saveHierarchy(childNode)); } return map; } } }
/** * Adds all child nodes of the given source node to this view node. * * @param source the source node */ public void appendChildren(ConfigurationNode source) { if (source != null) { for (ConfigurationNode child : source.getChildren()) { addChild(child); } } } }
/** * Adds all child nodes of the given source node to this view node. * * @param source the source node */ public void appendChildren(ConfigurationNode source) { if (source != null) { for (ConfigurationNode child : source.getChildren()) { addChild(child); } } } }
/** * Returns a list with {@code SubnodeConfiguration} objects for the * child nodes of the specified configuration node. * * @param node the start node * @return a list with subnode configurations for the node's children */ private List<SubnodeConfiguration> fetchChildConfigs(ConfigurationNode node) { List<ConfigurationNode> children = node.getChildren(); List<SubnodeConfiguration> result = new ArrayList<SubnodeConfiguration>(children.size()); for (ConfigurationNode child : children) { result.add(createSubnodeConfiguration(child)); } return result; }
private void skipNode(ConfigurationNode nodePtr) { List<ConfigurationNode> children = nodePtr.getChildren(); for (int i = 0; i < children.size(); i++) { ConfigurationNode configNodeChild = children.get(i); if( configNodeChild.getAttributeCount() > 0 ) { continue; } else { skipNode(configNodeChild); } } }
XMLConfiguration config = new XMLConfiguration("_config.xml"); Map<String, String> configMap = new HashMap<String, String>(); ConfigurationNode node = config.getRootNode(); for (ConfigurationNode c : node.getChildren("entry")) { String key = (String)c.getAttribute(0).getValue(); String value = (String)c.getValue(); configMap.put(key, value); }
@Override protected boolean checkEvent(CfgEvent cfgEvent) { if (cfgEvent.getConfiguration().getName().equals(getType()) && !cfgEvent.getConfiguration().getChildren(getTarget()).isEmpty()) { setTypeConfig(cfgEvent.getConfiguration()); setConfig((ConfigurationNode) cfgEvent.getConfiguration().getChildren(getTarget()).get(0)); return true; } return false; }
public static boolean iterateAllKeys(ConfigKeyFactory factory, HierarchicalConfiguration config, ConfigKeyHandler handler) { List<ConfigurationNode> configNodes = config.getRootNode().getChildren(); for (ConfigurationNode node : configNodes) { ConfigKey key = factory.generateByPropertiesKey(node.getName()); if (!handler.handle(key)) { return true; } } return false; }
/** * Prints all configuration values. Is the actual execution of the 'get-all' action ('-a', '--all') */ private void printAllValues() { List<ConfigurationNode> configNodes = keysConfig.getRootNode().getChildren(); for (ConfigurationNode node : configNodes) { ConfigKey key = configKeyFactory.generateByPropertiesKey(node.getName()); // TODO - move to one statement for all - time permitting; try { printAllValuesForKey(key.getKey()); } catch (Exception exception) { log.error("Error while retrieving value for key \"{}\".", key.getKey(), exception); } } }
/** * Prints all reloadable configuration keys. Is the actual execution of the 'list' action ('-l', '--list') with the * --only-reloadable flag */ public void printReloadableKeys() { List<ConfigurationNode> configNodes = keysConfig.getRootNode().getChildren(); for (ConfigurationNode node : configNodes) { ConfigKey key = configKeyFactory.generateByPropertiesKey(node.getName()); if (key.isReloadable()) { printKeyInFormat(key); } } }
protected void printNodes(ConfigurationNode root) { for (Object kid : root.getChildren()) { ConfigurationNode cn = (ConfigurationNode) kid; say("key=" + cn.getName() + ", value=" + cn.getValue()); printNodes(cn); } }