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:de.huberlin.german.korpling.laudatioteitool.SplitTEI.java

License:Apache License

private TEIValidator.Errors extractDocumentHeaders(Document doc)
        throws LaudatioException, IOException, SAXException {
    TEIValidator validator = documentSchemeURL == null ? new TEIDocumentValidator()
            : new FromURLValidator(documentSchemeURL);

    File documentDir = new File(outputDirectory, "DocumentHeader");
    if (!documentDir.exists() && !documentDir.mkdir()) {
        throw new LaudatioException(
                messages.getString("COULD NOT CREATE DIRECTORY") + documentDir.getAbsolutePath());
    }//from   ww w.  jav  a 2  s.  co  m

    Element documentRoot = Preconditions.checkNotNull(doc.getRootElement().getChild("teiCorpus", null));

    for (Element docHeader : documentRoot.getChildren("teiHeader", null)) {
        Preconditions.checkState("DocumentHeader".equals(docHeader.getAttributeValue("type")));

        // create the subtree for the global corpus header
        Namespace teiNS = Namespace.getNamespace("http://www.tei-c.org/ns/1.0");
        Element tei = new Element("TEI", teiNS);
        tei.addContent(docHeader.clone());
        Document newDoc = new Document(tei);

        if (documentSchemeURL == null) {
            newDoc.addContent(0, new ProcessingInstruction("xml-model",
                    "href=\"" + TEIDocumentValidator.DEFAULT_SCHEME_URL + "\""));
        } else {
            newDoc.addContent(0, new ProcessingInstruction("xml-model", "href=\"" + documentSchemeURL + "\""));
        }

        // we need to append an empty "text" element after the header
        Element text = new Element("text", teiNS);
        text.setText("");
        tei.addContent(text);

        Element fileDesc = Preconditions
                .checkNotNull(tei.getChild("teiHeader", null).getChild("fileDesc", null));

        String outName = UUID.randomUUID().toString();

        String id = fileDesc.getAttributeValue("id", Namespace.XML_NAMESPACE);
        if (id != null) {
            outName = id;
        } else {
            Element titleStmt = Preconditions.checkNotNull(fileDesc.getChild("titleStmt", null));

            String title = titleStmt.getChildText("title", null);
            if (title != null) {
                outName = title;
            }
        }

        File outputFile = new File(documentDir, outName + ".xml");
        XMLOutputter xmlOut = new XMLOutputter(Format.getPrettyFormat());
        xmlOut.output(newDoc, new OutputStreamWriter(new FileOutputStream(outputFile), "UTF-8"));
        log.info(messages.getString("WRITTEN DOCUMENT HEADER"), outputFile.getPath());

        validator.validate(outputFile);

    }
    return validator.getErrors();
}

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);/* w w  w  .ja  v  a2  s  . co m*/
        }
    }
}

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

License:Apache License

private void parseDirectives(final Element directivesElement) {
    if (directivesElement == null) {
        return;/*from  ww  w. ja v a  2 s . com*/
    }

    final Directives.Builder builder = new Directives.Builder();
    final String skip = directivesElement.getChildText("skip", NS);
    builder.withSkip(skip);
    final String inheritSlot = directivesElement.getChildText("inherit-slot", NS);
    builder.withInheritSlot(inheritSlot);
    final Directives directives = builder.build();
    this.builder.with(directives);
}

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

License:Apache License

private void parseApply(final Builder builder, final Element dependenciesElement) {
    final Element applyElement = dependenciesElement.getChild("apply", NS);
    if (applyElement == null) {
        return;/*from  ww  w .  j a va  2s . c o m*/
    }

    final String slot = applyElement.getChildText("slot", NS);
    final String skip = applyElement.getChildText("skip", NS);
    final String export = applyElement.getChildText("export", NS);
    final String services = applyElement.getChildText("services", NS);
    final String optional = applyElement.getChildText("optional", NS);

    builder.withSlot(slot);
    builder.withSkip(skip);
    builder.withExport(export);
    builder.withServices(services);
    builder.withOptional(optional);

    final XMLOutputter outputter = new XMLOutputter(Format.getCompactFormat());
    final Element importElement = applyElement.getChild("imports", NS);
    if (importElement != null) {
        adjustNamespaces(importElement);
        final String imports = outputter.outputString(importElement);
        builder.withImportsXml(imports);
    }
    final Element exportElement = applyElement.getChild("exports", NS);
    if (exportElement != null) {
        adjustNamespaces(exportElement);
        final String exports = outputter.outputString(exportElement);
        builder.withExportsXml(exports);
    }
}

From source file:de.sub.goobi.helper.HelperSchritte.java

License:Open Source License

public static void extractAuthorityMetadata(Path metadataFile, Map<String, List<String>> metadataPairs) {
    XPathFactory xFactory = XPathFactory.instance();
    XPathExpression<Element> authorityMetaXpath = xFactory.compile(
            "//mets:xmlData/mods:mods/mods:extension/goobi:goobi/goobi:metadata[goobi:authorityValue]",
            Filters.element(), null, mods, mets, goobiNamespace);
    SAXBuilder builder = new SAXBuilder();
    Document doc;/*from  www . j av  a  2s  .co m*/
    try {
        doc = builder.build(metadataFile.toString());
    } catch (JDOMException | IOException e1) {
        return;
    }
    for (Element meta : authorityMetaXpath.evaluate(doc)) {
        String name = meta.getAttributeValue("name");
        if (name == null) {
            continue;
        } else {
            String key = name + "_authority";
            List<String> values = metadataPairs.get(key);
            if (values == null) {
                values = new ArrayList<>();
                metadataPairs.put(key, values);
            }
            values.add(meta.getChildText("authorityValue", goobiNamespace));
        }
    }
}

