Example usage for org.jdom2 Element getChildText

List of usage examples for org.jdom2 Element getChildText

Introduction

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

Prototype

public String getChildText(final String cname, final Namespace ns) 

Source Link

Document

Returns the textual content of the named child element, or null if there's no such child.

Usage

From source file:org.helm.notation2.tools.MonomerParser.java

License:Open Source License

/**
 * Convert monomer element to Monomer object
 *
 * @param monomer element/*  www . j  a va2 s .c  o  m*/
 * @return Monomer
 */
public static Monomer getMonomer(Element monomer) throws MonomerException {
    Monomer m = new Monomer();
    Namespace ns = monomer.getNamespace();
    m.setAlternateId(monomer.getChildText(MONOMER_ID_ELEMENT, ns));
    m.setCanSMILES(monomer.getChildText(MONOMER_SMILES_ELEMENT, ns));
    String encodedMolfile = monomer.getChildText(MONOMER_MOL_FILE_ELEMENT, ns);

    String molfile = null;
    try {
        molfile = MolfileEncoder.decode(encodedMolfile);
    } catch (EncoderException ex) {
        throw new MonomerException("Invalid monomer molfile");
    }
    m.setMolfile(molfile);
    m.setMonomerType(monomer.getChildText(MONOMER_TYPE_ELEMENT, ns));
    m.setPolymerType(monomer.getChildText(POLYMER_TYPE_ELEMENT, ns));
    m.setNaturalAnalog(monomer.getChildText(NATURAL_ANALOG_ELEMENT, ns));
    m.setName(monomer.getChildText(MONOMER_NAME_ELEMENT, ns));
    Element attachmentElement = monomer.getChild(ATTACHEMENTS_ELEMENT, ns);

    if (null != attachmentElement) {
        List attachments = attachmentElement.getChildren(ATTACHEMENT_ELEMENT, ns);
        List<Attachment> l = new ArrayList<Attachment>();
        Iterator i = attachments.iterator();
        while (i.hasNext()) {
            Element attachment = (Element) i.next();
            Attachment att = getAttachment(attachment);
            l.add(att);
        }
        m.setAttachmentList(l);
    }
    return m;
}

From source file:org.mycore.mods.MCRMODSPagesHelper.java

License:Open Source License

void completeEndPage(Element extent) {
    String start = extent.getChildText("start", MCRConstants.MODS_NAMESPACE);
    String end = extent.getChildText("end", MCRConstants.MODS_NAMESPACE);
    if (isNumber(start) && isNumber(end) && start.length() > end.length()) {
        end = start.substring(0, start.length() - end.length()) + end;
        extent.getChild("end", MCRConstants.MODS_NAMESPACE).setText(end);
    }//from  w  w w .ja v a2  s  . c  om
}

From source file:org.mycore.oai.MCROAIObjectManager.java

License:Open Source License

Header headerToHeader(Element headerElement) {
    String id = headerElement.getChildText("identifier", OAIConstants.NS_OAI);
    String datestampString = headerElement.getChildText("datestamp", OAIConstants.NS_OAI);
    if (id == null || datestampString == null) {
        return null;
    }/*from w  w  w.ja  va  2  s.c om*/
    Date datestamp = DateUtils.parseUTC(datestampString);
    Header header = new Header(id, datestamp);
    if (!exists(id)) {
        header.setDeleted(true);
    }
    for (Object setSpec : headerElement.getChildren("setSpec", OAIConstants.NS_OAI)) {
        header.getSetList().add(setToSet((Element) setSpec));
    }
    return header;
}

From source file:org.mycore.oai.MCROAISetManager.java

License:Open Source License

private Set createSet(String setId, Element setElement) {
    String setSpec = setElement.getChildText("setSpec", NS_OAI);
    String setName = setElement.getChildText("setName", NS_OAI);
    Set set = new Set(getSetSpec(setId, setSpec), setName);
    set.getDescription().addAll(setElement.getChildren("setDescription", NS_OAI).stream() //all setDescription
            .flatMap(e -> e.getChildren().stream().limit(1)) //first childElement of setDescription
            .peek(Element::detach).map(d -> (Description) new Description() {
                @Override/*  w w w  .j av  a  2 s .c om*/
                public Element toXML() {
                    return d;
                }

                @Override
                public void fromXML(Element descriptionElement) {
                    throw new UnsupportedOperationException();
                }
            }).collect(Collectors.toList()));
    return set;
}

