/** * Write a DOM-Tree to a target file. * * @param target File to write to. * @param dom dom to write to file. * @throws IOException in case of unexpected writer exceptions. */ private void writeDomToTarget(final File target, final Xpp3Dom dom) throws IOException { if (getLog().isDebugEnabled()) getLog().debug("writing: " + dom.getName() + " to: " + target.getAbsoluteFile()); final XmlStreamWriter writer = WriterFactory.newXmlWriter(target); final PrettyPrintXMLWriter pretty = new PrettyPrintXMLWriter(writer); Xpp3DomWriter.write(pretty, dom); writer.close(); if (getLog().isDebugEnabled()) getLog().debug(dom.getName() + " written to: " + target.getAbsoluteFile()); }
/** * Returns information about child config entries. * * @param node Current config node. * @param store The database. * @return Child config information. */ private ValueDescriptor<?> getConfigChildNodes(Xpp3Dom node, Store store) { Xpp3Dom[] children = node.getChildren(); if (children.length == 0) { PropertyDescriptor propertyDescriptor = store.create(PropertyDescriptor.class); propertyDescriptor.setName(node.getName()); propertyDescriptor.setValue(node.getValue()); return propertyDescriptor; } ArrayValueDescriptor childDescriptor = store.create(ArrayValueDescriptor.class); childDescriptor.setName(node.getName()); for (Xpp3Dom child : children) { childDescriptor.getValue().add(getConfigChildNodes(child, store)); } return childDescriptor; }
public static void setCollectionValues( Xpp3Dom parent, String nodeName, String childName, Collection<String> values) { Xpp3Dom node = parent.getChild(nodeName); if (node != null) { for (int i = 0; i < parent.getChildCount(); i++) { Xpp3Dom existing = parent.getChild(i); if (StringUtils.equals(nodeName, existing.getName())) { parent.removeChild(i); break; } } node = null; } node = new Xpp3Dom(nodeName); parent.addChild(node); for (String childVal : values) { Xpp3Dom childNode = new Xpp3Dom(childName); node.addChild(childNode); childNode.setValue(childVal); } }
private void addChildren(final Xpp3Dom xpp3Dom, final ConfigurationElementBuilder builder) { builder.setText(xpp3Dom.getValue()); for (String attributeName : xpp3Dom.getAttributeNames()) { String attributeValue = xpp3Dom.getAttribute(attributeName); if (attributeValue != null) builder.addAttribute(attributeName, attributeValue); } for (Xpp3Dom child : xpp3Dom.getChildren()) { ConfigurationElementBuilder elementBuilder = builder.addChild(child.getName()); addChildren(child, elementBuilder); } }
public ConfigurationImpl(final Xpp3Dom configXml) { this.configuration = configXml; if (configuration != null) { for (Xpp3Dom xpp3Dom : configuration.getChildren()) { ConfigurationElementBuilder builder = ConfigurationElementBuilder.create() .setName(xpp3Dom.getName()) .setText(xpp3Dom.getValue()); addChildren(xpp3Dom, builder); configurationElements.add(builder); } } }