Java Code Examples for org.codehaus.plexus.util.xml.Xpp3Dom#getChildCount()

The following examples show how to use org.codehaus.plexus.util.xml.Xpp3Dom#getChildCount() . 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: ReportAggregateMojo.java    From revapi with Apache License 2.0 6 votes vote down vote up
protected static String[] getArtifacts(Xpp3Dom config, String artifactTag) {
    Xpp3Dom oldArtifactsXml = config == null ? null : config.getChild(artifactTag);

    if (oldArtifactsXml == null) {
        return new String[0];
    }

    if (oldArtifactsXml.getChildCount() == 0) {
        String artifact = oldArtifactsXml.getValue();
        return new String[]{artifact};
    } else {
        String[] ret = new String[oldArtifactsXml.getChildCount()];
        for (int i = 0; i < oldArtifactsXml.getChildCount(); ++i) {
            ret[i] = oldArtifactsXml.getChild(i).getValue();
        }

        return ret;
    }
}
 
Example 2
Source File: ModelIO.java    From pom-manipulation-ext with Apache License 2.0 6 votes vote down vote up
/**
 * Recursively process the DOM elements to inline any property values from the model.
 */
private void processChildren( Properties userProperties, Model model, Xpp3Dom parent )
{
    for ( int i = 0; i < parent.getChildCount(); i++ )
    {
        Xpp3Dom child = parent.getChild( i );

        if ( child.getChildCount() > 0 )
        {
            processChildren( userProperties, model, child );
        }
        if ( child.getValue() != null && child.getValue().startsWith( "${" ) )
        {
            String replacement = resolveProperty( userProperties, model.getProperties(), child.getValue() );

            if ( replacement != null && !replacement.isEmpty() )
            {
                logger.debug( "Replacing child value {} with {}", child.getValue(), replacement );
                child.setValue( replacement );
            }
        }

    }
}
 
Example 3
Source File: PluginPropertyUtils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
static @NonNull ConfigurationBuilder<Properties> propertiesBuilder(final @NonNull String propertyParameter) {
    return new ConfigurationBuilder<Properties>() {
        @Override
        public Properties build(Xpp3Dom conf, ExpressionEvaluator eval) {
            if (conf != null) {

                Xpp3Dom source = conf.getChild(propertyParameter);
                if (source != null) {
                    Properties toRet = new Properties();
                    Xpp3Dom[] childs = source.getChildren();
                    for (Xpp3Dom ch : childs) {
                            String val = ch.getValue();
                            if (val == null) {
                                //#168036
                                //we have the "property" named element now.
                                if (ch.getChildCount() == 2) {
                                    Xpp3Dom nameDom = ch.getChild("name"); //NOI18N
                                    Xpp3Dom valueDom = ch.getChild("value"); //NOI18N
                                    if (nameDom != null && valueDom != null) {
                                        String name = nameDom.getValue();
                                        String value = valueDom.getValue();
                                        if (name != null && value != null) {
                                            toRet.put(name, value);  //NOI18N
                                        }
                                    }
                                }
                                // #153063, #187648
                                toRet.put(ch.getName(), "");
                                continue;
                            }
                            toRet.put(ch.getName(), val.trim());  //NOI18N
                    }
                    return toRet;
                }
            }
            return null;
        }
    };
}
 
Example 4
Source File: NetbeansBuildActionJDOMWriter.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Method findAndReplaceXpp3DOM.
 * 
 * @param counter
 * @param dom
 * @param name
 * @param parent
 * @return Element
 */
protected Element findAndReplaceXpp3DOM(Counter counter, Element parent, String name, Xpp3Dom dom)
{
    boolean shouldExist = dom != null && (dom.getChildCount() > 0 || dom.getValue() != null);
    Element element = updateElement(counter, parent, name, shouldExist);
    if (shouldExist) {
        replaceXpp3DOM(element, dom, new Counter(counter.getDepth() + 1));
    }
    return element;
}
 
Example 5
Source File: MavenUtils.java    From developer-studio with Apache License 2.0 5 votes vote down vote up
public static boolean removeXpp3Node(Xpp3Dom parent,Xpp3Dom child) {
	int removeIndex=-1;
	for(int i=0;i<parent.getChildCount();i++){
		if (parent.getChild(i)==child){
			removeIndex=i;
			break;
		}
	}
	if (removeIndex==-1){
		return false;
	}else{
		parent.removeChild(removeIndex);
		return true;
	}
}
 
Example 6
Source File: Utils.java    From pom-manipulation-ext with Apache License 2.0 5 votes vote down vote up
/**
 * Method findAndReplaceXpp3DOM.
 * 
 * @param counter
 * @param dom
 * @param name
 * @param parent
 * @return Element
 */
public static Element findAndReplaceXpp3DOM( final IndentationCounter counter, final Element parent,
                                             final String name, final Xpp3Dom dom )
{
    final boolean shouldExist = ( dom != null ) && ( dom.getChildCount() > 0 || dom.getValue() != null );
    final Element element = updateElement( counter, parent, name, shouldExist );
    if ( shouldExist )
    {
        replaceXpp3DOM( element, dom, new IndentationCounter( counter.getDepth() + 1 ) );
    }
    return element;
}
 
Example 7
Source File: ExecuteMojoUtil.java    From ci.maven with Apache License 2.0 5 votes vote down vote up
/**
 * Strip all config elements except the ones in the goalParams list.
 * 
 * @param config existing config
 * @param goalParams the config elements to keep
 * @return config with non applicable elements removed
 */
private static Xpp3Dom stripConfigElements(Xpp3Dom config, ArrayList<String> goalParams) {
    // strip non applicable parameters
    List<Integer> removeChildren = new ArrayList<Integer>();
    for (int i=0; i<config.getChildCount(); i++) {
        if (!goalParams.contains(config.getChild(i).getName().trim())) {
            removeChildren.add(i);
        }
    }
    Collections.reverse(removeChildren);
    for (int child : removeChildren) {
        config.removeChild(child);
    }
    return config;
}
 
Example 8
Source File: MavenConfigurationExtractor.java    From jkube with Eclipse Public License 2.0 4 votes vote down vote up
private static boolean isSimpleType(Xpp3Dom currentElement) {
    return currentElement.getChildCount() == 0;
}