org.codehaus.plexus.configuration.PlexusConfiguration Java Examples
The following examples show how to use
org.codehaus.plexus.configuration.PlexusConfiguration.
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: AntXmlPlexusConfigurationWriter.java From was-maven-plugin with Apache License 2.0 | 6 votes |
private void write(PlexusConfiguration c, XMLWriter w, int depth) throws IOException { int count = c.getChildCount(); if (count == 0) { writeTag(c, w, depth); } else { w.startElement(c.getName()); writeAttributes(c, w); for (int i = 0; i < count; i++) { PlexusConfiguration child = c.getChild(i); write(child, w, depth + 1); } w.endElement(); } }
Example #2
Source File: SchemaDrivenJSONToXmlConverterTest.java From revapi with Apache License 2.0 | 6 votes |
@Test public void testNestedSchemasConverted() throws Exception { ModelNode topSchema = json("{\"type\": \"object\", \"properties\": {\"a\": {\"type\": \"string\"}}}"); ModelNode nestedSchema = json("{\"type\": \"boolean\"}"); Map<String, ModelNode> extensionSchemas = new HashMap<>(); extensionSchemas.put("top", topSchema); extensionSchemas.put("top.nested", nestedSchema); ModelNode config = json("{\"top\": {\"a\": \"kachny\", \"nested\": true}}"); PlexusConfiguration xml = SchemaDrivenJSONToXmlConverter.convertToXml(extensionSchemas, config); assertEquals(2, xml.getChildCount()); PlexusConfiguration topXml = xml.getChild("top"); assertNotNull(topXml); assertEquals("top", topXml.getName()); assertEquals(1, topXml.getChildCount()); assertEquals("a", topXml.getChild(0).getName()); assertEquals("kachny", topXml.getChild("a").getValue()); PlexusConfiguration nested = xml.getChild("top.nested"); assertNotNull(nested); assertEquals(0, nested.getChildCount()); assertEquals("true", nested.getValue()); }
Example #3
Source File: SchemaDrivenJSONToXmlConverterTest.java From revapi with Apache License 2.0 | 6 votes |
@Test public void testOneOf() throws Exception { ModelNode schema = json("{\"oneOf\": [{\"type\": \"integer\"}, {\"type\": \"number\"}, {\"type\": \"boolean\"}]}"); ModelNode json1 = json("1"); ModelNode json2 = json("1.1"); try { SchemaDrivenJSONToXmlConverter.convert(json1, schema, "ext", null); fail("Should not have been possible to convert using ambiguous oneOf."); } catch (IllegalArgumentException __) { //good } PlexusConfiguration xml = SchemaDrivenJSONToXmlConverter.convert(json2, schema, "ext", null); assertNotNull(xml); assertEquals("ext", xml.getName()); assertEquals(0, xml.getChildCount()); assertEquals("1.1", xml.getValue()); }
Example #4
Source File: DMNTransformerComponentConfigurationTest.java From jdmn with Apache License 2.0 | 6 votes |
@Test public void testDuplicateKeyConfiguration() throws Exception { PlexusConfiguration config = new DefaultPlexusConfiguration(OptionallyConfigurableMojoComponent.ELEMENT_CONFIGURATION) .addChild("key1", "value1") .addChild("key2", "value2a") .addChild("key2", "value2b") .addChild("key2", "value2c") .addChild("key3", "value3"); PlexusConfiguration configuration = generateComponentConfiguration("componentName", ELEMENT_NAME, config); OptionallyConfigurableMojoComponent component = parseConfiguration(configuration, DMNTransformerComponent.class); assertEquivalentConfiguration(component, "{\n" + " \"key1\": \"value1\",\n" + " \"key2\": [ \"value2a\", \"value2b\", \"value2c\" ],\n" + " \"key3\": \"value3\"\n" + "}"); }
Example #5
Source File: DMNTransformerComponentConfigurationTest.java From jdmn with Apache License 2.0 | 6 votes |
@Test public void testNestedConfiguration() throws Exception { PlexusConfiguration inner = new DefaultPlexusConfiguration("innerConfig"); inner.addChild("innerKey1", "innerValue1"); PlexusConfiguration intermediate = new DefaultPlexusConfiguration("intermediateConfig"); intermediate.addChild("intermediateKey1", "intermediateValue1"); intermediate.addChild(inner); PlexusConfiguration config = new DefaultPlexusConfiguration(OptionallyConfigurableMojoComponent.ELEMENT_CONFIGURATION); config.addChild("key1", "value1"); config.addChild(intermediate); PlexusConfiguration configuration = generateComponentConfiguration("componentName", ELEMENT_NAME, config); OptionallyConfigurableMojoComponent component = parseConfiguration(configuration, DMNTransformerComponent.class); assertEquivalentConfiguration(component, "{\n" + " \"key1\": \"value1\",\n" + " \"intermediateConfig\": {\n" + " \"intermediateKey1\": \"intermediateValue1\",\n" + " \"innerConfig\": {\n" + " \"innerKey1\": \"innerValue1\" \n" + " }\n" + " }\n" + "}"); }
Example #6
Source File: BasePitMojoTest.java From pitest with Apache License 2.0 | 6 votes |
protected void configurePitMojo(final AbstractPitMojo pitMojo, final String config) throws Exception { final Xpp3Dom xpp3dom = Xpp3DomBuilder.build(new StringReader(config)); final PlexusConfiguration pluginConfiguration = extractPluginConfiguration( "pitest-maven", xpp3dom); // default the report dir to something setVariableValueToObject(pitMojo, "reportsDirectory", new File(".")); configureMojo(pitMojo, pluginConfiguration); final Map<String, Artifact> pluginArtifacts = new HashMap<>(); setVariableValueToObject(pitMojo, "pluginArtifactMap", pluginArtifacts); setVariableValueToObject(pitMojo, "project", this.project); if (pitMojo.getAdditionalClasspathElements() == null) { ArrayList<String> elements = new ArrayList<>(); setVariableValueToObject(pitMojo, "additionalClasspathElements", elements); } }
Example #7
Source File: OptionallyConfigurableComponentConverter.java From jdmn with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") private Map<String, Object> generateConfigurationMap(PlexusConfiguration configuration) { Map<String, Object> node = new HashMap<>(); for (PlexusConfiguration child : configuration.getChildren()) { // Expand node to a list where duplicate keys exist Object existingNode = node.get(child.getName()); if (existingNode != null) { if (!(existingNode instanceof List)) { List<Object> listNode = new ArrayList<>(); listNode.add(existingNode); node.put(child.getName(), listNode); } List<Object> target = ((List)node.get(child.getName())); target.add(generateChildNode(child)); } else { node.put(child.getName(), generateChildNode(child)); } } return node; }
Example #8
Source File: OptionallyConfigurableComponentConverter.java From jdmn with Apache License 2.0 | 6 votes |
private OptionallyConfigurableMojoComponent configureCompoundComponent(OptionallyConfigurableMojoComponent component, PlexusConfiguration configuration) throws ComponentConfigurationException { PlexusConfiguration name = configuration.getChild(OptionallyConfigurableMojoComponent.ELEMENT_NAME, false); if (name == null || name.getValue() == null) { throw new ComponentConfigurationException(String.format( "Cannot configure component; \"%s\" property must be provided", OptionallyConfigurableMojoComponent.ELEMENT_NAME)); } component.setName(name.getValue()); PlexusConfiguration config = configuration.getChild(OptionallyConfigurableMojoComponent.ELEMENT_CONFIGURATION, false); if (config != null) { component.setConfiguration(generateConfigurationMap(config)); } return component; }
Example #9
Source File: MojoConfigurationMergerTest.java From takari-lifecycle with Eclipse Public License 1.0 | 6 votes |
@Test public void extractionOfMojoSpecificConfigurationAndMergingwithDefaultMojoConfiguration() throws Exception { InputStream is = getClass().getResourceAsStream("/META-INF/maven/plugin.xml"); assertNotNull(is); PluginDescriptor pluginDescriptor = pluginDescriptorBuilder.build(new InputStreamReader(is, "UTF-8")); String goal = merger.determineGoal("io.takari.maven.plugins.jar.Jar", pluginDescriptor); assertEquals("We expect the goal name to be 'jar'", "jar", goal); MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo(goal); PlexusConfiguration defaultMojoConfiguration = mojoDescriptor.getMojoConfiguration(); System.out.println(defaultMojoConfiguration); PlexusConfiguration configurationFromMaven = builder("configuration") // .es("jar") // .es("sourceJar").v("true").ee() // .ee() // .buildPlexusConfiguration(); PlexusConfiguration mojoConfiguration = merger.extractAndMerge(goal, configurationFromMaven, defaultMojoConfiguration); String xml = mojoConfiguration.toString(); assertXpathEvaluatesTo("java.io.File", "/configuration/classesDirectory/@implementation", xml); assertXpathEvaluatesTo("${project.build.outputDirectory}", "/configuration/classesDirectory/@default-value", xml); assertXpathEvaluatesTo("java.util.List", "/configuration/reactorProjects/@implementation", xml); assertXpathEvaluatesTo("${reactorProjects}", "/configuration/reactorProjects/@default-value", xml); assertXpathEvaluatesTo("true", "/configuration/sourceJar", xml); }
Example #10
Source File: MojoConfigurationMergerTest.java From takari-lifecycle with Eclipse Public License 1.0 | 6 votes |
@Test public void plexusConfigurationMerging() throws Exception { PlexusConfiguration mojoConfigurationFromPom = builder("configuration") // .es("sourceJar").v("true").ee() // .buildPlexusConfiguration(); PlexusConfiguration defaultMojoConfiguration = builder("configuration") // .entry("classesDirectory", "java.io.File", "${project.build.outputDirectory}") // .entry("reactorProjects", "java.util.List", "${reactorProjects}") // .entry("souceJar", "boolean", "${sourceJar") // .buildPlexusConfiguration(); PlexusConfiguration mojoConfiguration = merger.mergePlexusConfiguration(mojoConfigurationFromPom, defaultMojoConfiguration); String xml = mojoConfiguration.toString(); assertXpathEvaluatesTo("java.io.File", "/configuration/classesDirectory/@implementation", xml); assertXpathEvaluatesTo("${project.build.outputDirectory}", "/configuration/classesDirectory/@default-value", xml); assertXpathEvaluatesTo("java.util.List", "/configuration/reactorProjects/@implementation", xml); assertXpathEvaluatesTo("${reactorProjects}", "/configuration/reactorProjects/@default-value", xml); assertXpathEvaluatesTo("true", "/configuration/sourceJar", xml); }
Example #11
Source File: SchemaDrivenJSONToXmlConverter.java From revapi with Apache License 2.0 | 6 votes |
private static PlexusConfiguration convertArray(ModelNode configuration, ConversionContext ctx) { ModelNode itemsSchema = ctx.currentSchema.get("items"); if (!itemsSchema.isDefined()) { throw new IllegalArgumentException( "No schema found for items of a list. Cannot continue with XML-to-JSON conversion."); } PlexusConfiguration list = new XmlPlexusConfiguration(ctx.tagName); if (ctx.id != null) { list.setAttribute("id", ctx.id); } for (ModelNode childConfig : configuration.asList()) { ctx.tagName = "item"; ctx.currentSchema = itemsSchema; ctx.id = null; ctx.currentPath.push("[]"); PlexusConfiguration child = convert(childConfig, ctx); ctx.currentPath.pop(); list.addChild(child); } return list; }
Example #12
Source File: IncludeProjectDependenciesComponentConfigurator.java From protostuff with Apache License 2.0 | 5 votes |
public void configureComponent(Object component, PlexusConfiguration configuration, ExpressionEvaluator expressionEvaluator, ClassRealm containerRealm, ConfigurationListener listener) throws ComponentConfigurationException { addProjectDependenciesToClassRealm(expressionEvaluator, containerRealm); converterLookup.registerConverter(new ClassRealmConverter(containerRealm)); ObjectWithFieldsConverter converter = new ObjectWithFieldsConverter(); converter.processConfiguration(converterLookup, component, containerRealm.getClassLoader(), configuration, expressionEvaluator, listener); }
Example #13
Source File: MojoConfigurationProcessor.java From takari-lifecycle with Eclipse Public License 1.0 | 5 votes |
Xpp3Dom convert(PlexusConfiguration c) throws ComponentConfigurationException { try { return Xpp3DomBuilder.build(new StringReader(c.toString())); } catch (Exception e) { throw new ComponentConfigurationException("Failure converting PlexusConfiguration to Xpp3Dom.", e); } }
Example #14
Source File: MojoExecutionService.java From docker-maven-plugin with Apache License 2.0 | 5 votes |
private Xpp3Dom toXpp3Dom(PlexusConfiguration config) { Xpp3Dom result = new Xpp3Dom(config.getName()); result.setValue(config.getValue(null)); for (String name : config.getAttributeNames()) { result.setAttribute(name, config.getAttribute(name)); } for (PlexusConfiguration child : config.getChildren()) { result.addChild(toXpp3Dom(child)); } return result; }
Example #15
Source File: MojoConfigurator.java From takari-lifecycle with Eclipse Public License 1.0 | 5 votes |
@Override public void configureComponent(final Object mojoInstance, // final PlexusConfiguration pluginConfigurationFromMaven, // final ExpressionEvaluator evaluator, // final ClassRealm realm, // final ConfigurationListener listener) throws ComponentConfigurationException { super.configureComponent(mojoInstance, pluginConfigurationFromMaven, evaluator, realm, listener); }
Example #16
Source File: IteratorMojo.java From iterator-maven-plugin with Apache License 2.0 | 5 votes |
/** * This will copy the configuration from <b>src</b> to the result whereas the placeholder will be replaced with the * current value. */ private PlexusConfiguration copyConfiguration( Xpp3Dom src, String iteratorName, String value ) { XmlPlexusConfiguration dom = new XmlPlexusConfiguration( src.getName() ); if ( src.getValue() == null ) { dom.setValue( src.getValue() ); } else { if ( src.getValue().contains( iteratorName ) ) { dom.setValue( src.getValue().replaceAll( iteratorName, value ) ); } else { dom.setValue( src.getValue() ); } } for ( String attributeName : src.getAttributeNames() ) { dom.setAttribute( attributeName, src.getAttribute( attributeName ) ); } for ( Xpp3Dom child : src.getChildren() ) { dom.addChild( copyConfiguration( child, iteratorName, value ) ); } return dom; }
Example #17
Source File: IteratorMojo.java From iterator-maven-plugin with Apache License 2.0 | 5 votes |
/** * Taken from MojoExecutor of Don Brown. Converts PlexusConfiguration to a Xpp3Dom. * * @param config the PlexusConfiguration. Must not be {@code null}. * @return the Xpp3Dom representation of the PlexusConfiguration */ public Xpp3Dom toXpp3Dom( PlexusConfiguration config ) { Xpp3Dom result = new Xpp3Dom( config.getName() ); result.setValue( config.getValue( null ) ); for ( String name : config.getAttributeNames() ) { result.setAttribute( name, config.getAttribute( name ) ); } for ( PlexusConfiguration child : config.getChildren() ) { result.addChild( toXpp3Dom( child ) ); } return result; }
Example #18
Source File: AppengineEnhancerMojo.java From gcloud-maven-plugin with Apache License 2.0 | 5 votes |
private Xpp3Dom convertPlexusConfiguration(PlexusConfiguration config) { Xpp3Dom xpp3DomElement = new Xpp3Dom(config.getName()); xpp3DomElement.setValue(config.getValue()); for (String name : config.getAttributeNames()) { xpp3DomElement.setAttribute(name, config.getAttribute(name)); } for (PlexusConfiguration child : config.getChildren()) { xpp3DomElement.addChild(convertPlexusConfiguration(child)); } return xpp3DomElement; }
Example #19
Source File: IncludeProjectDependenciesComponentConfigurator.java From swagger-maven-plugin with Apache License 2.0 | 5 votes |
@Override public void configureComponent(Object component, PlexusConfiguration configuration, ExpressionEvaluator expressionEvaluator, ClassRealm containerRealm, ConfigurationListener listener) throws ComponentConfigurationException { addProjectDependenciesToClassRealm(expressionEvaluator, containerRealm); ObjectWithFieldsConverter converter = new ObjectWithFieldsConverter(); converter.processConfiguration(converterLookup, component, containerRealm.getClassLoader(), configuration, expressionEvaluator, listener); }
Example #20
Source File: MojoConfigurationProcessor.java From takari-lifecycle with Eclipse Public License 1.0 | 5 votes |
/** * Extract the Mojo specific configuration from the incoming plugin configuration from Maven by looking at an enclosing element with the goal name. Use this and merge it with the default Mojo * configuration and use this to apply values to the Mojo. * * @param goal * @param pluginConfigurationFromMaven * @param defaultMojoConfiguration * @return * @throws ComponentConfigurationException */ PlexusConfiguration extractAndMerge(String goal, PlexusConfiguration pluginConfigurationFromMaven, PlexusConfiguration defaultMojoConfiguration) throws ComponentConfigurationException { // // We need to extract the specific configuration for this goal out of the POM configuration // PlexusConfiguration mojoConfigurationFromPom = new XmlPlexusConfiguration("configuration"); for (PlexusConfiguration element : pluginConfigurationFromMaven.getChildren()) { if (element.getName().equals(goal)) { for (PlexusConfiguration goalConfigurationElements : element.getChildren()) { mojoConfigurationFromPom.addChild(goalConfigurationElements); } } } return new XmlPlexusConfiguration(Xpp3Dom.mergeXpp3Dom(convert(mojoConfigurationFromPom), convert(defaultMojoConfiguration))); }
Example #21
Source File: MojoExecutionService.java From jkube with Eclipse Public License 2.0 | 5 votes |
private Xpp3Dom toXpp3Dom(PlexusConfiguration config) { Xpp3Dom result = new Xpp3Dom(config.getName()); result.setValue(config.getValue(null)); for (String name : config.getAttributeNames()) { result.setAttribute(name, config.getAttribute(name)); } for (PlexusConfiguration child : config.getChildren()) { result.addChild(toXpp3Dom(child)); } return result; }
Example #22
Source File: Analyzer.java From revapi with Apache License 2.0 | 5 votes |
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)); } } }
Example #23
Source File: Analyzer.java From revapi with Apache License 2.0 | 5 votes |
private void parseIncludeExclude(PlexusConfiguration parent, Consumer<String> handleInclude, Consumer<String> handleExclude) { PlexusConfiguration include = parent.getChild("include"); PlexusConfiguration exclude = parent.getChild("exclude"); if (include != null) { Stream.of(include.getChildren()).forEach(c -> handleInclude.accept(c.getValue())); } if (exclude != null) { Stream.of(exclude.getChildren()).forEach(c -> handleExclude.accept(c.getValue())); } }
Example #24
Source File: Analyzer.java From revapi with Apache License 2.0 | 5 votes |
private PipelineConfiguration.Builder parsePipelineConfigurationXML() { PipelineConfiguration.Builder bld = PipelineConfiguration.builder(); if (pipelineConfiguration == null) { return bld; } for (PlexusConfiguration c : pipelineConfiguration.getChildren()) { switch (c.getName()) { case "analyzers": parseIncludeExclude(c, bld::addAnalyzerExtensionIdInclude, bld::addAnalyzerExtensionIdExclude); break; case "reporters": parseIncludeExclude(c, bld::addReporterExtensionIdInclude, bld::addReporterExtensionIdExclude); break; case "filters": parseIncludeExclude(c, bld::addFilterExtensionIdInclude, bld::addFilterExtensionIdExclude); break; case "transforms": parseIncludeExclude(c, bld::addTransformExtensionIdInclude, bld::addTransformExtensionIdExclude); break; case "transformBlocks": for (PlexusConfiguration b : c.getChildren()) { List<String> blockIds = Stream.of(b.getChildren()) .map(PlexusConfiguration::getValue).collect(toList()); bld.addTransformationBlock(blockIds); } break; } } return bld; }
Example #25
Source File: ConvertToXmlConfigMojo.java From revapi with Apache License 2.0 | 5 votes |
private static PlexusConfiguration convertToXml(Map<String, ModelNode> extensionSchemas, String xmlOrJson) throws IOException, XmlPullParserException { ModelNode jsonConfig; try { jsonConfig = ModelNode.fromJSONString(JSONUtil.stripComments(xmlOrJson)); } catch (IllegalArgumentException e) { //ok, this already is XML return null; } return SchemaDrivenJSONToXmlConverter.convertToXml(extensionSchemas, jsonConfig); }
Example #26
Source File: XmlUtil.java From revapi with Apache License 2.0 | 5 votes |
static void toIndentedString(PlexusConfiguration xml, int indentationSize, int currentDepth, Writer wrt) throws IOException { indent(indentationSize, currentDepth, wrt); boolean hasChildren = xml.getChildCount() > 0; boolean hasContent = xml.getValue() != null && !xml.getValue().isEmpty(); wrt.write('<'); wrt.write(xml.getName()); if (!hasChildren && !hasContent) { wrt.write("/>"); } else { wrt.write('>'); if (hasChildren) { wrt.write('\n'); for (PlexusConfiguration c : xml.getChildren()) { toIndentedString(c, indentationSize, currentDepth + 1, wrt); wrt.append('\n'); } if (!hasContent) { indent(indentationSize, currentDepth, wrt); } } if (hasContent) { escaped(wrt, xml.getValue()); } wrt.write("</"); wrt.write(xml.getName()); wrt.write('>'); } }
Example #27
Source File: SchemaDrivenJSONToXmlConverter.java From revapi with Apache License 2.0 | 5 votes |
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; }
Example #28
Source File: SchemaDrivenJSONToXmlConverter.java From revapi with Apache License 2.0 | 5 votes |
private static PlexusConfiguration convertOldStyleConfigToXml(Map<String, ModelNode> extensionSchemas, ModelNode jsonConfig) { PlexusConfiguration xmlConfig = new XmlPlexusConfiguration("analysisConfiguration"); extensionCheck: for (Map.Entry<String, ModelNode> e : extensionSchemas.entrySet()) { String extensionId = e.getKey(); ModelNode schema = e.getValue(); String[] extensionPath = extensionId.split("\\."); ModelNode config = jsonConfig; for (String segment : extensionPath) { if (!config.has(segment)) { continue extensionCheck; } else { config = config.get(segment); } } ConversionContext ctx = new ConversionContext(); ctx.rootSchema = schema; ctx.currentSchema = schema; ctx.pushTag(extensionId); ctx.id = null; ctx.ignorablePaths = extensionSchemas.keySet().stream() .filter(id -> !extensionId.equals(id) && id.startsWith(extensionId)) .collect(Collectors.toList()); PlexusConfiguration extXml = convert(config, ctx); ctx.currentPath.pop(); xmlConfig.addChild(extXml); } return xmlConfig; }
Example #29
Source File: SchemaDrivenJSONToXmlConverter.java From revapi with Apache License 2.0 | 5 votes |
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; }
Example #30
Source File: SchemaDrivenJSONToXmlConverter.java From revapi with Apache License 2.0 | 5 votes |
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; }