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: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);//w  ww . j  a  v  a2 s  .  co m
        }
    }
}

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

License:Apache License

private void parseModule(final Element moduleElement) {
    builder = new ModuleDescriptor.Builder();

    final String moduleName = moduleElement.getAttributeValue("name");
    final String slot = moduleElement.getAttributeValue("slot");
    builder.withName(moduleName);/*from ww  w.ja v  a 2s. c  om*/
    builder.withSlot(slot);

    parseDirectives(moduleElement.getChild("directives", NS));
    parseMatch(moduleElement.getChild("match", NS));
    parseApplyToDependencies(moduleElement.getChild("apply-to-dependencies", NS));
    parseApplyToModule(moduleElement.getChild("apply-to-module", NS));

    final ModuleDescriptor descriptor = builder.build();
    modulesDescriptor.addDescriptor(descriptor);
}

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

License:Apache License

private void parseMatcher(final DependenciesDescriptor.Builder dependencyBuilder,
        final Element dependenciesElement) {
    final Element matchElement = dependenciesElement.getChild("match", NS);
    if (matchElement == null) {
        return;/*from w w  w. j a v  a 2  s . c om*/
    }

    final ModuleMatcher.Builder builder = new ModuleMatcher.Builder();
    new AbstractModuleClusionAdder("includes", "include") {
        @Override
        public void add(final ModuleClusion clusion) {
            builder.addInclude(clusion);
        }
    }.addClusions(matchElement);
    new AbstractModuleClusionAdder("excludes", "exclude") {
        @Override
        public void add(final ModuleClusion clusion) {
            builder.addExclude(clusion);
        }
    }.addClusions(matchElement);

    final ModuleMatcher matcher = builder.build();
    dependencyBuilder.with(matcher);
}

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;/*  w  ww.  j a  v  a 2  s.  co  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.smartics.maven.plugin.jboss.modules.parser.ModulesDescriptorBuilderV2.java

License:Apache License

private void parseApply(final Builder builder, final Element dependenciesElement) {
    if (dependenciesElement == null) {
        return;//from   ww  w.ja v a 2  s. c  om
    }

    final String slot = dependenciesElement.getAttributeValue("slot");
    final String skip = dependenciesElement.getAttributeValue("skip");
    final String export = dependenciesElement.getAttributeValue("export");
    final String services = dependenciesElement.getAttributeValue("services");
    final String optional = dependenciesElement.getAttributeValue("optional");

    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 = dependenciesElement.getChild("imports", NS);
    if (importElement != null) {
        adjustNamespaces(importElement);
        final String imports = outputter.outputString(importElement);
        builder.withImportsXml(imports);
    }
    final Element exportElement = dependenciesElement.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 extractMetadata(Path metadataFile, Map<String, List<String>> metadataPairs) {
    SAXBuilder builder = new SAXBuilder();
    Document doc;//from www. j  ava  2  s  .com
    try {
        doc = builder.build(metadataFile.toString());
    } catch (JDOMException | IOException e1) {
        return;
    }
    Element root = doc.getRootElement();
    try {
        Element goobi = root.getChildren("dmdSec", mets).get(0).getChild("mdWrap", mets)
                .getChild("xmlData", mets).getChild("mods", mods).getChild("extension", mods)
                .getChild("goobi", goobiNamespace);
        List<Element> metadataList = goobi.getChildren();
        addMetadata(metadataList, metadataPairs);
        for (Element el : root.getChildren("dmdSec", mets)) {
            if (el.getAttributeValue("ID").equals("DMDPHYS_0000")) {
                Element phys = el.getChild("mdWrap", mets).getChild("xmlData", mets).getChild("mods", mods)
                        .getChild("extension", mods).getChild("goobi", goobiNamespace);
                List<Element> physList = phys.getChildren();
                addMetadata(physList, metadataPairs);
            }
        }
        // create field for "DocStruct"
        String docType = root.getChildren("structMap", mets).get(0).getChild("div", mets)
                .getAttributeValue("TYPE");
        metadataPairs.put("DocStruct", Collections.singletonList(docType));

    } catch (Exception e) {
        logger.error(e);
        logger.error("Cannot extract metadata from " + metadataFile.toString());
    }
}

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

License:Open Source License

private static void addMetadata(List<Element> elements, Map<String, List<String>> metadataPairs) {
    for (Element goobimetadata : elements) {
        String metadataType = goobimetadata.getAttributeValue("name");
        String metadataValue = "";
        if (goobimetadata.getAttributeValue("type") != null
                && goobimetadata.getAttributeValue("type").equals("person")) {
            Element displayName = goobimetadata.getChild("displayName", goobiNamespace);
            if (displayName != null && !displayName.getValue().equals(",")) {
                metadataValue = displayName.getValue();
            }//from  www.j  av a2 s.  c o  m
        } else if (goobimetadata.getAttributeValue("type") != null
                && goobimetadata.getAttributeValue("type").equals("group")) {
            List<Element> groupMetadataList = goobimetadata.getChildren();
            addMetadata(groupMetadataList, metadataPairs);
        } else {
            metadataValue = goobimetadata.getValue();
        }
        if (!metadataValue.equals("")) {

            if (metadataPairs.containsKey(metadataType)) {
                List<String> oldValue = metadataPairs.get(metadataType);
                if (!oldValue.contains(metadataValue)) {
                    oldValue.add(metadataValue);
                    metadataPairs.put(metadataType, oldValue);
                }
            } else {
                List<String> list = new ArrayList<>();
                list.add(metadataValue);
                metadataPairs.put(metadataType, list);
            }
        }

    }
    return;
}

From source file:de.uniwuerzburg.info3.ofcprobe.vswitch.graphml.GraphmlParser.java

License:Open Source License

/**
 * Constructor/*  ww w  . ja  v a 2  s. c o m*/
 *
 * @param graphml_filename the GraphML Filenam
 */
