Example usage for org.jdom2 Element getContentSize

List of usage examples for org.jdom2 Element getContentSize

Introduction

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

Prototype

@Override
    public int getContentSize() 

Source Link

Usage

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

License:Open Source License

/**
 * Build an Algorithm from a JDOM representation of an algorithm element.
 *
 * @param parent/*from w  w  w .  ja v  a 2 s  . co  m*/
 *            the parent Element.
 * @param namespace
 *            of the document.
 * @param rc
 * @return an Algorithm, or null if the document doesn't contain an
 *         algorithm element.
 * @throws ObservationParsingException
 */
protected Environment getEnvironment(Element parent, Namespace namespace, ReadContext rc)
        throws ObservationParsingException {
    Element element = getChildElement("environment", parent, namespace, false);
    if (element == null || element.getContentSize() == 0) {
        return null;
    }

    Environment env = new Environment();
    env.seeing = getChildTextAsDouble("seeing", element, namespace, false);
    env.humidity = getChildTextAsDouble("humidity", element, namespace, false);
    env.elevation = getChildTextAsDouble("elevation", element, namespace, false);
    env.tau = getChildTextAsDouble("tau", element, namespace, false);
    env.wavelengthTau = getChildTextAsDouble("wavelengthTau", element, namespace, false);
    env.ambientTemp = getChildTextAsDouble("ambientTemp", element, namespace, false);
    env.photometric = getChildTextAsBoolean("photometric", element, namespace, false);
    return env;
}

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

License:Open Source License

/**
 * Build an Algorithm from a JDOM representation of an algorithm element.
 * // w  w w  . ja  v a 2s  . c o  m
 * @param parent
 *            the parent Element.
 * @param namespace
 *            of the document.
 * @param rc
 * @return an Algorithm, or null if the document doesn't contain an
 *         algorithm element.
 * @throws ObservationParsingException
 */
protected Algorithm getAlgorithm(Element parent, Namespace namespace, ReadContext rc)
        throws ObservationParsingException {
    Element element = getChildElement("algorithm", parent, namespace, true);
    if (element == null || element.getContentSize() == 0) {
        return null;
    }

    String name = getChildText("name", element, namespace, true);
    return new Algorithm(name);
}

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

License:Open Source License

/**
 * Build an Proposal from a JDOM representation of an proposal element.
 * //from  w  w  w . j a v a 2 s  . co  m
 * @param parent
 *            the parent Element.
 * @param namespace
 *            of the document.
 * @param rc
 * @return an Proposal, or null if the document doesn't contain an proposal
 *         element.
 * @throws ObservationParsingException
 */
protected Proposal getProposal(Element parent, Namespace namespace, ReadContext rc)
        throws ObservationParsingException {
    Element element = getChildElement("proposal", parent, namespace, false);
    if (element == null || element.getContentSize() == 0) {
        return null;
    }

    String id = getChildText("id", element, namespace, true);
    // no check for null: Proposal will check and throw if illegal
    Proposal proposal = new Proposal(id);

    proposal.pi = getChildText("pi", element, namespace, false);
    proposal.project = getChildText("project", element, namespace, false);
    proposal.title = getChildText("title", element, namespace, false);
    if (rc.docVersion < 23) {
        addChildTextToStringList("keywords", proposal.getKeywords(), element, namespace, false);
    } else {
        addKeywordsToList(proposal.getKeywords(), element, namespace);
    }

    return proposal;
}

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

License:Open Source License

/**
 * Build an Target from a JDOM representation of an target element.
 * /*from  ww w  .  j  av  a 2  s . c o m*/
 * @param parent
 *            the parent Element.
 * @param namespace
 *            of the document.
 * @param rc
 * @return an Target, or null if the document doesn't contain an target
 *         element.
 * @throws ObservationParsingException
 */
protected Target getTarget(Element parent, Namespace namespace, ReadContext rc)
        throws ObservationParsingException {
    Element element = getChildElement("target", parent, namespace, false);
    if (element == null || element.getContentSize() == 0) {
        return null;
    }

    String name = getChildText("name", element, namespace, true);

    Target target = new Target(name);

    String type = getChildText("type", element, namespace, false);
    if (type != null) {
        target.type = TargetType.toValue(type);
    }

    target.standard = getChildTextAsBoolean("standard", element, namespace, false);
    target.redshift = getChildTextAsDouble("redshift", element, namespace, false);
    target.moving = getChildTextAsBoolean("moving", element, namespace, false);
    if (rc.docVersion < 23) {
        addChildTextToStringList("keywords", target.getKeywords(), element, namespace, false);
    } else {
        addKeywordsToList(target.getKeywords(), element, namespace);
    }

    return target;
}

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

