Example usage for org.jdom2 Element setText

List of usage examples for org.jdom2 Element setText

Introduction

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

Prototype

public Element setText(final String text) 

Source Link

Document

Sets the content of the element to be the text given.

Usage

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

License:Open Source License

private void addChild(Element parent, String ename, String eval) {
    Element uri = new Element(ename);
    uri.setText(eval);
    parent.addContent(uri);//  w w  w. j a va2 s .co m
}

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

License:Open Source License

private void addGroups(List<URI> groups, Element parent) {
    for (URI u : groups) {
        Element uri = new Element(ArtifactAccessReader.ENAMES.uri.name());
        uri.setText(u.toASCIIString());
        parent.addContent(uri);//from   w  ww .  j  av  a2  s.c o  m
    }
}

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

License:Open Source License

/**
 * Builds a JDOM representation Element with the given name and sets the
 * text to the given value, then adds the element to the parent.
 * /*  ww w  .j  av a 2 s .c om*/
 * @param name
 *            The name of the element.
 * @param value
 *            The value for the element.
 * @param parent
 *            The parent element for this child element.
 */
protected void addElement(String name, String value, Element parent) {
    if (value == null) {
        return;
    }

    Element element = new Element(name, caom2Namespace);
    element.setText(value);
    parent.addContent(element);
}

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

License:Open Source License

/**
 * Builds a JDOM representation Element with the given name and sets the
 * text to the given value, then adds the element to the parent.
 * /*from  w ww  .  ja  va2 s  .c  o  m*/
 * @param name
 *            The name of the element.
 * @param number
 *            The value for the element.
 * @param parent
 *            The parent element for this child element.
 */
protected void addNumberElement(String name, Number number, Element parent) {
    if (number == null) {
        return;
    }

    Element element = new Element(name, caom2Namespace);
    element.setText(number.toString());
    parent.addContent(element);
}

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

License:Open Source License

/**
 * Builds a JDOM representation Element with the given name and sets the
 * text to true if the value is true, else sets the text to false, then adds
 * the element to the parent./*w w  w .ja v a 2s .co m*/
 * 
 * @param name
 *            The name of the element.
 * @param value
 *            The boolean value for the element.
 * @param parent
 *            The parent element for this child element.
 */
protected void addBooleanElement(String name, Boolean value, Element parent) {
    if (value == null) {
        return;
    }

    Element element = new Element(name, caom2Namespace);
    element.setText(value ? "true" : "false");
    parent.addContent(element);
}

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

License:Open Source License

/**
 * Builds a JDOM representation Element with the given name and sets the
 * text to the given value, then adds the element to the parent.
 * /* w w  w.  java2  s  . co m*/
 * @param name
 *            The name of the element.
 * @param uri
 *            The URI value for the element.
 * @param parent
 *            The parent element for this child element.
 */
protected void addURIElement(String name, URI uri, Element parent) {
    if (uri == null) {
        return;
    }

    Element element = new Element(name, caom2Namespace);
    element.setText(uri.toString());
    parent.addContent(element);
}

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

License:Open Source License

/**
 * Builds a JDOM representation Element with the given name and adds space
 * delimited List values as the text, then adds the element to the parent.
 * // w w  w . j a v a 2s  .  co m
 * @param name
 *            The name of the element.
 * @param values
 *            The List of Strings for the element.
 * @param parent
 *            The parent element for this child element.
 */
protected void addStringListElement(String name, Collection<String> values, Element parent) {
    if (values == null || (values.isEmpty() && !writeEmptyCollections)) {
        return;
    }

    Element element = new Element(name, caom2Namespace);
    StringBuilder sb = new StringBuilder();
    for (String value : values) {
        sb.append(value).append(" ");
    }
    element.setText(sb.toString().trim());
    parent.addContent(element);
}

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

License:Open Source License

/**
 * Builds a JDOM representation of the Date in IVOA format and adds it to
 * the Observation element.// ww  w  .ja v  a 2s .  co m
 * 
 * @param name
 *            The name of the element.
 * @param date
 *            The Date for the element.
 * @param parent
 *            The parent element for this child element.
 * @param dateFormat
 *            IVOA DateFormat.
 */
protected void addDateElement(String name, Date date, Element parent, DateFormat dateFormat) {
    if (date == null) {
        return;
    }

    Element element = new Element(name, caom2Namespace);
    element.setText(dateFormat.format(date));
    parent.addContent(element);
}

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

License:Open Source License

/**
 * Add a DESCRIPTION Element to the FIELD.
 * @param description/*w w  w. ja va 2  s. c o m*/
 * @param namespace
 */
protected void setDescription(String description, Namespace namespace) {
    if (description != null) {
        Element element = new Element("DESCRIPTION", namespace);
        element.setText(description);
        addContent(element);
    }
}

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

License:Open Source License

/**
 * Write the VOTable to the specified Writer, only writing maxrec rows.
 * If the VOTable contains more than maxrec rows, appends an INFO element with
 * name="QUERY_STATUS" value="OVERFLOW" to the VOTable.
 *
 * @param votable VOTable object to write.
 * @param writer Writer to write to.//from  ww  w  . j a v a  2  s .  com
 * @param maxRec maximum number of rows to write.
 * @throws IOException if problem writing to the writer.
 */
public void write(VOTable votable, Writer writer, Long maxrec) throws IOException {
    log.debug("write, maxrec=" + maxrec);

    // VOTable document and root element.
    Document document = createDocument();
    Element root = document.getRootElement();
    Namespace namespace = root.getNamespace();

    // Create the RESOURCE element and add to the VOTABLE element.
    Element resource = new Element("RESOURCE", namespace);
    if (votable.getResourceName() != null) {
        resource.setAttribute("name", votable.getResourceName());
    }
    root.addContent(resource);

    // Create the INFO element and add to the RESOURCE element.
    for (Info in : votable.getInfos()) {
        Element info = new Element("INFO", namespace);
        info.setAttribute("name", in.getName());
        info.setAttribute("value", in.getValue());
        resource.addContent(info);
    }

    // Create the TABLE element and add to the RESOURCE element.
    Element table = new Element("TABLE", namespace);
    resource.addContent(table);

    // Add the metadata elements.
    for (TableParam param : votable.getParams()) {
        table.addContent(new ParamElement(param, namespace));
    }
    for (TableField field : votable.getColumns()) {
        table.addContent(new FieldElement(field, namespace));
    }

    // Create the DATA and TABLEDATA elements.
    Element data = new Element("DATA", namespace);
    table.addContent(data);

    // Add content.
    try {
        Iterator<List<Object>> it = votable.getTableData().iterator();

        TabledataContentConverter elementConverter = new TabledataContentConverter(namespace);
        TabledataMaxIterations maxIterations = new TabledataMaxIterations(maxrec, resource, namespace);

        IterableContent<Element, List<Object>> tabledata = new IterableContent<Element, List<Object>>(
                "TABLEDATA", namespace, it, elementConverter, maxIterations);

        data.addContent(tabledata);
    } catch (Throwable t) {
        log.debug("failure while iterating", t);
        Element info = new Element("INFO", namespace);
        info.setAttribute("name", "QUERY_STATUS");
        info.setAttribute("value", "ERROR");
        info.setText(t.toString());
        resource.addContent(info);
    }

    // Write out the VOTABLE.
    XMLOutputter outputter = new XMLOutputter();
    outputter.setFormat(org.jdom2.output.Format.getPrettyFormat());
    outputter.output(document, writer);
}