Example usage for org.jdom2 Element getChildTextNormalize

List of usage examples for org.jdom2 Element getChildTextNormalize

Introduction

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

Prototype

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

Source Link

Document

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

Usage

From source file:com.c4om.autoconf.ulysses.extra.svrlinterpreter.SVRLInterpreterExtractor.java

License:Apache License

/**
 * Method that actually extracts the info
 *//*from  www. j av  a 2s . co m*/
public List<List<String>> extractInfo() {
    XPathExpression<Element> xpathExpression = xpathFactory.compile(XPATH_STRING, Filters.element(), null,
            NAMESPACE_SVRL);

    List<Element> xpathResults = xpathExpression.evaluate(document);
    List<List<String>> results = new ArrayList<>(xpathResults.size());
    for (Element element : xpathResults) {
        List<String> result = new ArrayList<>(2);
        result.add(0, element.getChildTextNormalize("text", NAMESPACE_SVRL).replace(METAMODEL_DIR_REPLACE_TOKEN,
                metamodelPath));
        result.add(1, element.getChildTextNormalize("diagnostic-reference", NAMESPACE_SVRL));
        //         result.add(2,element.getAttributeValue("location"));
        if (!results.contains(result)) {
            results.add(result);
        }
    }
    return results;

}

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

License:Apache License

private AliasExtension createExtension(final Element extensionElement) {
    final AliasExtension.Builder builder = new AliasExtension.Builder();

    final Attribute env = extensionElement.getAttribute("env");
    if (env != null) {
        builder.withEnv(env.getValue());
    }//from  w w w. j a v  a 2s  .c  o m

    final String name = extensionElement.getChildTextNormalize("name", nsAlias);
    final String template = extensionElement.getChildTextNormalize("template", nsAlias);
    final String comment = readComment(extensionElement);

    final Element commentElement = extensionElement.getChild("comment", nsAlias);
    if (commentElement != null) {
        final String mnemonic = commentElement.getAttributeValue("mnemonic");
        builder.withMnemonic(mnemonic);
    }

    builder.withName(name).withTemplate(template).withComment(comment);

    appendApplyTos(extensionElement, builder);

    return builder.build();
}

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

License:Apache License

private Alias createAlias(final Element aliasElement) {
    final Alias.Builder builder = new Alias.Builder();
    final Attribute env = aliasElement.getAttribute("env");
    final Element command = aliasElement.getChild("command", nsAlias);
    final String normalizedCommandText = command.getTextNormalize();
    builder.withName(aliasElement.getChildTextNormalize("name", nsAlias)).withCommand(normalizedCommandText);

    final String comment = readComment(aliasElement);
    builder.withComment(comment);//from  ww  w.jav a2s .  com

    if (env != null) {
        builder.withEnv(env.getValue());
    }
    final Attribute args = command.getAttribute("passArgs");
    if (args != null && !Boolean.parseBoolean(args.getValue())) {
        builder.withPassArgs(false);
    }

    return builder.build();
}

From source file:io.smartspaces.workbench.project.constituent.BaseProjectConstituentBuilder.java

License:Apache License

/**
 * Convenience function to help more easily build constituent parts.
 *
 * @param resourceElement/*  w  w  w  .  jav  a2s  . c om*/
 *          input element
 * @param namespace
 *          XML namespace for property name
 * @param propertyName
 *          property name to extract
 * @param fallback
 *          fallback value to use if none supplied
 *
 * @return property value, else fallback
 */
public static String getChildTextNormalize(Element resourceElement, Namespace namespace, String propertyName,
        String fallback) {
    String value = resourceElement.getChildTextNormalize(propertyName, namespace);
    return (value == null || (value.isEmpty() && fallback != null)) ? fallback : value;
}

From source file:io.smartspaces.workbench.project.jdom.JdomProjectReader.java

License:Apache License

/**
 * Get the value for a configuration property.
 *
 * @param projectNamespace/*  w  w  w  .ja v  a  2s. c om*/
 *          the XML namespace for the property
 * @param propertyElement
 *          the XML element for the property
 * @param propertyName
 *          the name of the property
 *
 * @return the configuration value for the property
 */
