Example usage for org.jdom2 Attribute getValue

List of usage examples for org.jdom2 Attribute getValue

Introduction

In this page you can find the example usage for org.jdom2 Attribute getValue.

Prototype

public String getValue() 

Source Link

Document

This will return the actual textual value of this Attribute.

Usage

From source file:ca.nrc.cadc.caom2.xml.ObservationReader.java

License:Open Source License

private void assignEntityAttributes(Element e, CaomEntity ce, ReadContext rc)
        throws ObservationParsingException {
    Attribute aid = e.getAttribute("id", e.getNamespace());
    Attribute alastModified = e.getAttribute("lastModified", e.getNamespace());
    Attribute amaxLastModified = e.getAttribute("maxLastModified", e.getNamespace());
    Attribute mcs = e.getAttribute("metaChecksum", e.getNamespace());
    Attribute acc = e.getAttribute("accMetaChecksum", e.getNamespace());
    try {/*from   w ww  . j  av a 2 s  .c  o  m*/
        UUID uuid;
        if (rc.docVersion == 20) {
            Long id = new Long(aid.getLongValue());
            uuid = new UUID(0L, id);
        } else {
            uuid = UUID.fromString(aid.getValue());
        }

        CaomUtil.assignID(ce, uuid);
        if (alastModified != null) {
            Date lastModified = rc.parseTimestamp(alastModified.getValue());
            CaomUtil.assignLastModified(ce, lastModified, "lastModified");
        }

        if (rc.docVersion >= 23) {
            if (amaxLastModified != null) {
                Date lastModified = rc.parseTimestamp(amaxLastModified.getValue());
                CaomUtil.assignLastModified(ce, lastModified, "maxLastModified");
            }
            if (mcs != null) {
                URI metaCS = new URI(mcs.getValue());
                CaomUtil.assignMetaChecksum(ce, metaCS, "metaChecksum");
            }
            if (acc != null) {
                URI accCS = new URI(acc.getValue());
                CaomUtil.assignMetaChecksum(ce, accCS, "accMetaChecksum");
            }
        }
    } catch (DataConversionException ex) {
        throw new ObservationParsingException("invalid id: " + aid.getValue());
    } catch (ParseException ex) {
        throw new ObservationParsingException("invalid lastModified: " + alastModified.getValue());
    } catch (URISyntaxException ex) {
        throw new ObservationParsingException("invalid checksum uri: " + aid.getValue());
    }
}

From source file:ca.nrc.cadc.caom2.xml.ObservationReader.java

License:Open Source License

protected Position getPosition(Element parent, Namespace namespace, ReadContext rc)
        throws ObservationParsingException {
    Element element = getChildElement("position", parent, namespace, false);
    if (element == null) {
        return null;
    }/*from www.j  a va 2 s  .com*/

    Position pos = new Position();
    Element cur = getChildElement("bounds", element, namespace, false);
    if (cur != null) {
        if (rc.docVersion < 23) {
            throw new UnsupportedOperationException(
                    "cannot convert version " + rc.docVersion + " polygon to current version");
        }
        Attribute type = cur.getAttribute("type", xsiNamespace);
        String tval = type.getValue();
        String circleType = namespace.getPrefix() + ":" + Circle.class.getSimpleName();
        String polyType = namespace.getPrefix() + ":" + Polygon.class.getSimpleName();
        if (polyType.equals(tval)) {
            List<Point> points = new ArrayList<Point>();
            Element pes = cur.getChild("points", namespace);
            for (Element pe : pes.getChildren()) { // only vertex
                double cval1 = getChildTextAsDouble("cval1", pe, namespace, true);
                double cval2 = getChildTextAsDouble("cval2", pe, namespace, true);
                points.add(new Point(cval1, cval2));
            }
            Element se = cur.getChild("samples", namespace);
            MultiPolygon poly = new MultiPolygon();
            Element ves = se.getChild("vertices", namespace);
            for (Element ve : ves.getChildren()) { // only vertex
                double cval1 = getChildTextAsDouble("cval1", ve, namespace, true);
                double cval2 = getChildTextAsDouble("cval2", ve, namespace, true);
                int sv = getChildTextAsInteger("type", ve, namespace, true);
                poly.getVertices().add(new Vertex(cval1, cval2, SegmentType.toValue(sv)));
            }
            pos.bounds = new Polygon(points, poly);
        } else if (circleType.equals(tval)) {
            Element ce = cur.getChild("center", namespace);
            double cval1 = getChildTextAsDouble("cval1", ce, namespace, true);
            double cval2 = getChildTextAsDouble("cval2", ce, namespace, true);
            Point c = new Point(cval1, cval2);
            double r = getChildTextAsDouble("radius", cur, namespace, true);
            pos.bounds = new Circle(c, r);
        } else {
            throw new UnsupportedOperationException("unsupported shape: " + tval);
        }
    }

    cur = getChildElement("dimension", element, namespace, false);
    if (cur != null) {
        // Attribute type = cur.getAttribute("type", xsiNamespace);
        // String tval = type.getValue();
        // String extype = namespace.getPrefix() + ":" +
        // Dimension2D.class.getSimpleName();
        // if ( extype.equals(tval) )
        // {
        long naxis1 = getChildTextAsLong("naxis1", cur, namespace, true);
        long naxis2 = getChildTextAsLong("naxis2", cur, namespace, true);
        pos.dimension = new Dimension2D(naxis1, naxis2);
        // }
        // else
        // throw new ObservationParsingException("unsupported dimension
        // type: " + tval);
    }

    pos.resolution = getChildTextAsDouble("resolution", element, namespace, false);
    pos.sampleSize = getChildTextAsDouble("sampleSize", element, namespace, false);
    pos.timeDependent = getChildTextAsBoolean("timeDependent", element, namespace, false);

    return pos;
}

