Example usage for org.jdom2 Element setAttribute

List of usage examples for org.jdom2 Element setAttribute

Introduction

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

Prototype

public Element setAttribute(final String name, final String value, final Namespace ns) 

Source Link

Document

This sets an attribute value for this element.

Usage

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

License:Open Source License

private void addEntityAttributes(CaomEntity ce, Element el, DateFormat df) {
    if (docVersion < 21) {
        el.setAttribute("id", CaomUtil.uuidToLong(ce.getID()).toString(), caom2Namespace);
    } else {/*  ww w  .j a v a2 s .co  m*/
        el.setAttribute("id", ce.getID().toString(), caom2Namespace);
    }

    if (ce.getLastModified() != null) {
        el.setAttribute("lastModified", df.format(ce.getLastModified()), el.getNamespace());
    }

    if (docVersion >= 23 && ce.getMaxLastModified() != null) {
        el.setAttribute("maxLastModified", df.format(ce.getMaxLastModified()), el.getNamespace());
    }

    if (docVersion >= 23 && ce.getMetaChecksum() != null) {
        el.setAttribute("metaChecksum", ce.getMetaChecksum().toASCIIString(), el.getNamespace());
    }

    if (docVersion >= 23 && ce.getAccMetaChecksum() != null) {
        el.setAttribute("accMetaChecksum", ce.getAccMetaChecksum().toASCIIString(), el.getNamespace());
    }
}

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

License:Open Source License

/**
 * Builds a JDOM representation of an Observation.
 *
 * @param obs/*from  ww  w. j  a  va  2s  . co  m*/
 *            The Observation.
 * @return a JDOM Element representing the Observation.
 */
protected Element getObservationElement(Observation obs) {
    // IVOA DateFormat.
    DateFormat dateFormat = DateUtil.getDateFormat(DateUtil.IVOA_DATE_FORMAT, DateUtil.UTC);

    Element element = getCaom2Element("Observation");
    String type = caom2Namespace.getPrefix() + ":" + obs.getClass().getSimpleName();
    element.setAttribute("type", type, xsiNamespace);

    addEntityAttributes(obs, element, dateFormat);

    addElement("collection", obs.getCollection(), element);
    addElement("observationID", obs.getObservationID(), element);

    // Observation elements.
    addDateElement("metaRelease", obs.metaRelease, element, dateFormat);
    addNumberElement("sequenceNumber", obs.sequenceNumber, element);
    addAlgorithmElement(obs.getAlgorithm(), element, dateFormat);
    addElement("type", obs.type, element);
    if (obs.intent != null) {
        addElement("intent", obs.intent.getValue(), element);
    }
    addProposalElement(obs.proposal, element, dateFormat);
    addTargetElement(obs.target, element, dateFormat);
    addTargetPositionElement(obs.targetPosition, element, dateFormat);
    addRequirements(obs.requirements, element, dateFormat);
    addTelescopeElement(obs.telescope, element, dateFormat);
    addInstrumentElement(obs.instrument, element, dateFormat);
    addEnvironmentElement(obs.environment, element, dateFormat);
    addPlanesElement(obs.getPlanes(), element, dateFormat);

    // Members must be the last element.
    if (obs instanceof CompositeObservation) {
        addMembersElement(((CompositeObservation) obs).getMembers(), element, dateFormat);
    }

    return element;
}

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

License:Open Source License

protected void addPositionElement(Position comp, Element parent) {
    if (docVersion < 22) {
        return;/*www  . j a  v a 2 s  .co  m*/
    }
    if (comp == null) {
        return;
    }

    Element e = getCaom2Element("position");
    if (comp.bounds != null) {
        if (comp.bounds instanceof Circle) {
            Circle circ = (Circle) comp.bounds;
            Element pe = getCaom2Element("bounds");
            String xsiType = caom2Namespace.getPrefix() + ":" + Circle.class.getSimpleName();
            pe.setAttribute("type", xsiType, xsiNamespace);

            Element ce = getCaom2Element("center");
            addNumberElement("cval1", circ.getCenter().cval1, ce);
            addNumberElement("cval2", circ.getCenter().cval2, ce);
            pe.addContent(ce);
            addNumberElement("radius", circ.getRadius(), pe);
            e.addContent(pe);
        } else if (comp.bounds instanceof Polygon) {
            if (docVersion < 23) {
                throw new UnsupportedOperationException("cannot downgrade polygon doc version " + docVersion);
            }
            Polygon poly = (Polygon) comp.bounds;
            Element pe = getCaom2Element("bounds");
            String xsiType = caom2Namespace.getPrefix() + ":" + Polygon.class.getSimpleName();
            pe.setAttribute("type", xsiType, xsiNamespace);

            Element pes = getCaom2Element("points");

            for (Point p : poly.getPoints()) {
                Element ppe = getCaom2Element("point");
                addNumberElement("cval1", p.cval1, ppe);
                addNumberElement("cval2", p.cval2, ppe);
                pes.addContent(ppe);
            }
            pe.addContent(pes);

            Element se = getCaom2Element("samples");
            Element ves = getCaom2Element("vertices");
            MultiPolygon mp = poly.getSamples();
            for (Vertex v : mp.getVertices()) {
                Element ve = getCaom2Element("vertex");
                addNumberElement("cval1", v.cval1, ve);
                addNumberElement("cval2", v.cval2, ve);
                addNumberElement("type", v.getType().getValue(), ve);
                ves.addContent(ve);
            }
            se.addContent(ves);
            pe.addContent(se);
            e.addContent(pe);
        } else {
            throw new UnsupportedOperationException(comp.bounds.getClass().getName() + " -> XML");
        }
    }
    if (comp.dimension != null) {
        Element ce = getCaom2Element("dimension");
        // String xsiType = caom2Namespace.getPrefix() + ":" +
        // Dimension2D.class.getSimpleName();
        // ce.setAttribute("type", xsiType, xsiNamespace);
        addNumberElement("naxis1", comp.dimension.naxis1, ce);
        addNumberElement("naxis2", comp.dimension.naxis2, ce);
        e.addContent(ce);
    }
    if (comp.resolution != null) {
        addNumberElement("resolution", comp.resolution, e);
    }
    if (comp.sampleSize != null) {
        addNumberElement("sampleSize", comp.sampleSize, e);
    }
    if (comp.timeDependent != null) {
        addBooleanElement("timeDependent", comp.timeDependent, e);
    }
    parent.addContent(e);
}

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

