org.apache.commons.configuration.tree.ConfigurationNode Java Examples

The following examples show how to use org.apache.commons.configuration.tree.ConfigurationNode. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VarOneConfiguration.java    From varOne with MIT License 5 votes vote down vote up
private int getIntValue(String name, int d) {
	List<ConfigurationNode> properties = getRootNode().getChildren();
	if (properties == null || properties.size() == 0) {
		return d;
	}
	for (ConfigurationNode p : properties) {
		if (p.getChildren("name") != null && p.getChildren("name").size() > 0 
				&& name.equals(((ConfigurationNode) p.getChildren("name").get(0)).getValue())) {
			return Integer.parseInt((String) ((ConfigurationNode) p.getChildren("value").get(0)).getValue());
		}
	}
	return d;	
}
 
Example #2
Source File: ExplorerConfiguration.java    From Explorer with Apache License 2.0 5 votes vote down vote up
private boolean getBooleanValue(String name, boolean d){
	List<ConfigurationNode> properties = getRootNode().getChildren();
	if(properties==null || properties.size()==0) return d;
	for(ConfigurationNode p : properties){
		if(p.getChildren("name")!=null && p.getChildren("name").size()>0 && name.equals(p.getChildren("name").get(0).getValue())){
			return Boolean.parseBoolean((String) p.getChildren("value").get(0).getValue());
		}
	}
	return d;
}
 
Example #3
Source File: ExplorerConfiguration.java    From Explorer with Apache License 2.0 5 votes vote down vote up
private float getFloatValue(String name, float d){
	List<ConfigurationNode> properties = getRootNode().getChildren();
	if(properties==null || properties.size()==0) return d;
	for(ConfigurationNode p : properties){
		if(p.getChildren("name")!=null && p.getChildren("name").size()>0 && name.equals(p.getChildren("name").get(0).getValue())){
			return Float.parseFloat((String) p.getChildren("value").get(0).getValue());
		}
	}
	return d;
}
 
Example #4
Source File: ExplorerConfiguration.java    From Explorer with Apache License 2.0 5 votes vote down vote up
private long getLongValue(String name, long d){
	List<ConfigurationNode> properties = getRootNode().getChildren();
	if(properties==null || properties.size()==0) return d;
	for(ConfigurationNode p : properties){
		if(p.getChildren("name")!=null && p.getChildren("name").size()>0 && name.equals(p.getChildren("name").get(0).getValue())){
			return Long.parseLong((String) p.getChildren("value").get(0).getValue());
		}
	}
	return d;
}
 
Example #5
Source File: ExplorerConfiguration.java    From Explorer with Apache License 2.0 5 votes vote down vote up
private int getIntValue(String name, int d){
	List<ConfigurationNode> properties = getRootNode().getChildren();
	if(properties==null || properties.size()==0) return d;
	for(ConfigurationNode p : properties){
		if(p.getChildren("name")!=null && p.getChildren("name").size()>0 && name.equals(p.getChildren("name").get(0).getValue())){
			return Integer.parseInt((String) p.getChildren("value").get(0).getValue());
		}
	}
	return d;
}
 
Example #6
Source File: ExplorerConfiguration.java    From Explorer with Apache License 2.0 5 votes vote down vote up
private String getStringValue(String name, String d){
	List<ConfigurationNode> properties = getRootNode().getChildren();
	if(properties==null || properties.size()==0) return d;
	for(ConfigurationNode p : properties){
		if(p.getChildren("name")!=null && p.getChildren("name").size()>0 && name.equals(p.getChildren("name").get(0).getValue())){
			return (String) p.getChildren("value").get(0).getValue();
		}
	}
	return d;
}
 
