Example usage for org.jdom2 Element getChild

List of usage examples for org.jdom2 Element getChild

Introduction

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

Prototype

public Element getChild(final String cname, final Namespace ns) 

Source Link

Document

This returns the first child element within this element with the given local name and belonging to the given namespace.

Usage

From source file:com.sun.syndication.io.impl.SyModuleParser.java

License:Open Source License

public Module parse(Element syndRoot) {
    boolean foundSomething = false;
    SyModule sm = new SyModuleImpl();

    Element e = syndRoot.getChild("updatePeriod", getDCNamespace());
    if (e != null) {
        foundSomething = true;//  www  .  j  av  a2 s  .  c  o  m
        sm.setUpdatePeriod(e.getText());
    }
    e = syndRoot.getChild("updateFrequency", getDCNamespace());
    if (e != null) {
        foundSomething = true;
        sm.setUpdateFrequency(Integer.parseInt(e.getText().trim()));
    }
    e = syndRoot.getChild("updateBase", getDCNamespace());
    if (e != null) {
        foundSomething = true;
        sm.setUpdateBase(DateParser.parseDate(e.getText()));
    }
    return (foundSomething) ? sm : null;
}

From source file:com.tactfactory.harmony.dependencies.android.sdk.AndroidSDKManager.java

License:Open Source License

/**
 * Find the latest SDK Tools link./*from  www.  j  a v  a  2s  .c o  m*/
 * 
 * @param platform The user platform
 * @return The latest SDK tools link
 */
public final String findLatestSDKToolsLink(final String platform) {
    String result = null;

    Document document = XMLUtils.getRemoteXML(SDK_URL + XML_REPO_FILE);
    Element root = document.getRootElement();
    Namespace ns = root.getNamespace("sdk");

    Element sdkTool = root.getChild("tool", ns);
    List<Element> sdkArchives = sdkTool.getChild("archives", ns).getChildren();

    for (Element sdkArchive : sdkArchives) {
        if (sdkArchive.getAttribute("os").getValue().equals(platform)) {
            result = SDK_URL + sdkArchive.getChildText("url", ns);
        }
    }

    return result;
}

From source file:com.thoughtworks.go.util.ConfigUtil.java

License:Apache License

private Element child(Element e, ConfigTag tag) {
    return e.getChild(tag.value(), Namespace.getNamespace(tag.namespacePrefix(), tag.namespaceURI()));
}

From source file:com.xebialabs.overcast.support.libvirt.JDomUtil.java

License:Apache License

public static String getElementText(Element parent, String localName, Namespace ns) {
    if (parent == null) {
        throw new IllegalArgumentException("parent element not found");
    }/*from www.ja v a 2s  . c  o  m*/
    Element child = parent.getChild(localName, ns);
    if (child == null) {
        throw new IllegalArgumentException(String.format("child element '%s' not found", localName));
    }
    return child.getText();
}

From source file:com.xebialabs.overcast.support.libvirt.Metadata.java

License:Apache License

/**
 * Extract {@link Metadata} from the domain XML. Throws {@link IllegalArgumentException} if the metadata is
 * malformed./*from ww  w.ja va 2s  .c  om*/
 *
 * @return the metadata or <code>null</code> if there's no metadata
 */
public static Metadata fromXml(Document domainXml) {
    try {
        SimpleDateFormat sdf = new SimpleDateFormat(XML_DATE_FORMAT);
        Element metadata = getMetadataElement(domainXml);
        if (metadata == null) {
            return null;
        }
        Namespace ns = Namespace.getNamespace(METADATA_NS_V1);
        Element ocMetadata = metadata.getChild(OVERCAST_METADATA, ns);
        if (ocMetadata == null) {
            return null;
        }
        String parentDomain = getElementText(ocMetadata, PARENT_DOMAIN, ns);
        String creationTime = getElementText(ocMetadata, CREATION_TIME, ns);
        Date date = sdf.parse(creationTime);

        if (ocMetadata.getChild(PROVISIONED_WITH, ns) != null) {
            String provisionedWith = getElementText(ocMetadata, PROVISIONED_WITH, ns);
            String checkSum = getElementText(ocMetadata, PROVISIONED_CHECKSUM, ns);

            return new Metadata(parentDomain, provisionedWith, checkSum, date);
        }
        return new Metadata(parentDomain, date);
    } catch (ParseException e) {
        throw new IllegalArgumentException("Invalid date in metadata on domain", e);
    }
}

From source file:compile.util.Pom.java

public String getParentArtifactId() {
    Element racine = _xmlUtil.getRacine();
    Element projectParent = racine.getChild("parent", null);
    Element parentArtifactId = projectParent.getChild("artifactId", null);
    return parentArtifactId.getText();
}

From source file:compile.util.Pom.java

public String getArtifactId() {
    Element racine = _xmlUtil.getRacine();
    Element projectArtifactId = racine.getChild("artifactId", null);
    return projectArtifactId.getText();
}

From source file:compile.util.Pom.java

public String getVersion() {
    Element racine = _xmlUtil.getRacine();
    Element projectVersion = racine.getChild("version", null);
    return projectVersion.getText();
}

From source file:compile.util.Pom.java

public HashMap<String, String> getMapDependencies() {
    HashMap<String, String> mapDependenciesProject = new HashMap<String, String>();
    Element racine = _xmlUtil.getRacine();
    Element projectDependencies = racine.getChild("dependencies", null);
    List<Element> listProjectDependencies = projectDependencies.getChildren("dependency", null);
    for (Element elem : listProjectDependencies) {
        mapDependenciesProject.put(elem.getChild("artifactId", null).getText(),
                elem.getChild("version", null).getText());
    }/* ww w  . j a  v a2 s .  c o m*/
    return mapDependenciesProject;
}

From source file:compile.util.Tomcat.java

public void checkIfInContextFile(Project proj) {
    LogService.tomcatAddingContext(/* w w w  .jav a2s  .c om*/
            PropertiesFile.getInstance().getPropertiesUtil().getParam("workingDirContext"));
    Element racine = _serverXml.getRacine();
    Element service = racine.getChild("Service", null);
    Element engine = service.getChild("Engine", null);
    Element host = engine.getChild("Host", null);
    List<Element> listContext = host.getChildren("Context", null);
    boolean notInContext = true;
    for (Element context : listContext) {
        if (context.getAttributeValue("docBase")
                .equals(proj.getPathProject() + SEP + "target" + SEP + proj.getWebappName())) {
            notInContext = false;
        }
    }
    if (notInContext) {
        host.addContent(new Element("Context")
                .setAttribute("docBase", proj.getPathProject() + SEP + "target" + SEP + proj.getWebappName())
                .setAttribute("path",
                        PropertiesFile.getInstance().getPropertiesUtil().getParam("workingDirContext"))
                .setAttribute("reloadable", "true"));
        _serverXml.save();
    }
}