From source file:ca.nrc.cadc.dali.tables.votable.VOTableReader.java

License:Open Source License

/**
 * Read a XML VOTable from a Reader and build a VOTable object.
 *
 * @param reader Reader to read from./* ww w  .ja v a2 s  .c om*/
 * @return a VOTable object.
 * @throws IOException if problem reading from the reader.
 */
public VOTable read(Reader reader) throws IOException {
    // Parse the input document.
    Document document;
    try {
        document = docBuilder.build(reader);
    } catch (JDOMException e) {
        throw new IOException("Unable to parse " + e.getMessage());
    }

    // Returned VOTable object.
    VOTable votable = new VOTable();

    // Document root element.
    Element root = document.getRootElement();

    // Namespace for the root element.
    Namespace namespace = root.getNamespace();
    log.debug("Namespace: " + namespace);

    // RESOURCE element.
    Element resource = root.getChild("RESOURCE", namespace);
    if (resource != null) {
        // Get the RESOURCE name attribute.
        Attribute resourceName = resource.getAttribute("name");
        if (resourceName != null) {
            votable.setResourceName(resourceName.getValue());
        }

        // INFO element.
        List<Element> infos = resource.getChildren("INFO", namespace);
        votable.getInfos().addAll(getInfos(infos, namespace));

        // TABLE element.
        Element table = resource.getChild("TABLE", namespace);
        if (table != null) {
            // PARAM elements.
            List<Element> params = table.getChildren("PARAM", namespace);
            votable.getParams().addAll(getParams(params, namespace));

            // FIELD elements.
            List<Element> fields = table.getChildren("FIELD", namespace);
            votable.getColumns().addAll(getFields(fields, namespace));

            // DATA element.
            Element data = table.getChild("DATA", namespace);
            if (data != null) {
                // TABLEDATA element.
                Element tableData = data.getChild("TABLEDATA", namespace);
                votable.setTableData(getTableData(tableData, namespace, votable.getColumns()));
            }
        }
    }
    return votable;
}

From source file:ca.nrc.cadc.xml.JsonOutputter.java

License:Open Source License

private boolean writeAttributes(Element e, PrintWriter w, int i) throws IOException {
    boolean ret = writeSchemaAttributes(e, w, i);

    Iterator<Attribute> iter = e.getAttributes().iterator();
    if (ret && iter.hasNext())
        w.print(",");
    while (iter.hasNext()) {
        ret = true;/*from   w w w.  jav a2s .co m*/
        Attribute a = iter.next();
        indent(w, i);
        w.print(QUOTE);
        w.print("@");
        if (StringUtil.hasText(a.getNamespacePrefix())) {
            w.print(a.getNamespacePrefix());
            w.print(":");
        }
        w.print(a.getName());
        w.print(QUOTE);
        w.print(" : ");
        if (isBoolean(e.getName(), a.getValue()) || isNumeric(e.getName(), a.getValue())) {
            w.print(a.getValue());
        } else {
            w.print(QUOTE);
            w.print(a.getValue());
            w.print(QUOTE);
        }
        if (iter.hasNext())
            w.print(",");
    }

    return ret;
}

From source file:com.abyala.decisiontree.SimpleDecisionTreeParser.java

License:Open Source License

