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

/**
 * Builds a JDOM representation of an Target and adds it to the parent
 * element./*  ww  w .  j  a v a2  s  .com*/
 *
 * @param target
 *            The Target to add to the parent.
 * @param parent
 *            The parent element for this child element.
 * @param dateFormat
 *            The IVOA DateFormat.
 */
protected void addTargetElement(Target target, Element parent, DateFormat dateFormat) {
    if (target == null) {
        return;
    }

    Element element = getCaom2Element("target");
    addElement("name", target.getName(), element);
    if (target.type != null) {
        addElement("type", target.type.getValue(), element);
    }
    addBooleanElement("standard", target.standard, element);
    addNumberElement("redshift", target.redshift, element);
    addBooleanElement("moving", target.moving, element);
    if (docVersion < 23) {
        addStringListElement("keywords", target.getKeywords(), element);
    } else {
        addKeywordsElement(target.getKeywords(), element);
    }
    parent.addContent(element);
}

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

License:Open Source License

/**
 * Builds a JDOM representation of an TargetPosition and adds it to the
 * parent element.//from  w w  w  .  j a  va 2s .c  o  m
 *
 * @param targetPosition
 *            The Target to add to the parent.
 * @param parent
 *            The parent element for this child element.
 * @param dateFormat
 *            The IVOA DateFormat.
 */
protected void addTargetPositionElement(TargetPosition targetPosition, Element parent, DateFormat dateFormat) {
    if (targetPosition == null) {
        return;
    }

    Element element = getCaom2Element("targetPosition");
    Element coordsys = getCaom2Element("coordsys");
    coordsys.addContent(targetPosition.getCoordsys());
    element.addContent(coordsys);
    if (targetPosition.equinox != null) {
        Element equinox = getCaom2Element("equinox");
        equinox.addContent(targetPosition.equinox.toString());
        element.addContent(equinox);
    }
    Element coords = getCaom2Element("coordinates");
    addNumberElement("cval1", targetPosition.getCoordinates().cval1, coords);
    addNumberElement("cval2", targetPosition.getCoordinates().cval2, coords);
    element.addContent(coords);
    parent.addContent(element);
}

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

License:Open Source License

/**
 * Add a JDOM representation of Requirements.
 * //w  w  w  .j  a va  2s  . c o m
 * @param req
 * @param parent
 * @param dateFormat
 */
protected void addRequirements(Requirements req, Element parent, DateFormat dateFormat) {
    if (docVersion < 21) {
        return; // Requirements added in CAOM-2.1
    }
    if (req == null) {
        return;
    }
    Element element = getCaom2Element("requirements");
    Element flag = getCaom2Element("flag");
    flag.addContent(req.getFlag().getValue());
    element.addContent(flag);
    parent.addContent(element);
}

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 . java2  s  .  co  m*/
 *
 * @param telescope
 *            The Telescope to add to the parent.
 * @param parent
 *            The parent element for this child element.
 * @param dateFormat
 *            The IVOA DateFormat.
 */
protected void addTelescopeElement(Telescope telescope, Element parent, DateFormat dateFormat) {
    if (telescope == null) {
        return;
    }

    Element element = getCaom2Element("telescope");
    addElement("name", telescope.getName(), element);
    addNumberElement("geoLocationX", telescope.geoLocationX, element);
    addNumberElement("geoLocationY", telescope.geoLocationY, element);
    addNumberElement("geoLocationZ", telescope.geoLocationZ, element);
    if (docVersion < 23) {
        addStringListElement("keywords", telescope.getKeywords(), element);
    } else {
        addKeywordsElement(telescope.getKeywords(), element);
    }
    parent.addContent(element);
}

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

License:Open Source License

/**
 * Builds a JDOM representation of an Instrument and adds it to the parent
 * element.//from   w ww .  ja v  a 2 s.  c o m
 *
 * @param instrument
 *            The Instrument to add to the parent.
 * @param parent
 *            The parent element for this child element.
 * @param dateFormat
 *            The IVOA DateFormat.
 */
protected void addInstrumentElement(Instrument instrument, Element parent, DateFormat dateFormat) {
    if (instrument == null) {
        return;
    }

    Element element = getCaom2Element("instrument");
    addElement("name", instrument.getName(), element);
    if (docVersion < 23) {
        addStringListElement("keywords", instrument.getKeywords(), element);
    } else {
        addKeywordsElement(instrument.getKeywords(), element);
    }
    parent.addContent(element);
}

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

License:Open Source License

