Example usage for org.jdom2 Element getText

List of usage examples for org.jdom2 Element getText

Introduction

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

Prototype

public String getText() 

Source Link

Document

Returns the textual content directly held under this element as a string.

Usage

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

License:Open Source License

protected Double getChildTextAsDouble(String name, Element element, Namespace ns, boolean required)
        throws ObservationParsingException {
    Element child = getChildElement(name, element, ns, required);
    if (child != null) {
        return Double.valueOf(child.getText());
    }/* ww w .  j av  a 2s.c  om*/
    return null;
}

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

License:Open Source License

protected Long getChildTextAsLong(String name, Element element, Namespace ns, boolean required)
        throws ObservationParsingException {
    Element child = getChildElement(name, element, ns, required);
    if (child != null) {
        return Long.valueOf(child.getText());
    }/*ww w .ja v  a2 s  .co  m*/
    return null;
}

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

License:Open Source License

/**
 * Populate a TableField object with values from the FIELD element.
 *
 * @param tableField TableField to populate.
 * @param element source Element.// w ww . j a  v  a 2  s.  c  om
 * @param namespace document namespace.
 */
protected void updateTableField(TableField tableField, Element element, Namespace namespace) {
    tableField.id = element.getAttributeValue("ID");
    tableField.ucd = element.getAttributeValue("ucd");
    tableField.unit = element.getAttributeValue("unit");
    tableField.utype = element.getAttributeValue("utype");
    tableField.xtype = element.getAttributeValue("xtype");

    String arraysize = element.getAttributeValue("arraysize");
    if (arraysize != null) {
        int index = arraysize.indexOf("*");
        if (index == -1) {
            tableField.variableSize = Boolean.FALSE;
        } else {
            arraysize = arraysize.substring(0, index);
            tableField.variableSize = Boolean.TRUE;
        }
        if (!arraysize.trim().isEmpty()) {
            tableField.arraysize = Integer.parseInt(arraysize);
        }
    }

    // DESCRIPTION element for the FIELD.
    Element description = element.getChild("DESCRIPTION", namespace);
    if (description != null) {
        tableField.description = description.getText();
    }

    // VALUES element for the PARAM.
    Element values = element.getChild("VALUES", namespace);
    if (values != null) {
        List<Element> options = values.getChildren("OPTION", namespace);
        if (!options.isEmpty()) {
            tableField.values = new ArrayList<String>();
            for (Element option : options) {
                tableField.values.add(option.getAttributeValue("value"));
            }
        }
    }
}

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

License:Open Source License

/**
 * Build a List that contains the TableData rows.
 *
 * @param element TABLEDATA element./*  w  ww  .  ja  va 2  s . c  om*/
 * @param namespace document namespace.
 * @return TableData object containing rows of data.
 */
TableData getTableData(Element element, Namespace namespace, List<TableField> fields) {
    ArrayListTableData tableData = new ArrayListTableData();

    if (element != null) {
        List<Element> trs = element.getChildren("TR", namespace);
        for (Element tr : trs) {
            List<Object> row = new ArrayList<Object>();
            List<Element> tds = tr.getChildren("TD", namespace);
            for (int i = 0; i < tds.size(); i++) {
                Element td = tds.get(i);
                TableField field = fields.get(i);
                Format format = FormatFactory.getFormat(field);
                String text = td.getText();
                Object o = format.parse(text);
                row.add(o);
            }
            tableData.getArrayList().add(row);
        }
    }
    return tableData;
}

From source file:ca.nrc.cadc.reg.CapabilitiesReader.java

License:Open Source License

private URL parseURL(final Element accessURLElement) {
    String accessURLString = accessURLElement.getText();
    if (accessURLString == null) {
        String msg = this.resourceIDStr + this.standardIDStr + ", URL not found in accessURL element";
        throw new RuntimeException(msg);
    }//  ww w . j a  v  a2 s. c  o  m

    log.debug("accessURL: " + accessURLString);
    this.accessURLStr = ", accessURL=" + accessURLString;

    URL accessURL;
    try {
        accessURL = new URL(accessURLString);
    } catch (MalformedURLException e) {
        String msg = this.resourceIDStr + this.standardIDStr + this.accessURLStr
                + ", invalid accessURL in xml: " + e.getMessage();
        throw new RuntimeException(msg);
    }
    return accessURL;
}

From source file:ca.nrc.cadc.uws.JobReader.java

License:Open Source License

private List<Parameter> parseParametersList(Document doc) {
    List<Parameter> rtn = null;
    Element root = doc.getRootElement();
    Element elementParameters = root.getChild(JobAttribute.PARAMETERS.getAttributeName(), UWS.NS);
    if (elementParameters != null) {
        rtn = new ArrayList<Parameter>();

        Parameter par = null;/*from   w w  w . j  av  a 2s.  co  m*/
        List<?> listElement = elementParameters.getChildren(JobAttribute.PARAMETER.getAttributeName(), UWS.NS);
        for (Object obj : listElement) {
            Element e = (Element) obj;
            String id = e.getAttributeValue("id");
            String value = e.getText();
            par = new Parameter(id, value);
            rtn.add(par);
        }
    }
    return rtn;
}

From source file:ca.nrc.cadc.uws.JobReader.java

License:Open Source License