private ResultAttribute parseResultBooleanAttribute(final Element element, final String name,
        final Method method) throws DecisionTreeParserException {
    final BooleanResultAttribute.Builder builder = new BooleanResultAttribute.Builder(name, method);
    final Attribute defaultAttribute = element.getAttribute("default");
    if (defaultAttribute != null) {
        final String value = defaultAttribute.getValue();
        if ("true".equals(value)) {
            builder.setDefaultValue(true);
        } else if ("false".equals(value)) {
            builder.setDefaultValue(false);
        } else {/*from   w  ww.  j ava 2 s . c o m*/
            throw new DecisionTreeParserException(
                    "Invalid default value \"" + value + "\" for boolean result attribute \"" + name + "\"");
        }
    }

    return builder.build();
}

From source file:com.abyala.decisiontree.SimpleDecisionTreeParser.java

License:Open Source License

private ResultAttribute parseResultIntegerAttribute(final Element element, final String name,
        final Method method) throws DecisionTreeParserException {
    final IntegerResultAttribute.Builder builder = new IntegerResultAttribute.Builder(name, method);
    final Attribute defaultAttribute = element.getAttribute("default");
    if (defaultAttribute != null) {
        final String value = defaultAttribute.getValue();
        try {//from   w ww  .j a  va2  s.  c  om
            final Integer intValue = Integer.parseInt(value);
            builder.setDefaultValue(intValue);
        } catch (NumberFormatException e) {
            throw new DecisionTreeParserException(
                    "Invalid default value \"" + value + "\" for integer result attribute \"" + name + "\"");
        }
    }

    return builder.build();
}

From source file:com.abyala.decisiontree.SimpleDecisionTreeParser.java

License:Open Source License

/**
 * Creates a result specification for this node. Does not create the actual result object,
 * since there's no guarantee that that object will be immutable.
 *///from w ww  .j  a  v a 2 s .c o m
private ResultNode parseResult(final Element element, final ResultSpec resultSpec)
        throws DecisionTreeParserException {
    final ResultNode.Builder builder = new ResultNode.Builder(resultSpec);
    for (final Attribute attribute : element.getAttributes()) {
        final String name = attribute.getName();
        final String value = attribute.getValue();
        builder.addAttribute(name, value);
    }

    return builder.build();
}

From source file:com.archimatetool.canvas.templates.model.CanvasTemplateManager.java

License:Open Source License

@Override
protected boolean isValidTemplateFile(File file) throws IOException {
    if (file == null || !file.exists()) {
        return false;
    }/*from  ww w. java2 s.co  m*/

    // Ensure the template is of the right kind
    String xmlString = ZipUtils.extractZipEntry(file, ZIP_ENTRY_MANIFEST);
    if (xmlString == null) {
        return false;
    }

    // If the attribute "type" exists then return true if its value is "canvas".
    // If the attribute doesn't exist it was from an older version (before 2.1)
    try {
        Document doc = JDOMUtils.readXMLString(xmlString);
        Element root = doc.getRootElement();
        Attribute attType = root.getAttribute(ITemplateXMLTags.XML_TEMPLATE_ATTRIBUTE_TYPE);
        if (attType != null) {
            return CanvasModelTemplate.XML_CANVAS_TEMPLATE_ATTRIBUTE_TYPE_MODEL.equals(attType.getValue());
        }
    } catch (JDOMException ex) {
        return false;
    }

    return true;
}

From source file:com.archimatetool.editor.model.compatibility.Archimate2To3Converter.java

License:Open Source License

/**
 * Convert concept name types// w  w w  .j  a  v  a2  s  .  c om
 */
private void convertConceptTypeName(Element element) {
    Attribute attType = element.getAttribute("type", JDOMUtils.XSI_Namespace);

    if (attType != null) {
        String oldValue = attType.getValue();
        String newValue = ConceptNameMapping.get(oldValue);

        if (newValue != null) {
            attType.setValue(newValue);
        }

        // Or Junction has type set
        if ("archimate:OrJunction".equals(oldValue)) {
            element.setAttribute("type", "or");
        }
    }
}

From source file:com.archimatetool.editor.model.compatibility.Archimate2To3Converter.java

License:Open Source License

/**
 * Move concepts to different folders/*from   w  w w. ja  va  2 s . c o  m*/
 */
private void moveConceptType(Element element) {
    Attribute attType = element.getAttribute("type", JDOMUtils.XSI_Namespace);

    if (attType != null) {
        String value = attType.getValue();

        // Location
        if ("archimate:Location".equals(value)) {
            Element eFolder = getModelFolder("other");
            if (eFolder != null) {
                element.detach();
                eFolder.addContent(element);
            }
        }

        // Value / Meaning
        if ("archimate:Value".equals(value) || "archimate:Meaning".equals(value)) {
            Element eFolder = getModelFolder("motivation");
            if (eFolder != null) {
                element.detach();
                eFolder.addContent(element);
            }
        }
    }
}