public GraphmlParser(String graphml_filename) {
    try {
        Document doc = new SAXBuilder().build(graphml_filename);
        Element graphml = doc.getRootElement();
        this.ns = graphml.getNamespace();
        this.graph = graphml.getChild("graph", this.ns);
        List<Element> list = graphml.getChildren("key", ns);
        for (Element e : list) {
            String s = e.getAttributeValue("attr.name");
            switch (s) {
            case "Latitude":
                latitude_key = e.getAttributeValue("id");

                break;
            case "Country":
                country_key = e.getAttributeValue("id");

                break;
            case "Internal":
                internal_key = e.getAttributeValue("id");

                break;
            case "id":
                if (e.getAttributeValue("for").equals("node")) {
                    id_key = e.getAttributeValue("id");

                }
                break;
            case "Longitude":
                longitude_key = e.getAttributeValue("id");

                break;
            case "label":
                if (e.getAttributeValue("for").equals("node")) {
                    label_key = e.getAttributeValue("id");

                }
                break;
            case "LinkLabel":
                linklabel_key = e.getAttributeValue("id");
                break;
            default:
                break;
            }
        }
    } catch (JDOMException | IOException e) {
        logger.error("Error in GraphmlParser");
        System.exit(-1);
    }
}

From source file:de.weichand.inspire.inspirerome.io.InspireDlsModuleParser.java

License:Apache License

public Module parse(Element element, Locale locale) {

    final InspireDlsModuleImpl inspireDlsModuleImpl = new InspireDlsModuleImpl();
    final SpatialDatasetIdentifier spatialDatasetIdentifier = new SpatialDatasetIdentifier();

    Element code = element.getChild("spatial_dataset_identifier_code", NS);
    Element namespace = element.getChild("spatial_dataset_identifier_namespace", NS);

    if (code != null && namespace != null) {
        spatialDatasetIdentifier.setCode(code.getText().trim());
        spatialDatasetIdentifier.setNamespace(namespace.getText().trim());
        inspireDlsModuleImpl.setSpatialDatasetIdentifier(spatialDatasetIdentifier);
        return inspireDlsModuleImpl;
    } else {/*  w  ww  .j  av  a 2 s . co  m*/
        return null;
    }
}