List of usage examples for org.jdom2 Element getContentSize
@Override public int getContentSize()
From source file:ca.nrc.cadc.caom2.xml.ObservationReader.java
License:Open Source License
protected Metrics getMetrics(Element parent, Namespace namespace, ReadContext rc) throws ObservationParsingException { Element element = getChildElement("metrics", parent, namespace, false); if (element == null || element.getContentSize() == 0) { return null; }/*from w w w.j a va 2s .c o m*/ Metrics metrics = new Metrics(); metrics.sourceNumberDensity = getChildTextAsDouble("sourceNumberDensity", element, namespace, false); metrics.background = getChildTextAsDouble("background", element, namespace, false); metrics.backgroundStddev = getChildTextAsDouble("backgroundStddev", element, namespace, false); metrics.fluxDensityLimit = getChildTextAsDouble("fluxDensityLimit", element, namespace, false); metrics.magLimit = getChildTextAsDouble("magLimit", element, namespace, false); return metrics; }
From source file:ca.nrc.cadc.caom2.xml.ObservationReader.java
License:Open Source License
/** * /*from w ww . j av a2 s . c o m*/ * @param parent * @param namespace * @param rc * @return * @throws ObservationParsingException */ protected DataQuality getQuality(Element parent, Namespace namespace, ReadContext rc) throws ObservationParsingException { Element element = getChildElement("quality", parent, namespace, false); if (element == null || element.getContentSize() == 0) { return null; } String flag = getChildText("flag", element, namespace, true); DataQuality ret = new DataQuality(Quality.toValue(flag)); return ret; }
From source file:ca.nrc.cadc.caom2.xml.ObservationReader.java
License:Open Source License
protected EnergyTransition getTransition(Element parent, Namespace namespace, ReadContext rc) throws ObservationParsingException { Element element = getChildElement("transition", parent, namespace, false); if (element == null || element.getContentSize() == 0) { return null; }//w w w . j a v a 2 s . co m String species = getChildText("species", element, namespace, true); String transition = getChildText("transition", element, namespace, true); return new EnergyTransition(species, transition); }
From source file:ca.nrc.cadc.caom2.xml.ObservationReader.java
License:Open Source License
/** * Creates Artifact's from the artifact elements found in the artifacts * element, and adds them to the given Set of Artifact's. * //w ww .ja v a2 s.c o m * @param artifacts * the Set of Artifact's from the Plane. * @param parent * the parent Element. * @param namespace * of the document. * @param rc * @throws ObservationParsingException */ protected void addArtifacts(Set<Artifact> artifacts, Element parent, Namespace namespace, ReadContext rc) throws ObservationParsingException { Element element = getChildElement("artifacts", parent, namespace, false); if (element == null || element.getContentSize() == 0) { return; } List artifactElements = getChildrenElements("artifact", element, namespace, false); Iterator it = artifactElements.iterator(); while (it.hasNext()) { Element artifactElement = (Element) it.next(); String uri = getChildText("uri", artifactElement, namespace, true); String pts = getChildText("productType", artifactElement, namespace, false); ProductType productType = null; if (pts != null) { productType = ProductType.toValue(pts); } else { productType = ProductType.SCIENCE; log.warn("assigning default Artifact.productType = " + productType + " for " + uri); } String rts = getChildText("releaseType", artifactElement, namespace, false); ReleaseType releaseType = null; if (rts != null) { releaseType = ReleaseType.toValue(rts); } else { releaseType = ReleaseType.DATA; log.warn("assigning default Artifact.releaseType = " + releaseType + " for " + uri); } Artifact artifact; try { artifact = new Artifact(new URI(uri), productType, releaseType); } catch (URISyntaxException e) { String error = "Unable to parse uri " + uri + " in to a URI in element " + artifactElement.getName() + " because " + e.getMessage(); throw new ObservationParsingException(error); } artifact.contentType = getChildText("contentType", artifactElement, namespace, false); artifact.contentLength = getChildTextAsLong("contentLength", artifactElement, namespace, false); String contentChecksumStr = getChildText("contentChecksum", artifactElement, namespace, false); if (contentChecksumStr != null) { try { artifact.contentChecksum = new URI(contentChecksumStr); } catch (URISyntaxException e) { String error = "Unable to parse contentChecksum " + uri + " into a URI in element " + artifactElement.getName() + " because " + e.getMessage(); throw new ObservationParsingException(error, e); } } addParts(artifact.getParts(), artifactElement, namespace, rc); assignEntityAttributes(artifactElement, artifact, rc); boolean added = artifacts.add(artifact); if (!added) { throw new IllegalArgumentException("Artifact.uri = " + uri + " is not unique"); } } }
From source file:ca.nrc.cadc.caom2.xml.ObservationReader.java
License:Open Source License
/** * Creates Part's from the part elements found in the parts element, and * adds them to the given Set of Part's. * /*from www . ja va 2 s . c o m*/ * @param parts * the Set of Part's from the Artifact. * @param parent * the parent Element. * @param namespace * of the document. * @param rc * @throws ObservationParsingException */ protected void addParts(Set<Part> parts, Element parent, Namespace namespace, ReadContext rc) throws ObservationParsingException { Element element = getChildElement("parts", parent, namespace, false); if (element == null || element.getContentSize() == 0) { return; } List partElements = getChildrenElements("part", element, namespace, false); Iterator it = partElements.iterator(); while (it.hasNext()) { Element partElement = (Element) it.next(); String partName = getChildText("name", partElement, namespace, true); Part part = new Part(partName); String productType = getChildText("productType", partElement, namespace, false); if (productType != null) { part.productType = ProductType.toValue(productType); } addChunks(part.getChunks(), partElement, namespace, rc); assignEntityAttributes(partElement, part, rc); boolean added = parts.add(part); if (!added) { throw new IllegalArgumentException("Part.name = " + partName + " is not unique"); } } }
From source file:ca.nrc.cadc.caom2.xml.ObservationReader.java
License:Open Source License
/** * Creates Chunk's from the chunk elements found in the chunks element, and * adds them to the given Set of Chunk's. * //from ww w . j av a 2s. c o m * @param chunks * the Set of Chunk's from the Part. * @param parent * the parent Element. * @param namespace * of the document. * @param rc * @throws ObservationParsingException */ protected void addChunks(Set<Chunk> chunks, Element parent, Namespace namespace, ReadContext rc) throws ObservationParsingException { Element element = getChildElement("chunks", parent, namespace, false); if (element == null || element.getContentSize() == 0) { return; } List chunkElements = getChildrenElements("chunk", element, namespace, false); Iterator it = chunkElements.iterator(); while (it.hasNext()) { Element chunkElement = (Element) it.next(); Chunk chunk = new Chunk(); String productType = getChildText("productType", chunkElement, namespace, false); if (productType != null) { chunk.productType = ProductType.toValue(productType); } chunk.naxis = getChildTextAsInteger("naxis", chunkElement, namespace, false); chunk.observableAxis = getChildTextAsInteger("observableAxis", chunkElement, namespace, false); chunk.positionAxis1 = getChildTextAsInteger("positionAxis1", chunkElement, namespace, false); chunk.positionAxis2 = getChildTextAsInteger("positionAxis2", chunkElement, namespace, false); chunk.energyAxis = getChildTextAsInteger("energyAxis", chunkElement, namespace, false); chunk.timeAxis = getChildTextAsInteger("timeAxis", chunkElement, namespace, false); chunk.polarizationAxis = getChildTextAsInteger("polarizationAxis", chunkElement, namespace, false); chunk.observable = getObservableAxis("observable", chunkElement, namespace, false, rc); chunk.position = getSpatialWCS("position", chunkElement, namespace, false, rc); chunk.energy = getSpectralWCS("energy", chunkElement, namespace, false, rc); chunk.time = getTemporalWCS("time", chunkElement, namespace, false, rc); chunk.polarization = getPolarizationWCS("polarization", chunkElement, namespace, false, rc); assignEntityAttributes(chunkElement, chunk, rc); chunks.add(chunk); } }
From source file:ca.nrc.cadc.caom2.xml.ObservationReader.java
License:Open Source License
/** * Build an ObservableAxis from a JDOM representation of an observable * element./*from w w w . jav a2 s . co m*/ * * @param name * the name of the Element. * @param parent * the parent Element. * @param namespace * of the document. * @param required * is the element expected to be found. * @param rc * @return an ObservableAxis, or null if the document doesn't contain an * observable element. * @throws ObservationParsingException */ protected ObservableAxis getObservableAxis(String name, Element parent, Namespace namespace, boolean required, ReadContext rc) throws ObservationParsingException { Element element = getChildElement(name, parent, namespace, false); if (element == null || element.getContentSize() == 0) { return null; } Slice dependent = getSlice("dependent", element, namespace, true); ObservableAxis observable = new ObservableAxis(dependent); observable.independent = getSlice("independent", element, namespace, false); return observable; }
From source file:ca.nrc.cadc.caom2.xml.ObservationReader.java
License:Open Source License
/** * Build an SpatialWCS from a JDOM representation of an position element. * /* w w w. ja v a 2s. c o m*/ * @param name * the name of the Element. * @param parent * the parent Element. * @param namespace * of the document. * @param required * is the element expected to be found. * @param rc * @return an SpatialWCS, or null if the document doesn't contain an * position element. * @throws ObservationParsingException */ protected SpatialWCS getSpatialWCS(String name, Element parent, Namespace namespace, boolean required, ReadContext rc) throws ObservationParsingException { Element element = getChildElement(name, parent, namespace, required); if (element == null || element.getContentSize() == 0) { return null; } CoordAxis2D axis = getCoordAxis2D("axis", element, namespace, true); SpatialWCS position = new SpatialWCS(axis); position.coordsys = getChildText("coordsys", element, namespace, false); position.equinox = getChildTextAsDouble("equinox", element, namespace, false); position.resolution = getChildTextAsDouble("resolution", element, namespace, false); return position; }
From source file:ca.nrc.cadc.caom2.xml.ObservationReader.java
License:Open Source License
/** * Build an SpectralWCS from a JDOM representation of an energy element. * /*from ww w . ja v a 2 s.c o m*/ * @param name * the name of the Element. * @param parent * the parent Element. * @param namespace * of the document. * @param required * is the element expected to be found. * @param rc * @return an SpectralWCS, or null if the document doesn't contain an energy * element. * @throws ObservationParsingException */ protected SpectralWCS getSpectralWCS(String name, Element parent, Namespace namespace, boolean required, ReadContext rc) throws ObservationParsingException { Element element = getChildElement(name, parent, namespace, false); if (element == null || element.getContentSize() == 0) { return null; } CoordAxis1D axis = getCoordAxis1D("axis", element, namespace, true); String specsys = getChildText("specsys", element, namespace, true); SpectralWCS energy = new SpectralWCS(axis, specsys); energy.ssysobs = getChildText("ssysobs", element, namespace, false); energy.ssyssrc = getChildText("ssyssrc", element, namespace, false); energy.restfrq = getChildTextAsDouble("restfrq", element, namespace, false); energy.restwav = getChildTextAsDouble("restwav", element, namespace, false); energy.velosys = getChildTextAsDouble("velosys", element, namespace, false); energy.zsource = getChildTextAsDouble("zsource", element, namespace, false); energy.velang = getChildTextAsDouble("velang", element, namespace, false); energy.bandpassName = getChildText("bandpassName", element, namespace, false); energy.resolvingPower = getChildTextAsDouble("resolvingPower", element, namespace, false); energy.transition = getTransition(element, namespace, rc); return energy; }
From source file:ca.nrc.cadc.caom2.xml.ObservationReader.java
License:Open Source License
/** * Build an TemporalWCS from a JDOM representation of an time element. * // w ww . ja v a 2s.c o m * @param name * the name of the Element. * @param parent * the parent Element. * @param namespace * of the document. * @param required * is the element expected to be found. * @param rc * @return an TemporalWCS, or null if the document doesn't contain an time * element. * @throws ObservationParsingException */ protected TemporalWCS getTemporalWCS(String name, Element parent, Namespace namespace, boolean required, ReadContext rc) throws ObservationParsingException { Element element = getChildElement(name, parent, namespace, false); if (element == null || element.getContentSize() == 0) { return null; } CoordAxis1D axis = getCoordAxis1D("axis", element, namespace, true); TemporalWCS time = new TemporalWCS(axis); time.timesys = getChildText("timesys", element, namespace, false); time.trefpos = getChildText("trefpos", element, namespace, false); time.mjdref = getChildTextAsDouble("mjdref", element, namespace, false); time.exposure = getChildTextAsDouble("exposure", element, namespace, false); time.resolution = getChildTextAsDouble("resolution", element, namespace, false); return time; }