Example #7
Source File: XmlConfigParser.java    From onos with Apache License 2.0 5 votes vote down vote up
public static String createControllersConfig(HierarchicalConfiguration cfg,
                                             HierarchicalConfiguration actualCfg,
                                             String target, String netconfOperation,
                                             String controllerOperation,
                                             List<ControllerInfo> controllers) {
    //cfg.getKeys().forEachRemaining(key -> System.out.println(key));
    cfg.setProperty("edit-config.target", target);
    cfg.setProperty("edit-config.default-operation", netconfOperation);
    cfg.setProperty("edit-config.config.capable-switch.id",
            parseCapableSwitchId(actualCfg));
    cfg.setProperty("edit-config.config.capable-switch." +
            "logical-switches.switch.id", parseSwitchId(actualCfg));
    List<ConfigurationNode> newControllers = new ArrayList<>();
    for (ControllerInfo ci : controllers) {
        XMLConfiguration controller = new XMLConfiguration();
        controller.setRoot(new HierarchicalConfiguration.Node("controller"));
        String id = ci.type() + ":" + ci.ip() + ":" + ci.port();
        controller.setProperty("id", id);
        controller.setProperty("ip-address", ci.ip());
        controller.setProperty("port", ci.port());
        controller.setProperty("protocol", ci.type());
        newControllers.add(controller.getRootNode());
    }
    cfg.addNodes("edit-config.config.capable-switch.logical-switches." +
            "switch.controllers", newControllers);
    XMLConfiguration editcfg = (XMLConfiguration) cfg;
    StringWriter stringWriter = new StringWriter();
    try {
        editcfg.save(stringWriter);
    } catch (ConfigurationException e) {
        log.error("createControllersConfig()", e);
    }
    String s = stringWriter.toString()
            .replaceAll("<controller>",
                    "<controller nc:operation=\"" + controllerOperation + "\">");
    s = s.replace("<target>" + target + "</target>",
            "<target><" + target + "/></target>");
    return s;

}
 
Example #8
Source File: YangXmlUtils.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves a valid XML configuration for a specific XML path for multiple
 * instance of YangElements objects.
 *
 * @param file     path of the file to be used.
 * @param elements List of YangElements that are to be set.
 * @return Hierachical configuration containing XML with values.
 */
public XMLConfiguration getXmlConfiguration(String file, List<YangElement> elements) {
    InputStream stream = getCfgInputStream(file);
    HierarchicalConfiguration cfg = loadXml(stream);
    XMLConfiguration complete = new XMLConfiguration();
    Multimap<String, YangElement> commonElements = ArrayListMultimap.create();

    //saves the elements in a Multimap based on the computed key.
    elements.forEach(element -> {
        String completeKey = nullIsNotFound(findPath(cfg, element.getBaseKey()),
                                            "Yang model does not contain desired path");
        commonElements.put(completeKey, element);
    });

    //iterates over the elements and constructs the configuration
    commonElements.keySet().forEach(key -> {
        // if there is more than one element for a given path
        if (commonElements.get(key).size() > 1) {
            //creates a list of nodes that have to be added for that specific path
            ArrayList<ConfigurationNode> nodes = new ArrayList<>();
            //creates the nodes
            commonElements.get(key).forEach(element -> nodes.add(getInnerNode(element).getRootNode()));
            //computes the parent path
            String parentPath = key.substring(0, key.lastIndexOf("."));
            //adds the nodes to the complete configuration
            complete.addNodes(parentPath, nodes);
        } else {
            //since there is only a single element we can assume it's the first one.
            Map<String, String> keysAndValues = commonElements.get(key).stream().
                    findFirst().get().getKeysAndValues();
            keysAndValues.forEach((k, v) -> complete.setProperty(key + "." + k, v));
        }
    });
    addProperties(cfg, complete);
    return complete;
}
 
Example #9
Source File: VarOnedConfiguration.java    From varOne with MIT License 5 votes vote down vote up
public String getStringValue(String name, String d) {
	List<ConfigurationNode> properties = getRootNode().getChildren();
	if (properties == null || properties.size() == 0) {
		return d;
	}
	for (ConfigurationNode p : properties) {
		if (p.getChildren("name") != null && p.getChildren("name").size() > 0 
				&& name.equals(((ConfigurationNode) p.getChildren("name").get(0)).getValue())) {
			return (String) ((ConfigurationNode) p.getChildren("value").get(0)).getValue();
		}
	}
	return d;
}
 
