List of usage examples for org.apache.commons.configuration XMLConfiguration addNodes
public void addNodes(String key, Collection nodes)
From source file:com.vmware.qe.framework.datadriven.utils.XMLUtil.java
public static void writeToXML(HierarchicalConfiguration config, String fileName) throws Exception { XMLConfiguration xmlConfiguration = new XMLConfiguration(); xmlConfiguration.addNodes("test-data", config.getRootNode().getChildren()); xmlConfiguration.save(fileName);// ww w. j a va 2 s .c o m }
From source file:org.onosproject.drivers.utilities.YangXmlUtils.java
/** * Retrieves a valid XML configuration for a specific XML path for multiple * instance of YangElements objects.//from w w w. j a v a2 s. com * * @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; }
From source file:org.zaproxy.gradle.UpdateAddOnZapVersionsEntries.java
@TaskAction public void update() throws Exception { if (checksumAlgorithm.get().isEmpty()) { throw new IllegalArgumentException("The checksum algorithm must not be empty."); }/* w w w. j a va 2s .co m*/ if (fromFile.isPresent()) { if (fromUrl.isPresent()) { throw new IllegalArgumentException( "Only one of the properties, URL or file, can be set at the same time."); } if (!downloadUrl.isPresent()) { throw new IllegalArgumentException("The download URL must be provided when specifying the file."); } } else if (!fromUrl.isPresent()) { throw new IllegalArgumentException("Either one of the properties, URL or file, must be set."); } if (downloadUrl.get().isEmpty()) { throw new IllegalArgumentException("The download URL must not be empty."); } try { URL url = new URL(downloadUrl.get()); if (!HTTPS_SCHEME.equalsIgnoreCase(url.getProtocol())) { throw new IllegalArgumentException( "The provided download URL does not use HTTPS scheme: " + url.getProtocol()); } } catch (IOException e) { throw new IllegalArgumentException("Failed to parse the download URL: " + e.getMessage(), e); } Path addOn = getAddOn(); String addOnId = extractAddOnId(addOn.getFileName().toString()); AddOnEntry addOnEntry = new AddOnEntry(addOnId, new AddOnConfBuilder(addOn, downloadUrl.get(), checksumAlgorithm.get(), releaseDate.get()).build()); for (File zapVersionsFile : into.getFiles()) { if (!Files.isRegularFile(zapVersionsFile.toPath())) { throw new IllegalArgumentException("The provided path is not a file: " + zapVersionsFile); } SortedSet<AddOnEntry> addOns = new TreeSet<>(); XMLConfiguration zapVersionsXml = new CustomXmlConfiguration(); zapVersionsXml.load(zapVersionsFile); Arrays.stream(zapVersionsXml.getStringArray(ADD_ON_ELEMENT)).filter(id -> !addOnId.equals(id)) .forEach(id -> { String key = ADD_ON_NODE_PREFIX + id; addOns.add(new AddOnEntry(id, zapVersionsXml.configurationAt(key))); zapVersionsXml.clearTree(key); }); zapVersionsXml.clearTree(ADD_ON_ELEMENT); zapVersionsXml.clearTree(ADD_ON_NODE_PREFIX + addOnId); addOns.add(addOnEntry); addOns.forEach(e -> { zapVersionsXml.addProperty(ADD_ON_ELEMENT, e.getAddOnId()); zapVersionsXml.addNodes(ADD_ON_NODE_PREFIX + e.getAddOnId(), e.getData().getRootNode().getChildren()); }); zapVersionsXml.save(zapVersionsFile); } }