private JobInfo parseJobInfo(Document doc) {
    JobInfo rtn = null;//w  w  w.j av  a2  s  .  c o  m
    Element root = doc.getRootElement();
    Element e = root.getChild(JobAttribute.JOB_INFO.getAttributeName(), UWS.NS);
    if (e != null) {
        log.debug("found jobInfo element");
        String content = e.getText();
        List children = e.getChildren();
        if (content != null)
            content = content.trim();
        if (content.length() > 0) // it was text content
        {
            rtn = new JobInfo(content, null, null);
        } else if (children != null) {
            if (children.size() == 1) {
                try {
                    Element ce = (Element) children.get(0);
                    Document jiDoc = new Document((Element) ce.detach());
                    XMLOutputter outputter = new XMLOutputter();
                    StringWriter sw = new StringWriter();
                    outputter.output(jiDoc, sw);
                    sw.close();
                    rtn = new JobInfo(sw.toString(), null, null);

                } catch (IOException ex) {
                    throw new RuntimeException("BUG while writing element to string", ex);
                }
            }
        }
    }
    log.debug("parseJobInfo: " + rtn);
    return rtn;
}

From source file:ca.nrc.cadc.vos.NodeReader.java

License:Open Source License

/**
 * Constructs a LinkNode from the given root Element of the
 * Document, Document Namespace, and Node path.
 *
 * @param el a node Element in the Document.
 * @param namespace Document Namespace./*w w w  . java  2s  . c om*/
 * @param uri Node uri attribute.
 * @param target Target resource pointed to by the LinkNode
 * @return LinkNode.
 * @throws NodeParsingException if there is an error parsing the XML.
 * @throws URISyntaxException 
 */
protected Node buildLinkNode(Element el, Namespace namespace, String uri)
        throws NodeParsingException, URISyntaxException {
    // Instantiate a LinkNode class
    LinkNode node;
    VOSURI vosuri;

    // target element in the node element
    Element target = el.getChild("target", namespace);
    if (target == null) {
        String error = "target element not found in node element";
        throw new NodeParsingException(error);
    }
    log.debug("node target: " + target.getText());

    try {
        vosuri = new VOSURI(uri);
    } catch (URISyntaxException e) {
        String error = "invalid node uri " + uri;
        throw new NodeParsingException(error, e);
    }

    try {
        node = new LinkNode(vosuri, new URI(target.getText()));
    } catch (URISyntaxException e) {
        String error = "invalid node target " + target.getText();
        throw new NodeParsingException(error, e);
    }

    // properties element
    node.setProperties(getProperties(el, namespace));

    return node;
}

From source file:ca.nrc.cadc.vos.NodeReader.java

License:Open Source License

/**
 * Builds a List of NodeProperty objects from the Document property Elements.
 *
 * @param el a node Element of the Document.
 * @param namespace Document Namespace./*from   w w w.j  a v  a  2  s .c  o m*/
 * @return List of NodeProperty objects.
 * @throws NodeParsingException if there is an error parsing the XML.
 */
protected List<NodeProperty> getProperties(Element el, Namespace namespace) throws NodeParsingException {
    // properties element
    Element properties = el.getChild("properties", namespace);
    if (properties == null) {
        String error = "properties element not found";
        throw new NodeParsingException(error);
    }

    // new NodeProperty List
    List<NodeProperty> set = new ArrayList<NodeProperty>();

    // properties property elements
    List<Element> propertyList = properties.getChildren("property", namespace);
    for (Element property : propertyList) {
        String propertyUri = property.getAttributeValue("uri");
        if (propertyUri == null) {
            String error = "uri attribute not found in property element " + property;
            throw new NodeParsingException(error);
        }

        // xsi:nil set to true indicates Property is to be deleted
        String xsiNil = property.getAttributeValue("nil", xsiNamespace);
        boolean markedForDeletion = false;
        if (xsiNil != null)
            markedForDeletion = xsiNil.equalsIgnoreCase("true") ? true : false;

        // if marked for deletetion, property can not contain text content
        String text = property.getText();
        if (markedForDeletion)
            text = "";

        // create new NodeProperty
        NodeProperty nodeProperty = new NodeProperty(propertyUri, text);

        // set readOnly attribute
        String readOnly = property.getAttributeValue("readOnly");
        if (readOnly != null)
            nodeProperty.setReadOnly((readOnly.equalsIgnoreCase("true") ? true : false));

        // markedForDeletion attribute
        nodeProperty.setMarkedForDeletion(markedForDeletion);
        set.add(nodeProperty);
    }

    return set;
}

From source file:ca.nrc.cadc.vos.TransferReader.java

License:Open Source License

private Transfer parseTransfer(Document document) throws URISyntaxException {
    Element root = document.getRootElement();

    Direction direction = parseDirection(root);
    // String serviceUrl; // not in XML yet
    VOSURI target = new VOSURI(root.getChildText("target", VOS_NS));

    // TODO: get view nodes and uri attribute
    View view = null;// w  w  w. j  a v  a 2  s.  c o m
    Parameter param = null;
    List views = root.getChildren("view", VOS_NS);
    if (views != null && views.size() > 0) {
        Element v = (Element) views.get(0);
        view = new View(new URI(v.getAttributeValue("uri")));
        List params = v.getChildren("param", VOS_NS);
        if (params != null) {
            for (Object o : params) {
                Element p = (Element) o;
                param = new Parameter(new URI(p.getAttributeValue("uri")), p.getText());
                view.getParameters().add(param);
            }
        }
    }
    List<Protocol> protocols = parseProtocols(root);
    String keepBytesStr = root.getChildText("keepBytes", VOS_NS);

    if (keepBytesStr != null) {
        boolean keepBytes = true;
        keepBytes = keepBytesStr.equalsIgnoreCase("true");
        return new Transfer(target, direction, view, protocols, keepBytes);
    }
    return new Transfer(target, direction, view, protocols);
}