License:Open Source License

/**
 * Build a TargetPosition from a JDOM representation of an targetPosition
 * element.//  ww w  .  j  a v a  2  s .  c  o  m
 * 
 * @param parent
 *            the parent Element.
 * @param namespace
 *            of the document.
 * @param rc
 * @return a TargetPosition, or null if the document doesn't contain an
 *         targetPosition element.
 * @throws ObservationParsingException
 */
protected TargetPosition getTargetPosition(Element parent, Namespace namespace, ReadContext rc)
        throws ObservationParsingException {
    Element element = getChildElement("targetPosition", parent, namespace, false);
    if (element == null || element.getContentSize() == 0) {
        return null;
    }

    String coordsys = getChildText("coordsys", element, namespace, true);
    Double equinox = getChildTextAsDouble("equinox", element, namespace, false);
    Element coords = getChildElement("coordinates", element, namespace, true);
    double cval1 = getChildTextAsDouble("cval1", coords, namespace, true);
    double cval2 = getChildTextAsDouble("cval2", coords, namespace, true);

    TargetPosition tpos = new TargetPosition(coordsys, new Point(cval1, cval2));
    tpos.equinox = equinox;

    return tpos;
}

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

License:Open Source License

/**
 * //from w w  w .j  av  a 2s . c o  m
 * @param parent
 * @param namespace
 * @param rc
 * @return
 * @throws ObservationParsingException
 */
protected Requirements getRequirements(Element parent, Namespace namespace, ReadContext rc)
        throws ObservationParsingException {
    Element element = getChildElement("requirements", parent, namespace, false);
    if (element == null || element.getContentSize() == 0) {
        return null;
    }

    String flag = getChildText("flag", element, namespace, true);
    Requirements req = new Requirements(Status.toValue(flag));

    return req;
}

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

License:Open Source License

/**
 * Build an Telescope from a JDOM representation of an telescope element.
 * // ww w .j  a v  a2  s  .com
 * @param parent
 *            the parent Element.
 * @param namespace
 *            of the document.
 * @param rc
 * @return an TarTelescopeget, or null if the document doesn't contain an
 *         telescope element.
 * @throws ObservationParsingException
 */
protected Telescope getTelescope(Element parent, Namespace namespace, ReadContext rc)
        throws ObservationParsingException {
    Element element = getChildElement("telescope", parent, namespace, false);
    if (element == null || element.getContentSize() == 0) {
        return null;
    }

    String name = getChildText("name", element, namespace, true);
    Telescope telescope = new Telescope(name);

    telescope.geoLocationX = getChildTextAsDouble("geoLocationX", element, namespace, false);
    telescope.geoLocationY = getChildTextAsDouble("geoLocationY", element, namespace, false);
    telescope.geoLocationZ = getChildTextAsDouble("geoLocationZ", element, namespace, false);
    if (rc.docVersion < 23) {
        addChildTextToStringList("keywords", telescope.getKeywords(), element, namespace, false);
    } else {
        addKeywordsToList(telescope.getKeywords(), element, namespace);
    }

    return telescope;
}

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

License:Open Source License

/**
 * Build an Instrument from a JDOM representation of an instrument element.
 * //from ww w.  ja va2  s.  co m
 * @param parent
 *            the parent Element.
 * @param namespace
 *            of the document.
 * @param rc
 * @return an Instrument, or null if the document doesn't contain an
 *         instrument element.
 * @throws ObservationParsingException
 */
protected Instrument getInstrument(Element parent, Namespace namespace, ReadContext rc)
        throws ObservationParsingException {
    Element element = getChildElement("instrument", parent, namespace, false);
    if (element == null || element.getContentSize() == 0) {
        return null;
    }

    String name = getChildText("name", element, namespace, true);
    Instrument instrument = new Instrument(name);

    if (rc.docVersion < 23) {
        addChildTextToStringList("keywords", instrument.getKeywords(), element, namespace, false);
    } else {
        addKeywordsToList(instrument.getKeywords(), element, namespace);
    }

    return instrument;
}

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

License:Open Source License

