use of org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration in project revapi by revapi.
the class SchemaDrivenJSONToXmlConverter method convertSimple.
private static PlexusConfiguration convertSimple(String tagName, String id, String value) {
XmlPlexusConfiguration ret = new XmlPlexusConfiguration(tagName);
if (id != null) {
ret.setAttribute("id", id);
}
ret.setValue(value);
return ret;
}
use of org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration in project revapi by revapi.
the class SchemaDrivenJSONToXmlConverter method convertObject.
private static PlexusConfiguration convertObject(ModelNode configuration, ConversionContext ctx) {
XmlPlexusConfiguration object = new XmlPlexusConfiguration(ctx.tagName);
if (ctx.id != null) {
object.setAttribute("id", ctx.id);
}
ModelNode propertySchemas = ctx.currentSchema.get("properties");
ModelNode additionalPropSchemas = ctx.currentSchema.get("additionalProperties");
for (String key : configuration.keys()) {
ModelNode childConfig = configuration.get(key);
ModelNode childSchema = propertySchemas.get(key);
if (!childSchema.isDefined()) {
if (additionalPropSchemas.getType() == ModelType.BOOLEAN) {
throw new IllegalArgumentException("Cannot determine the format for the '" + key + "' JSON value during the JSON-to-XML conversion.");
}
childSchema = additionalPropSchemas;
}
ctx.currentSchema = childSchema;
ctx.pushTag(key);
ctx.id = null;
if (!childSchema.isDefined()) {
// check if this is an ignorable path
if (ctx.ignorablePaths.contains(ctx.getCurrentPathString())) {
ctx.currentPath.pop();
continue;
}
throw new IllegalArgumentException("Could not determine the format for the '" + key + "' JSON value during the JSON-to-XML conversion.");
}
PlexusConfiguration xmlChild = convert(childConfig, ctx);
ctx.currentPath.pop();
object.addChild(xmlChild);
}
return object;
}
use of org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration in project revapi by revapi.
the class SchemaDrivenJSONToXmlConverter method convertNewStyleConfigToXml.
private static PlexusConfiguration convertNewStyleConfigToXml(Map<String, ModelNode> extensionSchemas, ModelNode jsonConfig) throws IOException {
PlexusConfiguration xmlConfig = new XmlPlexusConfiguration("analysisConfiguration");
for (ModelNode extConfig : jsonConfig.asList()) {
String extensionId = extConfig.get("extension").asString();
ModelNode configuration = extConfig.get("configuration");
String id = extConfig.hasDefined("id") ? extConfig.get("id").asString() : null;
ModelNode schema = extensionSchemas.get(extensionId);
if (schema == null) {
continue;
}
ConversionContext ctx = new ConversionContext();
ctx.rootSchema = schema;
ctx.currentSchema = schema;
ctx.pushTag(extensionId);
ctx.id = id;
// we don't assign the ignorable paths, because this must not be tracked in a new-style configuration
PlexusConfiguration extXml = convert(configuration, ctx);
ctx.currentPath.pop();
xmlConfig.addChild(extXml);
}
return xmlConfig;
}
use of org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration in project revapi by revapi.
the class Analyzer method mergeXmlConfigFile.
private void mergeXmlConfigFile(AnalysisContext.Builder ctxBld, ConfigurationFile configFile, Reader rdr) throws IOException, XmlPullParserException {
XmlToJson<PlexusConfiguration> conv = new XmlToJson<>(revapi, PlexusConfiguration::getName, PlexusConfiguration::getValue, PlexusConfiguration::getAttribute, x -> Arrays.asList(x.getChildren()));
PlexusConfiguration xml = new XmlPlexusConfiguration(Xpp3DomBuilder.build(rdr));
String[] roots = configFile.getRoots();
if (roots == null) {
ctxBld.mergeConfiguration(conv.convert(xml));
} else {
roots: for (String r : roots) {
PlexusConfiguration root = xml;
boolean first = true;
String[] rootPath = r.split("/");
for (String name : rootPath) {
if (first) {
first = false;
if (!name.equals(root.getName())) {
continue roots;
}
} else {
root = root.getChild(name);
if (root == null) {
continue roots;
}
}
}
ctxBld.mergeConfiguration(conv.convert(root));
}
}
}
use of org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration in project revapi by revapi.
the class XmlUtilTest method testPrettyPrintingXml.
@Test
public void testPrettyPrintingXml() throws Exception {
String text = "<a><b><c>asdf</c><d/></b></a>";
XmlPlexusConfiguration xml = new XmlPlexusConfiguration(Xpp3DomBuilder.build(new StringReader(text)));
StringWriter wrt = new StringWriter();
XmlUtil.toIndentedString(xml, 2, 0, wrt);
String pretty = wrt.toString();
assertEquals("<a>\n <b>\n <c>asdf</c>\n <d/>\n </b>\n</a>", pretty);
}
Aggregations