Example usage for org.jdom2 Element getTextNormalize

List of usage examples for org.jdom2 Element getTextNormalize

Introduction

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

Prototype

public String getTextNormalize() 

Source Link

Document

Returns the textual content of this element with all surrounding whitespace removed and internal whitespace normalized to a single space.

Usage

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

License:Apache License

/**
 * Compares the affiliation values in the given MODS document against the ontology. If a preferred term(s) is found,
 * then it will replace the original. Only the first and last terms in a single hierarchy are kept if there are more
 * than two levels/*w w  w  .j  a  v  a 2  s .c  o  m*/
 *
 * @param modsDoc
 * @return Returns true if the mods document was modified by adding or changing affiliations
 * @throws JDOMException
 */
@Override
public boolean updateDocumentTerms(Element docElement) throws JDOMException {
    List<?> nameObjs = namePath.evaluate(docElement);
    boolean modified = false;

    for (Object nameObj : nameObjs) {
        Element nameEl = (Element) nameObj;

        List<?> affiliationObjs = nameEl.getChildren("affiliation", MODS_V3_NS);
        if (affiliationObjs.size() == 0)
            continue;

        // Collect the set of all affiliations for this name so that it can be used to detect duplicates
        Set<String> affiliationSet = new HashSet<>();
        for (Object affiliationObj : affiliationObjs) {
            Element affiliationEl = (Element) affiliationObj;

            affiliationSet.add(affiliationEl.getTextNormalize());
        }

        // Make a snapshot of the list of affiliations so that the original can be modified
        List<?> affilList = new ArrayList<>(affiliationObjs);
        // Get the authoritative department path for each affiliation and overwrite the original
        for (Object affiliationObj : affilList) {
            Element affiliationEl = (Element) affiliationObj;
            String affiliation = affiliationEl.getTextNormalize();

            List<List<String>> departments = getAuthoritativeForm(affiliation);
            if (departments != null && departments.size() > 0) {

                Element parentEl = affiliationEl.getParentElement();
                int affilIndex = parentEl.indexOf(affiliationEl);

                boolean removeOriginal = true;
                // Add each path that matched the affiliation. There can be multiple if there were multiple parents
                for (List<String> deptPath : departments) {
                    String baseDept = deptPath.size() > 1 ? deptPath.get(0) : null;
                    String topDept = deptPath.get(deptPath.size() - 1);

                    // No need to remove the original if it is in the set of departments being added
                    if (affiliation.equals(topDept))
                        removeOriginal = false;

                    modified = addAffiliation(baseDept, parentEl, affilIndex, affiliationSet) || modified;
                    modified = addAffiliation(topDept, parentEl, affilIndex, affiliationSet) || modified;
                }

                // Remove the old affiliation unless it was already in the vocabulary
                if (removeOriginal)
                    parentEl.removeContent(affiliationEl);

            }
        }
    }

    return modified;
}

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

License:Apache License

public Set<String> getInvalidTerms(Element modsRoot, boolean includePrefix) throws JDOMException {
    List<?> nameObjs = namePath.evaluate(modsRoot);

    Set<String> invalidTerms = new HashSet<String>();

    for (Object nameObj : nameObjs) {
        Element nameEl = (Element) nameObj;

        List<?> affiliationObjs = nameEl.getChildren("affiliation", MODS_V3_NS);
        if (affiliationObjs.size() == 0)
            continue;

        // Make a snapshot of the list of affiliations so that the original can be modified
        List<?> affilList = new ArrayList<Object>(affiliationObjs);
        // Get the authoritative department path for each affiliation and overwrite the original
        for (Object affiliationObj : affilList) {
            Element affiliationEl = (Element) affiliationObj;
            String affiliation = affiliationEl.getTextNormalize();

            List<List<String>> departments = getAuthoritativeForm(affiliation);
            if (departments == null || departments.size() == 0) {
                // Affiliation was not found in the ontology, add it to result set
                if (includePrefix)
                    affiliation = getInvalidTermPrefix() + "|" + affiliation;
                invalidTerms.add(affiliation);
            }/*from  w  w w.  j a  v  a  2 s . c  o m*/
        }
    }

    return invalidTerms;
}

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

License:Apache License

