Example usage for org.jdom2 Element getChildren

List of usage examples for org.jdom2 Element getChildren

Introduction

In this page you can find the example usage for org.jdom2 Element getChildren.

Prototype

public List<Element> getChildren(final String cname, final Namespace ns) 

Source Link

Document

This returns a List of all the child elements nested directly (one level deep) within this element with the given local name and belonging to the given Namespace, returned as Element objects.

Usage

From source file:de.nava.informa.utils.AtomParserUtils.java

License:Open Source License

/**
 * Looks for link sub-elements of type "link" and selects the most preferred.
 *
 * @param item  item element./*www . ja v a2  s  .  c o m*/
 * @param defNS default namespace.
 * @return link in string or <code>null</code>.
 */
public static String getItemLink(Element item, Namespace defNS) {
    String currentHref = null;
    int currentOrder = Integer.MAX_VALUE;

    List links = item.getChildren("link", defNS);

    for (int i = 0; (currentOrder != 0) && (i < links.size()); i++) {
        Element link = (Element) links.get(i);

        // get type of the link
        String type = link.getAttributeValue("type");
        String rel = link.getAttributeValue("rel");

        if (type != null) {
            type = type.trim().toLowerCase();
        }

        // if we prefer this type more than the one we already have then
        // replace current href with new one and update preference order
        // value.
        int preferenceOrder = getPreferenceOrderForItemLinkType(type, rel);

        LOGGER.info("Link " + link.getAttributeValue("href") + " with pref "
                + getPreferenceOrderForItemLinkType(type, rel) + " " + type + " " + rel);

        if (preferenceOrder < currentOrder) {
            String href = link.getAttributeValue("href");

            if (href != null) {
                currentHref = href.trim();
                currentOrder = preferenceOrder;
            }
        }
    }

    LOGGER.debug("url read : " + currentHref);

    return currentHref;
}

From source file:de.smartics.maven.alias.domain.AliasesProcessor.java

License:Apache License

/**
 * Applies the alias information from the XML file to the given
 * {@code builders}.//from  w  ww . j av  a  2s . com
 *
 * @param builders the builders to create alias scripts.
 */
public void process(final AliasCollector... builders) {
    final Element root = doc.getRootElement();

    for (final Element extensionElement : root.getChildren("extension", nsAlias)) {
        final AliasExtension extension = createExtension(extensionElement);
        final ExtensionGroup extensionGroup = new ExtensionGroup(extension);
        extensionGroups.add(extensionGroup);
    }

    for (final Element groupElement : root.getChildren("group", nsAlias)) {
        final Attribute groupName = groupElement.getAttribute("name");
        final String comment = readComment(groupElement);
        final AliasGroup group = new AliasGroup(groupName.getValue(), comment);
        for (final Element aliasElement : groupElement.getChildren("alias", nsAlias)) {
            final Alias alias = createAlias(aliasElement);
            for (final ExtensionGroup extensionGroup : extensionGroups) {
                extensionGroup.addAlias(group.getName(), alias);
            }
            group.addAlias(alias);
        }

        for (final AliasCollector builder : builders) {
            builder.addAliases(group);
        }
    }

    for (final AliasCollector builder : builders) {
        builder.setExtensionGroups(extensionGroups);
    }
}

From source file:de.smartics.maven.alias.domain.AliasesProcessor.java

License:Apache License

private void appendApplyTos(final Element extensionElement, final AliasExtension.Builder builder) {
    final Element applyToElement = extensionElement.getChild("apply-to", nsAlias);
    if (applyToElement != null) {
        for (final Element groupElement : applyToElement.getChildren("group", nsAlias)) {
            final String group = groupElement.getTextNormalize();
            builder.addGroup(group);//  w  w  w  .  jav a  2s . c o  m
        }

        for (final Element aliasElement : applyToElement.getChildren("alias", nsAlias)) {
            final String alias = aliasElement.getTextNormalize();
            builder.addAlias(alias);
        }
    }
}

From source file:de.smartics.maven.plugin.jboss.modules.parser.AbstractArtifactClusionAdder.java

License:Apache License

public void addClusions(final Element matchElement) {
    final Element clusionsElement = matchElement.getChild(collectionElementId, NS);
    if (clusionsElement != null) {
        final List<Element> clusionElements = clusionsElement.getChildren(elementId, NS);
        for (final Element clusionElement : clusionElements) {
            final ArtifactClusion clusion = new ArtifactClusion();
            final String groupId = clusionElement.getChildText("groupId", NS);
            final String artifactId = clusionElement.getChildText("artifactId", NS);
            clusion.setGroupId(groupId);
            clusion.setArtifactId(artifactId);
            add(clusion);//from  ww w .j  ava  2 s.  c o m
        }
    }
}