Example #10
Source File: VarOneConfiguration.java    From varOne with MIT License 5 votes vote down vote up
private boolean getBooleanValue(String name, boolean d) {
	List<ConfigurationNode> properties = getRootNode().getChildren();
	if (properties == null || properties.size() == 0) {
		return d;
	}
	for (ConfigurationNode p : properties) {
		if (p.getChildren("name") != null && p.getChildren("name").size() > 0 
				&& name.equals(((ConfigurationNode) p.getChildren("name").get(0)).getValue())) {
			return Boolean.parseBoolean((String) ((ConfigurationNode) p.getChildren("value").get(0)).getValue());	
		}	
	}
	return d;	
}
 
Example #11
Source File: VarOneConfiguration.java    From varOne with MIT License 5 votes vote down vote up
private float getFloatValue(String name, float d) {
	List<ConfigurationNode> properties = getRootNode().getChildren();
	if (properties == null || properties.size() == 0) {
		return d;
	}
	for (ConfigurationNode p : properties) {
		if (p.getChildren("name") != null && p.getChildren("name").size() > 0 
				&& name.equals(((ConfigurationNode) p.getChildren("name").get(0)).getValue())) {
			return Float.parseFloat((String) ((ConfigurationNode) p.getChildren("value").get(0)).getValue());
		}
	}
	return d;	
}
 
Example #12
Source File: VarOneConfiguration.java    From varOne with MIT License 5 votes vote down vote up
private long getLongValue(String name, long d) {
	List<ConfigurationNode> properties = getRootNode().getChildren();
	if (properties == null || properties.size() == 0) {
		return d;
	}
	for (ConfigurationNode p : properties) {
		if (p.getChildren("name") != null && p.getChildren("name").size() > 0 
				&& name.equals(((ConfigurationNode) p.getChildren("name").get(0)).getValue())) {
			return Long.parseLong((String) ((ConfigurationNode) p.getChildren("value").get(0)).getValue());
		}
	}
	return d;	
}
 
Example #13
Source File: SubmarineConfiguration.java    From submarine with Apache License 2.0 5 votes vote down vote up
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);
    }
  }
}
 
Example #14
Source File: VarOneConfiguration.java    From varOne with MIT License 5 votes vote down vote up
private String getStringValue(String name, String d) {
	List<ConfigurationNode> properties = getRootNode().getChildren();
	if (properties == null || properties.size() == 0) {
		return d;
	}
	for (ConfigurationNode p : properties) {
		if (p.getChildren("name") != null && p.getChildren("name").size() > 0 
				&& name.equals(((ConfigurationNode) p.getChildren("name").get(0)).getValue())) {
			return (String) ((ConfigurationNode) p.getChildren("value").get(0)).getValue();
		}
	}
	return d;
}
 
Example #15
Source File: ZeppelinConfiguration.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
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);
    }
  }
}
 
Example #16
Source File: Yfiton.java    From yfiton with Apache License 2.0 5 votes vote down vote up
private Map<String, Map<String, String>> loadPreferences(HierarchicalINIConfiguration configuration, Notifier notifier) {
    Set<String> sections = configuration.getSections();

    return sections.stream().filter(isEqual(null).negate().and(section -> notifier.getKey().equals(section)))
            .collect(Collectors.toMap(Function.identity(),
                    section -> configuration.getSection(section).
                            getRootNode().getChildren().stream().collect(
                            Collectors.toMap(ConfigurationNode::getName, node -> (String) node.getValue()))));
}
 
Example #17
Source File: ExtensionQuickStart.java    From zap-extensions with Apache License 2.0 5 votes vote down vote up
private String getFirstChildNodeString(ConfigurationNode node, String childName) {
    ConfigurationNode child = this.getFirstChildNode(node, childName);
    if (child != null) {
        return child.getValue().toString();
    }
    return null;
}
 
Example #18
Source File: ExtensionQuickStart.java    From zap-extensions with Apache License 2.0 5 votes vote down vote up
private ConfigurationNode getFirstChildNode(ConfigurationNode node, String childName) {
    List<ConfigurationNode> list = node.getChildren(childName);
    if (list.size() > 0) {
        return list.get(0);
    }
    return null;
}
 
Example #19
Source File: XMLScenarioFactory.java    From qaf with MIT License 5 votes vote down vote up
private Map<?, ?> getMetaData(ConfigurationNode defination) {
	Map<String, Object> metaData = new HashMap<String, Object>();
	for (Object obj : defination.getAttributes()) {
		Node node = (Node) obj;
		metaData.put(node.getName(), toObject((String) node.getValue()));
	}
	return metaData;
}
 