private static LineString buildCircleByCentrePoint(List<Element> segments, CoordinateSequenceDimensions dims,
        SRSInfo srsInfo) {//from  w w w  .ja v  a  2s. c o m

    Element circleElement = segments.get(0);
    Point point = buildPoint(circleElement, dims);
    Coordinate centre = point.getCoordinate();

    //Get radius and convert units of measure if required.
    Element radiusElement = circleElement.getChild("radius", GML_NAMESPACE);
    double radius = Double.parseDouble(radiusElement.getTextNormalize());

    //Extract units of measure uri. Use SRS units of measure if absent.
    String uomURI = radiusElement.getAttributeValue("uom");

    if (uomURI != null) {
        UnitsOfMeasure uom = new UnitsOfMeasure(uomURI);
        //Convert the radius if the specified units of measure don't match.
        radius = UnitsOfMeasure.conversion(radius, uom, srsInfo.getUnitsOfMeasure());
    }

    GeometricShapeFactory geometricShapeFactory = new GeometricShapeFactory(GEOMETRY_FACTORY);
    geometricShapeFactory.setCentre(centre);
    geometricShapeFactory.setSize(radius * 2); //Set the width and height, i.e. the diameter.
    Polygon circlePolygon = geometricShapeFactory.createCircle();
    return circlePolygon.getExteriorRing();
}

From source file:org.jpos.util.RealmLogFilter.java

License:Open Source License

@Override
public void setConfiguration(Element e) throws ConfigurationException {
    Element enabled = e.getChild("enabled");
    Element disabled = e.getChild("disabled");
    if (enabled != null && !"".equals(enabled.getTextNormalize()))
        enabledRealms = new HashSet(Arrays.asList(enabled.getTextNormalize().split(" ")));
    if (disabled != null && !"".equals(disabled.getTextNormalize()))
        disabledRealms = new HashSet(Arrays.asList(disabled.getTextNormalize().split(" ")));
    ;/*www . ja  v  a2  s.c o m*/
}

From source file:org.olanto.myterm.extractor.model.posfix.LoadModelPosfix.java

License:Open Source License

static String getText(Element e, boolean localverbose) {
    String val = e.getTextNormalize();
    if (localverbose) {
        System.out.println("--> " + val);
    }//from www. j  a  v  a  2  s . c om
    return val;
}

From source file:org.olanto.myterm.extractor.model.posfix.LoadModelPosfix.java

License:Open Source License

static String getExtraElement(Element e) {
    StringBuilder collect = new StringBuilder();
    boolean attributeverbose = false;
    collect.append("<" + e.getName());
    List<Attribute> attlist = e.getAttributes();
    Iterator i = attlist.iterator();
    while (i.hasNext()) {
        Attribute att = (Attribute) i.next();
        String av = att.getName() + "=\"" + getAtt(e, att.getName(), noNS, attributeverbose) + "\"";
        collect.append(" " + av);
        //System.out.println(av);
    }/*from   w  ww. ja  v  a 2  s.  c o m*/
    collect.append(">");
    List listNode = e.getChildren();
    i = listNode.iterator();
    while (i.hasNext()) {
        Element info = (Element) i.next();
        collect.append("\n");
        collect.append(getExtraElement(info));
    }
    //System.out.println(e.getTextTrim());
    collect.append(e.getTextNormalize());
    collect.append("</" + e.getName() + ">");
    String res = collect.toString();
    res = res.replace("><", ">\n<");
    res = res.replace("  ", " ");
    //System.out.println(res);      
    return res;
}

From source file:org.opengroup.archimate.xmlexchange.XMLModelImporter.java

License:Open Source License

String getChildElementText(Element parentElement, String childElementName, boolean normalise) {
    //Check for localised element according to the system's locale
    String code = Locale.getDefault().getLanguage();
    if (code == null) {
        code = "en";
    }/* w w  w .j av  a  2 s .c o m*/

    for (Element childElement : parentElement.getChildren(childElementName, OPEN_GROUP_NAMESPACE)) {
        String lang = childElement.getAttributeValue(ATTRIBUTE_LANG, Namespace.XML_NAMESPACE);
        if (code.equals(lang)) {
            return normalise ? childElement.getTextNormalize() : childElement.getText();
        }
    }

    // Default to first element found
    Element element = parentElement.getChild(childElementName, OPEN_GROUP_NAMESPACE);
    return element == null ? null : normalise ? element.getTextNormalize() : element.getText();
}

