Example usage for org.jdom2 Element addContent

List of usage examples for org.jdom2 Element addContent

Introduction

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

Prototype

@Override
public Element addContent(final Collection<? extends Content> newContent) 

Source Link

Document

Appends all children in the given collection to the end of the content list.

Usage

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

License:Open Source License

protected void addTimeElement(Time comp, Element parent) {
    if (docVersion < 22) {
        return;/*w w w . ja  v a  2 s. c o m*/
    }
    if (comp == null) {
        return;
    }

    Element e = getCaom2Element("time");
    if (comp.bounds != null) {
        Element pe = getCaom2Element("bounds");
        // String xsiType = caom2Namespace.getPrefix() + ":" +
        // Interval.class.getSimpleName();
        // pe.setAttribute("type", xsiType, xsiNamespace);
        addNumberElement("lower", comp.bounds.getLower(), pe);
        addNumberElement("upper", comp.bounds.getUpper(), pe);
        e.addContent(pe);
        if (!comp.bounds.getSamples().isEmpty()) {
            Element ses = getCaom2Element("samples");
            for (SubInterval si : comp.bounds.getSamples()) {
                Element se = getSampleElement(si);
                ses.addContent(se);
            }
            pe.addContent(ses);
        }
    }
    if (comp.dimension != null) {
        Element ce = getCaom2Element("dimension");
        // String xsiType = caom2Namespace.getPrefix() + ":" +
        // Long.class.getSimpleName();
        // ce.setAttribute("type", xsiType, xsiNamespace);
        ce.addContent(Long.toString(comp.dimension));
        e.addContent(ce);
    }
    if (comp.resolution != null) {
        addNumberElement("resolution", comp.resolution, e);
    }
    if (comp.sampleSize != null) {
        addNumberElement("sampleSize", comp.sampleSize, e);
    }
    if (comp.exposure != null) {
        addNumberElement("exposure", comp.exposure, e);
    }

    parent.addContent(e);
}

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

License:Open Source License

protected void addPolarizationElement(Polarization comp, Element parent) {
    if (docVersion < 22) {
        return;//ww  w.  j  a  v a  2  s.co m
    }
    if (comp == null) {
        return;
    }

    Element e = getCaom2Element("polarization");
    if (comp.states != null) {
        Element pe = getCaom2Element("states");
        for (PolarizationState s : comp.states) {
            addElement("state", s.stringValue(), pe);
        }
        e.addContent(pe);
    }
    if (comp.dimension != null) {
        Element ce = getCaom2Element("dimension");
        // String xsiType = caom2Namespace.getPrefix() + ":" +
        // Integer.class.getSimpleName();
        // ce.setAttribute("type", xsiType, xsiNamespace);
        ce.addContent(Long.toString(comp.dimension));
        e.addContent(ce);
    }

    parent.addContent(e);
}

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

License:Open Source License

/**
 * Builds a JDOM representation of an Telescope and adds it to the parent
 * element./*from  w w  w .  j  a v a 2 s  . co  m*/
 *
 * @param provenance
 *            The Provenance to add to the parent.
 * @param parent
 *            The parent element for this child element.
 * @param dateFormat
 *            The IVOA DateFormat.
 */
protected void addProvenanceElement(Provenance provenance, Element parent, DateFormat dateFormat) {
    if (provenance == null) {
        return;
    }

    Element element = getCaom2Element("provenance");
    addElement("name", provenance.getName(), element);
    addElement("version", provenance.version, element);
    addElement("project", provenance.project, element);
    addElement("producer", provenance.producer, element);
    addElement("runID", provenance.runID, element);
    addURIElement("reference", provenance.reference, element);
    addDateElement("lastExecuted", provenance.lastExecuted, element, dateFormat);
    if (docVersion < 23) {
        addStringListElement("keywords", provenance.getKeywords(), element);
    } else {
        addKeywordsElement(provenance.getKeywords(), element);
    }
    addInputsElement(provenance.getInputs(), element, dateFormat);
    parent.addContent(element);
}

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

License:Open Source License

protected void addMetricsElement(Metrics metrics, Element parent, DateFormat dateFormat) {
    if (metrics == null) {
        return;/*from  w  ww .j a v a2 s .c  o m*/
    }

    Element element = getCaom2Element("metrics");
    addNumberElement("sourceNumberDensity", metrics.sourceNumberDensity, element);
    addNumberElement("background", metrics.background, element);
    addNumberElement("backgroundStddev", metrics.backgroundStddev, element);
    addNumberElement("fluxDensityLimit", metrics.fluxDensityLimit, element);
    addNumberElement("magLimit", metrics.magLimit, element);
    parent.addContent(element);
}

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

License:Open Source License

/**
 * Add a JDOM representation of DaatQuality.
 * //from w  w  w. ja v a  2 s .  com
 * @param dq
 * @param parent
 * @param dateFormat
 */
protected void addQuaility(DataQuality dq, Element parent, DateFormat dateFormat) {
    if (docVersion < 21) {
        return; // DataQuality added in CAOM-2.1
    }
    if (dq == null) {
        return;
    }
    Element element = getCaom2Element("quality");
    Element flag = getCaom2Element("flag");
    flag.addContent(dq.getFlag().getValue());
    element.addContent(flag);
    parent.addContent(element);
}

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

License:Open Source License