Example #20
Source File: XMLScenarioFactory.java    From qaf with MIT License 5 votes vote down vote up
private void addSteps(ConfigurationNode defination, ArrayList<Object[]> statements) {
	for (Object o : defination.getChildren()) {
		Node stepNode = (Node) o;
		if (stepNode.getName().equalsIgnoreCase("STEP")) {
			String name = getAttribute(stepNode, "name", null);
			String inParams = getAttribute(stepNode, "params", "[]");
			if (!inParams.startsWith("[")) {
				Object[] params = new Object[] { toObject(inParams) };
				inParams = gson.toJson(params);
			}
			String outParams = getAttribute(stepNode, "result", "");
			statements.add(new String[] { name, inParams, outParams });
		}
	}
}
 
Example #21
Source File: XMLScenarioFactory.java    From qaf with MIT License 5 votes vote down vote up
@Override
protected Collection<Object[]> parseFile(String xmlFile) {
	ArrayList<Object[]> statements = new ArrayList<Object[]>();
	try {
		HierarchicalConfiguration processor = new XMLConfiguration(xmlFile);
		List<?> definations = processor.getRoot().getChildren();
		for (Object definationObj : definations) {
			ConfigurationNode defination = (ConfigurationNode) definationObj;
			String type = defination.getName();
			String[] entry = new String[3];

			if (type.equalsIgnoreCase("SCENARIO") || type.equalsIgnoreCase("STEP-DEF")) {
				entry[0] = type;

				Map<?, ?> metaData = getMetaData(defination);
				entry[1] = (String) metaData.get("name");
				metaData.remove("name");
				entry[2] = gson.toJson(metaData);
				statements.add(entry);
				System.out.println("META-DATA:" + entry[2]);
				addSteps(defination, statements);
				statements.add(new String[] { "END", "", "" });
			}
		}
	} catch (ConfigurationException e) {
		e.printStackTrace();
	}

	return statements;
}
 
Example #22
Source File: Yfiton.java    From yfiton with Apache License 2.0 5 votes vote down vote up
private Map<String, Map<String, String>> loadPreferences(HierarchicalINIConfiguration configuration, Notifier notifier) {
    Set<String> sections = configuration.getSections();

    return sections.stream().filter(isEqual(null).negate().and(section -> notifier.getKey().equals(section)))
            .collect(Collectors.toMap(Function.identity(),
                    section -> configuration.getSection(section).
                            getRootNode().getChildren().stream().collect(
                            Collectors.toMap(ConfigurationNode::getName, node -> (String) node.getValue()))));
}
 
Example #23
Source File: InitStore.java    From hugegraph with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    E.checkArgument(args.length == 2,
                    "HugeGraph init-store can only accept two config files");
    E.checkArgument(args[0].endsWith(".yaml"),
                    "Expect the 1st parameter is yaml config file.");
    E.checkArgument(args[1].endsWith(".properties"),
                    "Expect the 2nd parameter is properties config file.");

    String gremlinConfFile = args[0];
    String restConfFile = args[1];

    RegisterUtil.registerBackends();
    RegisterUtil.registerPlugins();
    RegisterUtil.registerServer();

    YamlConfiguration config = new YamlConfiguration();
    config.load(gremlinConfFile);

    List<ConfigurationNode> nodes = config.getRootNode()
                                          .getChildren(GRAPHS);
    E.checkArgument(nodes.size() == 1,
                    "Must contain one '%s' node in config file '%s'",
                    GRAPHS, gremlinConfFile);

    List<ConfigurationNode> graphNames = nodes.get(0).getChildren();

    E.checkArgument(!graphNames.isEmpty(),
                    "Must contain at least one graph");

    for (ConfigurationNode graphName : graphNames) {
        @SuppressWarnings("unchecked")
        String name = ((Map.Entry<String, Object>)
                       graphName.getReference()).getKey();
        HugeFactory.checkGraphName(name, "gremlin-server.yaml");
        String configPath = graphName.getValue().toString();
        initGraph(configPath);
    }

    StandardAuthenticator.initAdminUser(restConfFile);

    HugeFactory.shutdown(30L);
}