License:Open Source License

/**
 * Get an Element representing the runID.
 *
 * @return The runID element./*w  w w .j  a va  2  s  .c  o  m*/
 */
private Element getRunID(JobRef jobRef) {
    Element element = new Element(JobAttribute.RUN_ID.getAttributeName(), UWS.NS);
    String runID = jobRef.getRunID();
    if (runID == null)
        element.setAttribute("nil", "true", UWS.XSI_NS);
    else
        element.addContent(runID);
    return element;
}

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

License:Open Source License

/**
 * Get an Element representing the creation time.
 *
 * @return The creation time element.// www. j a  v a2  s. c  o m
 */
private Element getCreationTime(JobRef jobRef) {
    Element element = new Element(JobAttribute.CREATION_TIME.getAttributeName(), UWS.NS);
    Date creationTime = jobRef.getCreationTime();
    if (creationTime == null)
        element.setAttribute("nil", "true", UWS.XSI_NS);
    else
        element.addContent(dateFormat.format(jobRef.getCreationTime()));
    return element;
}

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

License:Open Source License

/**
 * Get an Element representing the Job ownerId.
 *
 * @return The Job ownerId Element./*from www. j a va2s.  c  om*/
 */
public Element getOwnerId(Job job) {
    Element element = new Element(JobAttribute.OWNER_ID.getAttributeName(), UWS.NS);
    if (job.getOwnerID() != null)
        element.addContent(job.getOwnerID());
    else
        element.setAttribute("nil", "true", UWS.XSI_NS);
    return element;
}

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

License:Open Source License

/**
 * Get an Element representing the Job quote.
 *
 * @return The Job quote Element./*w ww  .  j  a v  a 2s  .  c  om*/
 */
public Element getQuote(Job job) {
    Element element = new Element(JobAttribute.QUOTE.getAttributeName(), UWS.NS);
    Date date = job.getQuote();
    if (date == null)
        element.setAttribute("nil", "true", UWS.XSI_NS);
    else
        element.addContent(dateFormat.format(date));
    return element;
}

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

License:Open Source License

/**
 * Get an Element representing the Job startTime.
 *
 * @return The Job startTime Element./*from   www  . j  ava2s .c o m*/
 */
public Element getStartTime(Job job) {
    Element element = new Element(JobAttribute.START_TIME.getAttributeName(), UWS.NS);
    Date date = job.getStartTime();
    if (date == null)
        element.setAttribute("nil", "true", UWS.XSI_NS);
    else
        element.addContent(dateFormat.format(date));
    return element;
}

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

License:Open Source License

/**
 * Get an Element representing the Job endTime.
 *
 * @return The Job endTime Element.//from w  w  w .java 2 s  . co m
 */
public Element getEndTime(Job job) {
    Element element = new Element(JobAttribute.END_TIME.getAttributeName(), UWS.NS);
    Date date = job.getEndTime();
    if (date == null)
        element.setAttribute("nil", "true", UWS.XSI_NS);
    else
        element.addContent(dateFormat.format(date));
    return element;
}

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

License:Open Source License

/**
 * Get an Element representing the Job creationTime.
 *
 * @return The Job creationTime Element.
 *///w  w  w. ja v  a  2 s .  com
public Element getCreationTime(Job job) {
    Element element = new Element(JobAttribute.CREATION_TIME.getAttributeName(), UWS.NS);
    Date date = job.getCreationTime();
    if (date == null)
        element.setAttribute("nil", "true", UWS.XSI_NS);
    else
        element.addContent(dateFormat.format(date));
    return element;
}