/**
 * Builds a JDOM representation of an Environment and adds it to the parent
 * element.//from ww w.jav a  2  s .  c  o  m
 *
 * @param environment
 *            The Environment to add to the parent.
 * @param parent
 *            The parent element for this child element.
 * @param dateFormat
 *            The IVOA DateFormat.
 */
protected void addEnvironmentElement(Environment environment, Element parent, DateFormat dateFormat) {
    if (environment == null) {
        return;
    }

    Element element = getCaom2Element("environment");
    addNumberElement("seeing", environment.seeing, element);
    addNumberElement("humidity", environment.humidity, element);
    addNumberElement("elevation", environment.elevation, element);
    addNumberElement("tau", environment.tau, element);
    addNumberElement("wavelengthTau", environment.wavelengthTau, element);
    addNumberElement("ambientTemp", environment.ambientTemp, element);
    addBooleanElement("photometric", environment.photometric, 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 ObservationURI and adds it to
 * the parent element.// w  w w  . j a v  a2 s.c o m
 *
 * @param members
 *            The Set of ObservationURI to add to the parent.
 * @param parent
 *            The parent element for this child element.
 * @param dateFormat
 *            The IVOA DateFormat.
 */
protected void addMembersElement(Set<ObservationURI> members, Element parent, DateFormat dateFormat) {
    if (members == null || (members.isEmpty() && !writeEmptyCollections)) {
        return;
    }

    Element element = getCaom2Element("members");
    for (ObservationURI member : members) {
        addURIElement("observationURI", member.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 Plane's and adds it to the
 * parent element.//from  www.j  av a2s  . co  m
 *
 * @param planes
 *            The Set of Plane's to add to the parent.
 * @param parent
 *            The parent element for this child element.
 * @param dateFormat
 *            The IVOA DateFormat.
 */
protected void addPlanesElement(Set<Plane> planes, Element parent, DateFormat dateFormat) {
    if (planes == null || (planes.isEmpty() && !writeEmptyCollections)) {
        return;
    }

    Element element = getCaom2Element("planes");
    for (Plane plane : planes) {
        Element planeElement = getCaom2Element("plane");
        addEntityAttributes(plane, planeElement, dateFormat);
        addElement("productID", plane.getProductID(), planeElement);

        if (docVersion >= 23 && plane.creatorID != null) {
            addURIElement("creatorID", plane.creatorID, planeElement);
        }

        addDateElement("metaRelease", plane.metaRelease, planeElement, dateFormat);
        addDateElement("dataRelease", plane.dataRelease, planeElement, dateFormat);
        if (plane.dataProductType != null) {
            if (docVersion < 23 && DataProductType.CATALOG.equals(plane.dataProductType)) {
                addElement("dataProductType", plane.dataProductType.getTerm(), planeElement);
            } else {
                addElement("dataProductType", plane.dataProductType.getValue(), planeElement);
            }
        }
        if (plane.calibrationLevel != null) {
            addElement("calibrationLevel", String.valueOf(plane.calibrationLevel.getValue()), planeElement);
        }
        addProvenanceElement(plane.provenance, planeElement, dateFormat);
        addMetricsElement(plane.metrics, planeElement, dateFormat);
        addQuaility(plane.quality, planeElement, dateFormat);

        addPositionElement(plane.position, planeElement);
        addEnergyElement(plane.energy, planeElement);
        addTimeElement(plane.time, planeElement);
        addPolarizationElement(plane.polarization, planeElement);

        addArtifactsElement(plane.getArtifacts(), planeElement, dateFormat);
        element.addContent(planeElement);
    }
    parent.addContent(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;/*  w ww. jav a 2  s  .  c o  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.caom2.xml.ObservationWriter.java

License:Open Source License

protected void addEnergyElement(Energy comp, Element parent) {
    if (docVersion < 22) {
        return;/*from w  ww .  ja  v a 2s. co m*/
    }
    if (comp == null) {
        return;
    }

    Element e = getCaom2Element("energy");
    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.resolvingPower != null) {
        addNumberElement("resolvingPower", comp.resolvingPower, e);
    }
    if (comp.sampleSize != null) {
        addNumberElement("sampleSize", comp.sampleSize, e);
    }
    if (comp.bandpassName != null) {
        addElement("bandpassName", comp.bandpassName, e);
    }
    if (comp.emBand != null) {
        addElement("emBand", comp.emBand.getValue(), e);
    }
    if (comp.restwav != null) {
        addNumberElement("restwav", comp.restwav, e);
    }
    if (comp.transition != null) {
        Element ce = getCaom2Element("transition");
        addElement("species", comp.transition.getSpecies(), ce);
        addElement("transition", comp.transition.getTransition(), ce);
        e.addContent(ce);
    }

    parent.addContent(e);
}