protected void addTransitionElement(EnergyTransition transition, Element parent, DateFormat dateFormat) {
    if (transition == null) {
        return;//  w  ww  .  ja  v  a2 s.  c  om
    }

    Element element = getCaom2Element("transition");
    addElement("species", transition.getSpecies(), element);
    addElement("transition", transition.getTransition(), element);
    parent.addContent(element);
}

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

License:Open Source License

/**
 * Builds a JDOM representation of a Set of PlaneURI and adds it to the
 * parent element.//from  www .  j a  v a2 s  . com
 *
 * @param inputs
 *            The Set of PlaneURI to add to the parent.
 * @param parent
 *            The parent element for this child element.
 * @param dateFormat
 *            The IVOA DateFormat.
 */
protected void addInputsElement(Set<PlaneURI> inputs, Element parent, DateFormat dateFormat) {
    if (inputs == null || (inputs.isEmpty() && !writeEmptyCollections)) {
        return;
    }

    Element element = getCaom2Element("inputs");
    for (PlaneURI input : inputs) {
        addURIElement("planeURI", input.getURI(), element);
    }
    parent.addContent(element);
}

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

License:Open Source License

/**
 * Builds a JDOM representation of a Set of Artifact's and adds it to the
 * parent element.//from  w  ww. j  a v a 2  s. c  o  m
 *
 * @param artifacts
 *            The Set of Artifact's to add to the parent.
 * @param parent
 *            The parent element for this child element.
 * @param dateFormat
 *            IVOA DateFormat.
 */
protected void addArtifactsElement(Set<Artifact> artifacts, Element parent, DateFormat dateFormat) {
    if (artifacts == null || (artifacts.isEmpty() && !writeEmptyCollections)) {
        return;
    }

    Element element = getCaom2Element("artifacts");
    for (Artifact artifact : artifacts) {
        Element artifactElement = getCaom2Element("artifact");
        addEntityAttributes(artifact, artifactElement, dateFormat);
        addURIElement("uri", artifact.getURI(), artifactElement);

        if (docVersion >= 22) {
            addElement("productType", artifact.getProductType().getValue(), artifactElement);
            addElement("releaseType", artifact.getReleaseType().getValue(), artifactElement);
        }

        addElement("contentType", artifact.contentType, artifactElement);
        addNumberElement("contentLength", artifact.contentLength, artifactElement);

        if (docVersion < 22) {
            addElement("productType", artifact.getProductType().getValue(), artifactElement);
        }

        if (docVersion > 22) {
            addURIElement("contentChecksum", artifact.contentChecksum, artifactElement);
        }

        addPartsElement(artifact.getParts(), artifactElement, dateFormat);
        element.addContent(artifactElement);
    }
    parent.addContent(element);
}

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

License:Open Source License

/**
 * Builds a JDOM representation of a Set of Part's and adds it to the parent
 * element./*from   www  .j a v a  2 s.  c  o  m*/
 *
 * @param parts
 *            The Set of Part's to add to the parent.
 * @param parent
 *            The parent element for this child element.
 * @param dateFormat
 *            The IVOA DateFormat.
 */
protected void addPartsElement(Set<Part> parts, Element parent, DateFormat dateFormat) {
    if (parts == null || (parts.isEmpty() && !writeEmptyCollections)) {
        return;
    }

    Element element = getCaom2Element("parts");
    for (Part part : parts) {
        Element partElement = getCaom2Element("part");
        addEntityAttributes(part, partElement, dateFormat);
        addElement("name", part.getName(), partElement);
        if (part.productType != null) {
            addElement("productType", part.productType.getValue(), partElement);
        }
        addChunksElement(part.getChunks(), partElement, dateFormat);
        element.addContent(partElement);
    }
    parent.addContent(element);
}

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

License:Open Source License

/**
 * Builds a JDOM representation of a Set of Chunk's and adds it to the
 * parent element./* w w w .  j av a 2s  .c  om*/
 *
 * @param chunks
 *            The Set of Chunk's to add to the parent.
 * @param parent
 *            The parent element for this child element.
 * @param dateFormat
 *            The IVOA DateFormat.
 */
protected void addChunksElement(Set<Chunk> chunks, Element parent, DateFormat dateFormat) {
    if (chunks == null || (chunks.isEmpty() && !writeEmptyCollections)) {
        return;
    }

    Element element = getCaom2Element("chunks");
    for (Chunk chunk : chunks) {
        Element chunkElement = getCaom2Element("chunk");
        addEntityAttributes(chunk, chunkElement, dateFormat);
        if (chunk.productType != null) {
            addElement("productType", chunk.productType.getValue(), chunkElement);
        }
        addNumberElement("naxis", chunk.naxis, chunkElement);
        addNumberElement("observableAxis", chunk.observableAxis, chunkElement);
        addNumberElement("positionAxis1", chunk.positionAxis1, chunkElement);
        addNumberElement("positionAxis2", chunk.positionAxis2, chunkElement);
        addNumberElement("energyAxis", chunk.energyAxis, chunkElement);
        addNumberElement("timeAxis", chunk.timeAxis, chunkElement);
        addNumberElement("polarizationAxis", chunk.polarizationAxis, chunkElement);

        addObservableAxisElement(chunk.observable, chunkElement, dateFormat);
        addSpatialWCSElement(chunk.position, chunkElement, dateFormat);
        addSpectralWCSElement(chunk.energy, chunkElement, dateFormat);
        addTemporalWCSElement(chunk.time, chunkElement, dateFormat);
        addPolarizationWCSElement(chunk.polarization, chunkElement, dateFormat);

        element.addContent(chunkElement);
    }
    parent.addContent(element);
}