From source file:edu.unc.lib.dl.xml.JDOMQueryUtil.java

License:Apache License

public static Date parseISO6392bDateChild(Element parent, String childName, Namespace namespace) {
    String dateString = parent.getChildText(childName, namespace);
    if (dateString != null) {
        try {// w w w.  j  a  v  a  2  s  .com
            return DateTimeUtil.parsePartialUTCToDate(dateString);
        } catch (ParseException e) {
            // Wasn't a valid date, ignore it.
        } catch (IllegalArgumentException e) {
            // Wasn't a valid date, ignore it.
        }
    }
    return null;
}

From source file:fr.d4delta.launcher.Dependency.java

License:Open Source License

public Dependency(Element reference, File rootFolder, Callback callback, Namespace namespace) {
    this(Utils.substituteMaven(reference.getChildText("groupId", namespace)),
            Utils.substituteMaven(reference.getChildText("artifactId", namespace)),
            Utils.substituteMaven(reference.getChildText("version", namespace)), rootFolder, callback);
}

From source file:fr.d4delta.launcher.Launcher.java

License:Open Source License

private void registerRepositories(Element pom, Namespace namespace) {
    List<Element> repos;
    try {//  www .  j  a  v  a  2s . c  o m
        repos = pom.getChild("repositories", namespace).getChildren("repository", namespace);
    } catch (NullPointerException ex) {
        return;
    }

    for (Element e : repos) {
        String id = Utils.substituteMaven(e.getChildText("id", namespace));
        String url = Utils.substituteMaven(e.getChildText("url", namespace));
        callback.addingRepositoryNotification(id, url);
        repositories.put(id, new Repository(id, url));
    }
}

From source file:fr.d4delta.launcher.Launcher.java

License:Open Source License

private void loadReference(Element reference, Namespace namespace) {

    {//from   ww  w .  j a v  a 2  s. co m
        String scope = reference.getChildText("scope", namespace);
        if (scope != null && (!scope.equals("runtime") || !scope.equals("compile")))
            return;

        String optional = reference.getChildText("optional", namespace);
        if (optional != null && optional.equals("true"))
            return;
    }

    Dependency dependency = new Dependency(reference, rootFolder, callback, namespace);

    if (isLoaded.get(dependency.groupId + dependency.artifactId + dependency.version) != null) {
        return;
    }

    callback.loadingDependencyNotification(dependency);

    if (!findRemote(dependency)) {
        callback.dependencyUnavailableError(dependency);
    } else {
        downloadDependency(dependency);
    }
}

From source file:net.exclaimindustries.paste.braket.server.TeamDownloader.java

License:Open Source License

public static Team parseTeam(Document document) throws MalformedURLException {
    // Parse out the details
    Element rootNode = document.getRootElement();

    // I need the espn namespace
    List<Namespace> namespaceList = rootNode.getNamespacesInScope();
    Namespace ns = Namespace.NO_NAMESPACE;
    for (Namespace namespace : namespaceList) {
        if (namespace.getPrefix() == "espn") {
            ns = namespace;//w w  w . j a  va 2  s  .  c om
            break;
        }
    }

    // Find the "item" element that has the right stuff in it
    Element channel = rootNode.getChild("channel");
    List<Element> items = channel.getChildren("item");
    Element teamElement = null;
    for (Element item : items) {
        if (item.getChild("teamAbbrev", ns) != null) {
            teamElement = item.clone();
            break;
        }
    }

    if (teamElement == null) {
        // Couldn't find any info about the team, so skip it.
        return null;
    }

    // Make sure that the given ID matches the ID in the team (else this
    // is not a real team)
    Long teamId = Long.valueOf(teamElement.getChildText("teamId", ns));

    Team team = new Team();
    team.setId(teamId);

    String abbreviation = digOutCDATA(teamElement, "teamAbbrev", ns);
    String displayName = digOutCDATA(teamElement, "teamDisplayName", ns);
    String location = digOutCDATA(teamElement, "teamLocation", ns);
    String nickname = digOutCDATA(teamElement, "teamNickname", ns);
    String teamNameString = teamElement.getChildText("teamName", ns);
    String teamColorString = "#" + teamElement.getChildText("teamColor", ns);
    String teamLogoUrl = teamElement.getChildText("teamLogo", ns);

    TeamName teamName = new TeamName(location, teamNameString, displayName, nickname, abbreviation);
    team.setName(teamName);

    try {
        if (teamColorString != null) {
            RGBAColor color = RGBAColor.fromCSSString(teamColorString);
            team.setColor(color);
        }
    } catch (Exception e) {
        // TODO Is this okay?
    }

    // Save the image name (should be the same as the downloaded version)
    URL url = new URL(teamLogoUrl);
    File file = new File(url.getPath());
    String teamLogoName = file.getName();
    team.setPicture(teamLogoName);

    return team;
}