/**
 * Creates Plane's from the plane elements found in the planes element, and
 * adds them to the given Set of Plane's.
 * /*from  w  w  w. jav  a 2  s  .co  m*/
 * @param planes
 *            the Set of Plane's from the Observation.
 * @param parent
 *            the parent Element.
 * @param namespace
 *            of the document.
 * @param rc
 * @throws ObservationParsingException
 */
protected void addPlanes(Set<Plane> planes, Element parent, Namespace namespace, ReadContext rc)
        throws ObservationParsingException {
    Element element = getChildElement("planes", parent, namespace, false);
    if (element == null || element.getContentSize() == 0) {
        return;
    }

    List planeElements = getChildrenElements("plane", element, namespace, false);
    Iterator it = planeElements.iterator();
    while (it.hasNext()) {
        Element planeElement = (Element) it.next();
        String productID = getChildText("productID", planeElement, namespace, true);
        Plane plane = new Plane(productID);

        plane.metaRelease = getChildTextAsDate("metaRelease", planeElement, namespace, false, rc.dateFormat);
        plane.dataRelease = getChildTextAsDate("dataRelease", planeElement, namespace, false, rc.dateFormat);

        String creatorIDStr = getChildText("creatorID", planeElement, namespace, false);
        if (creatorIDStr != null) {
            try {
                plane.creatorID = new URI(creatorIDStr);
            } catch (URISyntaxException e) {
                String error = "Unable to parse creatorID " + creatorIDStr + " to URI in element "
                        + element.getName() + " because " + e.getMessage();
                throw new ObservationParsingException(error, e);
            }
        }

        String dataProductType = getChildText("dataProductType", planeElement, namespace, false);
        if (dataProductType != null) {
            plane.dataProductType = DataProductType.toValue(dataProductType);
        }

        String calibrationLevel = getChildText("calibrationLevel", planeElement, namespace, false);
        if (calibrationLevel != null) {
            plane.calibrationLevel = CalibrationLevel.toValue(Integer.parseInt(calibrationLevel));
        }

        plane.provenance = getProvenance(planeElement, namespace, rc);
        plane.metrics = getMetrics(planeElement, namespace, rc);
        plane.quality = getQuality(planeElement, namespace, rc);

        plane.position = getPosition(planeElement, namespace, rc);
        plane.energy = getEnergy(planeElement, namespace, rc);
        plane.time = getTime(planeElement, namespace, rc);
        plane.polarization = getPolarization(planeElement, namespace, rc);

        addArtifacts(plane.getArtifacts(), planeElement, namespace, rc);

        assignEntityAttributes(planeElement, plane, rc);

        boolean added = planes.add(plane);
        if (!added) {
            throw new IllegalArgumentException("Plane.productID = " + productID + " is not unique");
        }
    }
}

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

License:Open Source License

/**
 * Build a Provenance from a JDOM representation of an Provenance.
 * /*from   w ww.ja  va  2  s.co m*/
 * @param parent
 *            the parent Element.
 * @param namespace
 *            of the document.
 * @param rc
 * @return an Provenance, or null if the document doesn't contain a
 *         provenance element.
 * @throws ObservationParsingException
 */
protected Provenance getProvenance(Element parent, Namespace namespace, ReadContext rc)
        throws ObservationParsingException {
    Element element = getChildElement("provenance", parent, namespace, false);
    if (element == null || element.getContentSize() == 0) {
        return null;
    }

    String name = getChildText("name", element, namespace, true);
    Provenance provenance = new Provenance(name);

    provenance.version = getChildText("version", element, namespace, false);
    provenance.project = getChildText("project", element, namespace, false);
    provenance.producer = getChildText("producer", element, namespace, false);
    provenance.runID = getChildText("runID", element, namespace, false);
    String reference = getChildText("reference", element, namespace, false);
    if (reference != null) {
        try {
            provenance.reference = new URI(reference);
        } catch (URISyntaxException e) {
            String error = "Unable to parse reference " + reference + " to URI in element " + element.getName()
                    + " because " + e.getMessage();
            throw new ObservationParsingException(error);
        }
    }
    provenance.lastExecuted = getChildTextAsDate("lastExecuted", element, namespace, false, rc.dateFormat);
    if (rc.docVersion < 23) {
        addChildTextToStringList("keywords", provenance.getKeywords(), element, namespace, false);
    } else {
        addKeywordsToList(provenance.getKeywords(), element, namespace);
    }
    addInputs(provenance.getInputs(), element, namespace, rc);

    return provenance;
}