From source file:de.smartics.maven.plugin.jboss.modules.parser.AbstractArtifactClusionAdderV2.java

License:Apache License

public void addClusions(final Element matchElement) {
    if (matchElement != null) {
        final List<Element> clusionElements = matchElement.getChildren(elementId, NS);
        for (final Element clusionElement : clusionElements) {
            final ArtifactClusion clusion = new ArtifactClusion();
            String artifact = clusionElement.getAttributeValue("artifact");
            String[] split = split(artifact, ":", 2);
            final String groupId = split.length == 2 ? split[0] : null;
            final String artifactId = split.length == 2 ? split[1] : split[0];
            clusion.setGroupId(groupId);
            clusion.setArtifactId(artifactId);
            add(clusion);/*from w ww  .  j a  v a 2s. c  o m*/
        }
    }
}

From source file:de.smartics.maven.plugin.jboss.modules.parser.AbstractModuleClusionAdder.java

License:Apache License

public void addClusions(final Element matchElement) {
    final Element clusionsElement = matchElement.getChild(collectionElementId, NS);
    if (clusionsElement != null) {
        final List<Element> clusionElements = clusionsElement.getChildren(elementId, NS);
        for (final Element clusionElement : clusionElements) {
            final String name = clusionElement.getTextNormalize();
            final ModuleClusion clusion = new ModuleClusion(name);
            add(clusion);/*from w ww . j av  a2s  . c om*/
        }
    }
}

From source file:de.smartics.maven.plugin.jboss.modules.parser.AbstractModuleClusionAdderV2.java

License:Apache License

public void addClusions(final Element matchElement) {
    if (matchElement != null) {
        final List<Element> clusionElements = matchElement.getChildren(elementId, NS);
        for (final Element clusionElement : clusionElements) {
            final String name = clusionElement.getAttributeValue("module");
            final ModuleClusion clusion = new ModuleClusion(name);
            add(clusion);/*from  w w  w.j av a 2 s . c  om*/
        }
    }
}

From source file:de.smartics.maven.plugin.jboss.modules.parser.ModulesDescriptorBuilder.java

License:Apache License

/**
 * Starts the parsing of the document.//from w  ww. j  a  va 2 s.c  o m
 *
 * @return the parsed information.
 */
public ModulesDescriptor build() {
    final Element rootElement = document.getRootElement();

    final List<Element> moduleElements = rootElement.getChildren("module", NS);
    for (final Element moduleElement : moduleElements) {
        parseModule(moduleElement);
    }

    return modulesDescriptor;
}

From source file:de.smartics.maven.plugin.jboss.modules.parser.ModulesDescriptorBuilder.java

License:Apache License

private void parseApplyToDependencies(final Element applyToDependenciesElement) {
    if (applyToDependenciesElement == null) {
        return;/* ww w .  j av  a  2s .  c  o m*/
    }

    final ApplyToDependencies.Builder builder = new ApplyToDependencies.Builder();

    final List<Element> dependenciesElements = applyToDependenciesElement.getChildren("dependencies", NS);
    for (final Element dependenciesElement : dependenciesElements) {
        final DependenciesDescriptor.Builder dependencyBuilder = new DependenciesDescriptor.Builder();
        parseMatcher(dependencyBuilder, dependenciesElement);
        parseApply(dependencyBuilder, dependenciesElement);

        final DependenciesDescriptor dependencies = dependencyBuilder.build();
        builder.add(dependencies);
    }

    final ApplyToDependencies applyToDependencies = builder.build();
    this.builder.with(applyToDependencies);
}

From source file:de.smartics.maven.plugin.jboss.modules.parser.ModulesDescriptorBuilder.java

License:Apache License

private void handleChild(final ApplyToModule.Builder mBuilder, final XMLOutputter outputter,
        final Element child) {
    final String elementName = child.getName();
    if ("dependencies".equals(elementName)) {
        handleDependencies(mBuilder, outputter, child);
    } else if ("properties".equals(elementName)) {
        for (final Element propertyElement : child.getChildren("property", ModuleXmlBuilder.NS)) {
            final String name = propertyElement.getAttributeValue("name");
            final String fragment = outputter.outputString(propertyElement);
            mBuilder.addPropertyXml(name, fragment);
        }//www  .  j  a v a 2s . c om
    } else if ("exports".equals(elementName)) {
        final String fragment = outputter.outputString(child);
        mBuilder.withExportsXml(fragment);
    } else if ("main-class".equals(elementName)) {
        final String fragment = outputter.outputString(child);
        mBuilder.withMainClassXml(fragment);
    } else if ("resource-root".equals(elementName)) {
        final String fragment = outputter.outputString(child);
        mBuilder.addResourceRootXml(fragment);
    } else {
        // TODO warn or add to end?
    }
}