private String getConfigurationValue(Namespace projectNamespace, Element propertyElement, String propertyName) {
    String valueAttribute = propertyElement.getAttributeValue(PROJECT_ATTRIBUTE_NAME_CONFIGURATION_ITEM_VALUE);
    String valueChild = propertyElement.getChildTextNormalize(PROJECT_ELEMENT_NAME_CONFIGURATION_ITEM_VALUE,
            projectNamespace);

    if (valueAttribute != null) {
        if (valueChild != null) {
            getWorkbench().getLog().warn(String.format(
                    "Configuration property %s has both an attribute and child element giving the value. "
                            + "The child element is being used.",
                    propertyName));
            return valueChild;
        } else {
            return valueAttribute;
        }
    } else {
        return valueChild;
    }
}

From source file:org.apache.jena.geosparql.implementation.parsers.gml.GMLReader.java

License:Apache License

private static CustomCoordinateSequence extractPos(Element gmlElement, CoordinateSequenceDimensions dims) {
    String coordinates = gmlElement.getChildTextNormalize("pos", GML_NAMESPACE);
    if (coordinates == null) {
        coordinates = "";
    }// www.j  a  v a  2s  . c  o m
    return new CustomCoordinateSequence(dims, coordinates);
}

From source file:org.apache.jena.geosparql.implementation.parsers.gml.GMLReader.java

License:Apache License

private static String extractPosList(Element gmlElement, int srsDimension) {
    String posList = gmlElement.getChildTextNormalize("posList", GML_NAMESPACE);
    if (posList == null) {
        return "";
    }/*from   www. j a v a2s. c om*/

    StringBuilder sb = new StringBuilder("");
    String[] coordinates = posList.trim().split(" ");

    int mod = coordinates.length % srsDimension;
    if (mod != 0) {
        throw new DatatypeFormatException("GML Pos List does not divide into srs dimension: "
                + coordinates.length + " divide " + srsDimension + " remainder " + mod + ".");
    }

    int finalCoordinate = coordinates.length - 1;
    for (int i = 0; i < coordinates.length; i++) {
        if (i != 0 & i % srsDimension == 0) {
            sb.append(",");
        }
        String coordinate = coordinates[i];
        sb.append(coordinate);
        if (i != finalCoordinate) {
            sb.append(" ");
        }
    }

    return sb.toString();
}

From source file:org.apache.jena.geosparql.implementation.parsers.gml.GMLReader.java

License:Apache License

private static List<Coordinate> buildCoordinateList(Element gmlElement, int srsDimension) {

    String posList = gmlElement.getChildTextNormalize("posList", GML_NAMESPACE);
    String[] coordinates = posList.trim().split(" ");

    int mod = coordinates.length % srsDimension;
    if (mod != 0) {
        throw new DatatypeFormatException("GML Pos List does not divide into srs dimension: "
                + coordinates.length + " divide " + srsDimension + " remainder " + mod + ".");
    }//from   w w  w.ja v  a2  s .  c o  m

    List<Coordinate> coordinateList = new ArrayList<>();

    for (int i = 0; i < coordinates.length; i += srsDimension) {
        Coordinate coord;
        //[10-100rs], page 22: "c) coordinate reference systems may have 1, 2 or 3 dimensions". 1 dimension does not fit with spatial relations of GeoSPARQL.
        switch (srsDimension) {
        case 2:
            coord = new CoordinateXY(Double.parseDouble(coordinates[i]),
                    Double.parseDouble(coordinates[i + 1]));
            break;
        case 3:
            coord = new Coordinate(Double.parseDouble(coordinates[i]), Double.parseDouble(coordinates[i + 1]),
                    Double.parseDouble(coordinates[i + 2]));
            break;
        default:
            throw new DatatypeFormatException("SRS dimension " + srsDimension + " is not supported.");
        }
        coordinateList.add(coord);
    }

    return coordinateList;
}