From source file:org.rometools.feed.module.sle.io.ModuleParser.java

License:Apache License

/**
 * Parses the XML node (JDOM element) extracting module information.
 * <p>/*from   www .  j  a  v a2s .c  om*/
 *
 * @param element the XML node (JDOM element) to extract module information from.
 * @return a module instance, <b>null</b> if the element did not have module information.
 */
public Module parse(Element element) {
    if (element.getChild("treatAs", NS) == null) {
        return null;
    }

    SimpleListExtension sle = new SimpleListExtensionImpl();
    sle.setTreatAs(element.getChildText("treatAs", NS));

    Element listInfo = element.getChild("listinfo", NS);
    List groups = listInfo.getChildren("group", NS);
    ArrayList values = new ArrayList();

    for (int i = 0; (groups != null) && (i < groups.size()); i++) {
        Element ge = (Element) groups.get(i);
        Namespace ns = (ge.getAttribute("ns") == null) ? element.getNamespace()
                : Namespace.getNamespace(ge.getAttributeValue("ns"));
        String elementName = ge.getAttributeValue("element");
        String label = ge.getAttributeValue("label");
        values.add(new Group(ns, elementName, label));
    }

    sle.setGroupFields((Group[]) values.toArray(new Group[values.size()]));
    values = (values.size() == 0) ? values : new ArrayList();

    List sorts = listInfo.getChildren("sort", NS);

    for (int i = 0; (sorts != null) && (i < sorts.size()); i++) {
        Element se = (Element) sorts.get(i);
        System.out.println(
                "Parse cf:sort " + se.getAttributeValue("element") + se.getAttributeValue("data-type"));
        Namespace ns = (se.getAttributeValue("ns") == null) ? element.getNamespace()
                : Namespace.getNamespace(se.getAttributeValue("ns"));
        String elementName = se.getAttributeValue("element");
        String label = se.getAttributeValue("label");
        String dataType = se.getAttributeValue("data-type");
        boolean defaultOrder = (se.getAttributeValue("default") == null) ? false
                : new Boolean(se.getAttributeValue("default")).booleanValue();
        values.add(new Sort(ns, elementName, dataType, label, defaultOrder));
    }

    sle.setSortFields((Sort[]) values.toArray(new Sort[values.size()]));
    insertValues(sle, element.getChildren());

    return sle;
}

From source file:org.savantbuild.dep.maven.POM.java

License:Open Source License

