/** * Recursively convert PLEXUS config to Xpp3Dom. * * @param config The config to convert * @return The Xpp3Dom document * @see #execute(String,String,Properties) */ private Xpp3Dom toXppDom(final PlexusConfiguration config) { final Xpp3Dom result = new Xpp3Dom(config.getName()); result.setValue(config.getValue(null)); for (final String name : config.getAttributeNames()) { try { result.setAttribute(name, config.getAttribute(name)); } catch (final PlexusConfigurationException ex) { throw new IllegalArgumentException(ex); } } for (final PlexusConfiguration child : config.getChildren()) { result.addChild(this.toXppDom(child)); } return result; }
private void writePlexusConfiguration(XMLWriter xmlWriter, PlexusConfiguration c) throws PlexusConfigurationException { if (c.getAttributeNames().length == 0 && c.getChildCount() == 0 && c.getValue() == null) { return; } xmlWriter.startElement(c.getName()); // ---------------------------------------------------------------------- // Write the attributes // ---------------------------------------------------------------------- String[] attributeNames = c.getAttributeNames(); for (int i = 0; i < attributeNames.length; i++) { String attributeName = attributeNames[i]; xmlWriter.addAttribute(attributeName, c.getAttribute(attributeName)); } // ---------------------------------------------------------------------- // Write the children // ---------------------------------------------------------------------- PlexusConfiguration[] children = c.getChildren(); if (children.length > 0) { for (int i = 0; i < children.length; i++) { writePlexusConfiguration(xmlWriter, children[i]); } } else { String value = c.getValue(); if (value != null) { xmlWriter.writeText(value); } } xmlWriter.endElement(); }