Example usage for org.jdom2 Element Element

List of usage examples for org.jdom2 Element Element

Introduction

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

Prototype

public Element(final String name, final String uri) 

Source Link

Document

Creates a new element with the supplied (local) name and a namespace given by a URI.

Usage

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.
 * //from  w  w  w. j a va  2 s  .  c o  m
 * @param name
 *            The name of the element.
 * @param values
 *            The List of CoordRange1D for the element.
 * @param parent
 *            The parent element for this child element.
 */
protected void addCoordRange1DListElement(String name, List<CoordRange1D> values, Element parent) {
    if (values == null) {
        return;
    }

    Element element = new Element(name, caom2Namespace);
    for (CoordRange1D range : values) {
        addCoordRange1DElement("range", range, element);
    }
    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.//from w ww  .  j  av  a  2  s .com
 * 
 * @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.caom2.xml.ObservationWriter.java

License:Open Source License

private Element getCaom2Element(String name) {
    return new Element(name, caom2Namespace);
}

From source file:ca.nrc.cadc.conformance.vos.InvalidTypeNodeWriter.java

License:Open Source License

/**
 * Returns the root JDOM Element of the node, with an invalid xsi:type
 * attribute./*www.  j a  va  2s. c  om*/
 *
 * @param node the Node.
 * @return the root element.
 */
@Override
protected Element getRootElement(Node node) {
    // Create the root element (node).
    Element root = new Element("node", NodeWriter.vosNamespace);
    root.addNamespaceDeclaration(NodeWriter.vosNamespace);
    root.addNamespaceDeclaration(NodeWriter.xsiNamespace);
    root.setAttribute("uri", node.getUri().toString());
    root.setAttribute("type", "vos:invalid_type" + "Type", NodeWriter.xsiNamespace);
    return root;
}

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

License:Open Source License

/**
 * Add a DESCRIPTION Element to the FIELD.
 * @param description//from  ww  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.FieldElement.java

License:Open Source License

/**
 * Add VALUES Element with OPTION child Elements.
 * @param values/*from   w ww .j a v a 2s  .co m*/
 * @param namespace
 */
protected void setValues(List<String> values, Namespace namespace) {
    if (values != null && !values.isEmpty()) {
        Element element = new Element("VALUES", namespace);
        for (String value : values) {
            Element option = new Element("OPTION", namespace);
            option.setAttribute("value", value);
            element.addContent(option);
        }
        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./*  ww w  .j a va 2 s.  c o  m*/
 * @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);
}

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

License:Open Source License

/**
 * Write the Throwable to a VOTable, creating an INFO element with
 * name="QUERY_STATUS" value="ERROR" and setting the stacktrace as
 * the INFO text./*  ww  w  . j a  v  a  2  s . co  m*/
 *
 * @param thrown Throwable to write.
 * @param output OutputStream to write to.
 * @throws IOException if problem writing to the stream.
 */
public void write(Throwable thrown, OutputStream output) throws IOException {
    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);
    resource.setAttribute("type", "results");
    root.addContent(resource);

    // Create the INFO element and add to the RESOURCE element.
    Element info = new Element("INFO", namespace);
    info.setAttribute("name", "QUERY_STATUS");
    info.setAttribute("value", "ERROR");
    info.setText(getThrownExceptions(thrown));
    resource.addContent(info);

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

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

License:Open Source License

/**
 * Builds a empty VOTable document with the appropriate namespaces and
 * attributes./*from w w  w.ja va 2s.  c  o  m*/
 *
 * @return VOTable document.
 */
protected Document createDocument() {
    // the root VOTABLE element
    Namespace vot = Namespace.getNamespace(VOTABLE_12_NS_URI);
    Namespace xsi = Namespace.getNamespace("xsi", XSI_SCHEMA);
    Element votable = new Element("VOTABLE", vot);
    votable.setAttribute("version", VOTABLE_VERSION);
    votable.addNamespaceDeclaration(xsi);

    Document document = new Document();
    document.addContent(votable);

    return document;
}

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

License:Open Source License

/**
 * Create the XML for a short job description.
 * @param jobRef//  w  w w  . j a  v  a  2s.  c o m
 * @return
 */
public Element getShortJobDescription(JobRef jobRef) {
    Element shortJobDescription = new Element(JobAttribute.JOB_REF.getAttributeName(), UWS.NS);
    shortJobDescription.setAttribute("id", jobRef.getJobID());
    shortJobDescription.addContent(getPhase(jobRef));
    shortJobDescription.addContent(getCreationTime(jobRef));
    shortJobDescription.addContent(getRunID(jobRef));
    shortJobDescription.addContent(getOwnerID(jobRef));
    return shortJobDescription;
}