public POM(Path file) throws RuntimeException {
    SAXBuilder builder = new SAXBuilder();
    try {//w  w  w .  j  a  v  a  2s.c  o  m
        Element pomElement = builder.build(file.toFile()).getRootElement();
        version = pomElement.getChildText("version", pomElement.getNamespace());
        if (version != null) {
            properties.put("project.version", version);
        }
        if (pomElement.getChildText("groupId", pomElement.getNamespace()) != null) {
            properties.put("project.groupId", pomElement.getChildText("groupId", pomElement.getNamespace()));
        }
        if (pomElement.getChildText("artifactId", pomElement.getNamespace()) != null) {
            properties.put("project.artifactId",
                    pomElement.getChildText("artifactId", pomElement.getNamespace()));
        }
        if (pomElement.getChildText("name", pomElement.getNamespace()) != null) {
            properties.put("project.name", pomElement.getChildText("name", pomElement.getNamespace()));
        }
        if (pomElement.getChildText("packaging", pomElement.getNamespace()) != null) {
            properties.put("project.packaging",
                    pomElement.getChildText("packaging", pomElement.getNamespace()));
        }

        // Grab the parent info
        Element parent = pomElement.getChild("parent", pomElement.getNamespace());
        if (parent != null) {
            parentGroup = parent.getChildText("groupId", pomElement.getNamespace());
            parentId = parent.getChildText("artifactId", pomElement.getNamespace());
            parentVersion = parent.getChildText("version", pomElement.getNamespace());
        }

        // Grab the properties
        Element properties = pomElement.getChild("properties", pomElement.getNamespace());
        if (properties != null) {
            properties.getChildren()
                    .forEach((element) -> this.properties.put(element.getName(), element.getTextTrim()));
        }

        // Grab the dependencies (top-level)
        Element dependencies = pomElement.getChild("dependencies", pomElement.getNamespace());
        if (dependencies != null) {
            dependencies.getChildren().forEach((element) -> this.dependencies.add(parseArtifact(element)));
        }

        // Grab the dependencyManagement info (top-level)
        Element dependencyManagement = pomElement.getChild("dependencyManagement", pomElement.getNamespace());
        if (dependencyManagement != null) {
            Element depMgntDeps = dependencyManagement.getChild("dependencies",
                    dependencyManagement.getNamespace());
            depMgntDeps.getChildren()
                    .forEach((element) -> this.dependenciesDefinitions.add(parseArtifact(element)));
        }
    } catch (JDOMException | IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.savantbuild.dep.maven.POM.java

License:Open Source License

private MavenArtifact parseArtifact(Element element) {
    MavenArtifact artifact = new MavenArtifact();
    artifact.group = element.getChildText("groupId", element.getNamespace());
    artifact.id = element.getChildText("artifactId", element.getNamespace());
    artifact.version = element.getChildText("version", element.getNamespace());
    artifact.type = element.getChildText("type", element.getNamespace());
    artifact.optional = toBoolean(element.getChildText("optional", element.getNamespace()));
    artifact.scope = element.getChildText("scope", element.getNamespace());
    if (artifact.scope == null) {
        artifact.scope = "compile";
    }//  w ww.j a v a2  s  .  c o m
    if (artifact.optional) {
        artifact.scope += "-optional";
    }

    List<Element> exclusions = element.getChildren("exclusions", element.getNamespace());
    if (exclusions.size() > 0) {
        System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
        System.out.println(
                "This Maven artifact has a dependency [" + artifact + "] with exclusions " + exclusions);
        System.out.println("This indicates that the artifact [" + artifact
                + "] declared a bad dependency or declared an optional dependency as required.");
        System.out.println(
                "There isn't much we can do here since Savant doesn't allow exclusions because they should not occur when dependencies are listed and configured correctly.");
        System.out.println();
    }

    return artifact;
}

From source file:org.yawlfoundation.yawl.logging.YLogPredicate.java

License:Open Source License

public void fromXML(Element xml, Namespace ns) {
    _startPredicate = xml.getChildText("start", ns);
    _completionPredicate = xml.getChildText("completion", ns);
}

From source file:org.yawlfoundation.yawl.resourcing.interactions.AbstractInteraction.java

License:Open Source License

public Map<String, String> parseParams(Element e, Namespace nsYawl) {
    HashMap<String, String> result = new HashMap<String, String>();
    Element eParams = e.getChild("params", nsYawl);
    if (eParams != null) {
        for (Element eParam : eParams.getChildren("param", nsYawl)) {
            result.put(eParam.getChildText("key", nsYawl), eParam.getChildText("value", nsYawl));
        }//  w  w w .  j  a  v a  2 s .  co m
    }
    return result;
}

From source file:org.yawlfoundation.yawl.resourcing.interactions.AllocateInteraction.java

License:Open Source License

public void parse(Element e, Namespace nsYawl) throws ResourceParseException {
    parseInitiator(e, nsYawl);/* ww w.j a  va2 s  .c om*/

    Element eAllocator = e.getChild("allocator", nsYawl);
    if (eAllocator != null) {
        String allocatorClassName = eAllocator.getChildText("name", nsYawl);
        if (allocatorClassName != null) {
            _allocator = PluginFactory.newAllocatorInstance(allocatorClassName);
            if (_allocator != null)
                _allocator.setParams(parseParams(eAllocator, nsYawl));
            else
                throw new ResourceParseException("Unknown allocator name: " + allocatorClassName);
        } else
            throw new ResourceParseException("Missing allocator element: name");
    }
}