From source file:org.openkennel.model.filemngr.XMLFileHandler.java

License:Open Source License

private List<Element> filterEmptyEntries(List<Element> list) {
    for (ListIterator<Element> iterator = list.listIterator(); iterator.hasNext();) {
        Element element = iterator.next();

        if (element.getTextNormalize().isEmpty()) {
            iterator.remove();/*from   w  w w . j  av a  2 s  .  c o m*/
        }
    }

    return list;
}

From source file:org.rhwlab.dispim.datasource.ClusteredDataSource.java

final public void openFromClusters(String xml) throws Exception {
    SAXBuilder saxBuilder = new SAXBuilder();
    Document doc = saxBuilder.build(new File(xml));
    Element root = doc.getRootElement();
    int K = Integer.valueOf(root.getAttributeValue("NumberOfClusters"));
    D = Integer.valueOf(root.getAttributeValue("Dimensions"));
    clusterMinIntensity = new int[K];
    clusterMaxIntensity = new int[K];
    this.clusterSegmentedProb = new double[K];
    centers = new RealVector[K];
    int N = Integer.valueOf(root.getAttributeValue("NumberOfPoints"));
    minIntensity = Integer.valueOf(root.getAttributeValue("MinimumIntensity"));
    maxIntensity = Integer.valueOf(root.getAttributeValue("MaximumIntensity"));
    segThresh = Double.valueOf(root.getAttributeValue("SegmentationThreshold"));
    List<Element> clusterElements = root.getChildren("Cluster");
    X = new Voxel[N];
    z = new GaussianComponent[N];
    int n = 0;//from ww  w .j  a  v  a2  s.  c o  m
    int k = 0;
    for (Element clusterElement : clusterElements) {

        String[] tokens = clusterElement.getAttributeValue("Center").split(" ");
        double[] v = new double[tokens.length];
        for (int i = 0; i < v.length; ++i) {
            v[i] = Double.valueOf(tokens[i]);
        }
        centers[k] = new ArrayRealVector(v);

        GaussianComponent comp = new GaussianComponent(this, k);
        gaussians.add(comp);
        this.clusterMinIntensity[k] = Integer.valueOf(clusterElement.getAttributeValue("MinimumIntensity"));
        this.clusterMaxIntensity[k] = Integer.valueOf(clusterElement.getAttributeValue("MaximumIntensity"));
        this.clusterSegmentedProb[k] = Double.valueOf(clusterElement.getAttributeValue("AvgAdjusted"));
        List<Element> pointElements = clusterElement.getChildren("Point");
        for (Element pointElement : pointElements) {
            tokens = pointElement.getTextNormalize().split(" ");
            v = new double[tokens.length];
            for (int i = 0; i < v.length; ++i) {
                v[i] = Double.valueOf(tokens[i]);
            }
            int in = Integer.valueOf(pointElement.getAttributeValue("Intensity"));
            double adj = Double.valueOf(pointElement.getAttributeValue("Adjusted"));
            X[n] = new Voxel(new ArrayRealVector(v), in, adj);
            comp.addPoint(n, false);
            z[n] = comp;
            ++n;
        }
        ++k;
        comp.calculateStatistics();

    }

}

From source file:org.rhwlab.dispim.datasource.MicroCluster.java

public MicroCluster(Element ele) {
    int D = 3;/*www . j a  va 2 s .  c  om*/
    String centerStr = ele.getAttributeValue("center").trim();
    String[] centerTokens = centerStr.split(" ");
    v = new double[D];
    for (int d = 0; d < D; ++d) {
        v[d] = Double.valueOf(centerTokens[d]);
    }
    this.avgProb = Double.valueOf(ele.getAttributeValue("avgProb"));
    int nPts = Integer.valueOf(ele.getAttributeValue("points"));
    points = new short[nPts][];
    intensities = new int[nPts];
    String cont = ele.getTextNormalize();
    String[] tokens = cont.substring(1, cont.length() - 1).split("\\)\\(");
    for (int i = 0; i < nPts; ++i) {
        short[] p = new short[D];
        String[] valStrs = tokens[i].split(",");
        for (int d = 0; d < D; ++d) {
            p[d] = Short.valueOf(valStrs[d]);
        }
        points[i] = p;
        intensities[i] = Integer.valueOf(valStrs[valStrs.length - 1]);
    }

}