/** * Writes the element if and only if the content is not null and not empty * * @param elementName * @param content */ protected void elementIfNotEmpty(String elementName, String content) { if (content != null && !"".equals(content.trim())) element(elementName, content); } }
/** * Writes the element if and only if the content is not null and not * empty * * @param elementName * @param content */ private void elementIfNotEmpty(String elementName, String content) { if (content != null && !"".equals(content.trim())) element(elementName, content); } }
private void handleKeywords(List kwords) { start("ows:Keywords"); if (kwords != null) { for (Iterator it = kwords.iterator(); it.hasNext();) { element("ows:Keyword", it.next().toString()); } } end("ows:Keywords"); }
protected void handleRange(CoverageInfo ci) { start("wcs:Range"); // at the moment we only handle single field coverages start("wcs:Field"); List<CoverageDimensionInfo> dimensions = ci.getDimensions(); element("wcs:Identifier", "contents"); // the output domain of the field start("wcs:Definition"); NumberRange range = getCoverageRange(dimensions); if (range == null || range.isEmpty()) { element("ows:AnyValue", ""); } else { start("ows:AllowedValues"); start("ows:Range"); element("ows:MinimumValue", Double.toString(range.getMinimum())); element("ows:MaximumValue", Double.toString(range.getMaximum())); end("ows:Range"); end("ows:AllowedValues"); } end("wcs:Definition"); handleNullValues(dimensions); handleInterpolationMethods(ci); handleAxis(ci); end("wcs:Field"); end("wcs:Range"); }
private void handleSupportedFormats(CoverageInfo ci) throws Exception { // gather all the formats for this coverage Set<String> formats = new HashSet<String>(); for (Iterator it = ci.getSupportedFormats().iterator(); it.hasNext();) { String format = (String) it.next(); // wcs 1.1 requires mime types, not format names try { CoverageResponseDelegate delegate = CoverageResponseDelegateFactory .encoderFor(format); String formatMime = delegate.getMimeFormatFor(format); if(formatMime != null) formats.add(formatMime); } catch(Exception e) { // no problem, we just want to avoid people writing HALLABALOOLA in the // supported formats section of the coverage config and then break the // describe response } } // sort them List<String> sortedFormats = new ArrayList<String>(formats); Collections.sort(sortedFormats); for (String format : sortedFormats) { element("wcs:SupportedFormat", format); } }
private void handleBoundingBox(GeneralEnvelope envelope, boolean wgsLonLat) throws Exception { final AttributesImpl attributes = new AttributesImpl(); final CoordinateReferenceSystem crs = envelope.getCoordinateReferenceSystem(); GeneralEnvelope encodedEnvelope = envelope; if (wgsLonLat) { attributes.addAttribute("", "crs", "crs", "", "urn:ogc:def:crs:OGC:1.3:CRS84"); } else { String urnIdentifier = urnIdentifier(crs); CoordinateReferenceSystem latlonCrs = CRS.decode(urnIdentifier); encodedEnvelope = CRS.transform(CRS.findMathTransform(crs, latlonCrs, true), envelope); attributes.addAttribute("", "crs", "crs", "", urnIdentifier); } attributes.addAttribute("", "dimensions", "dimensions", "", Integer.toString(crs .getCoordinateSystem().getDimension())); start("ows:BoundingBox", attributes); element("ows:LowerCorner", new StringBuffer(Double.toString(encodedEnvelope .getLowerCorner().getOrdinate(0))).append(" ").append( encodedEnvelope.getLowerCorner().getOrdinate(1)).toString()); element("ows:UpperCorner", new StringBuffer(Double.toString(encodedEnvelope .getUpperCorner().getOrdinate(0))).append(" ").append( encodedEnvelope.getUpperCorner().getOrdinate(1)).toString()); end("ows:BoundingBox"); }
protected void handleSupportedFormats(CoverageInfo ci) throws Exception { // gather all the formats for this coverage Set<String> formats = new LinkedHashSet<String>(); for (Iterator it = ci.getSupportedFormats().iterator(); it.hasNext(); ) { String format = (String) it.next(); // wcs 1.1 requires mime types, not format names try { CoverageResponseDelegate delegate = responseFactory.encoderFor(format); String formatMime = delegate.getMimeType(format); if (formatMime != null) formats.add(formatMime); } catch (Exception e) { // no problem, we just want to avoid people writing HALLABALOOLA in the // supported formats section of the coverage config and then break the // describe response } } // sort them for (String format : formats) { element("wcs:SupportedFormat", format); } }
protected void handleMetadataLink(MetadataLinkInfo mdl, String linkType) { AttributesImpl attributes = new AttributesImpl(); if ((mdl.getAbout() != null) && (mdl.getAbout() != "")) { attributes.addAttribute("", "about", "about", "", mdl.getAbout()); } if ((mdl.getMetadataType() != null) && (mdl.getMetadataType() != "")) { attributes.addAttribute( "", "metadataType", "metadataType", "", mdl.getMetadataType()); } if ((linkType != null) && (linkType != "")) { attributes.addAttribute("", "xlink:type", "xlink:type", "", linkType); } if ((mdl.getContent() != null) && (mdl.getContent() != "")) { attributes.addAttribute( "", "xlink:href", "xlink:href", "", ResponseUtils.proxifyMetadataLink(mdl, request.getBaseUrl())); } if (attributes.getLength() > 0) { element("ows:Metadata", null, attributes); } }
protected void handleNullValues(List<CoverageDimensionInfo> dimensions) { for (CoverageDimensionInfo cd : dimensions) { List<Double> nulls = cd.getNullValues(); if (nulls == null) return; if (nulls.size() == 1) { element("wcs:NullValue", nulls.get(0).toString()); } else if (nulls.size() >= 1) { // the new specification allows only for a list of values, // Can we assume min and max are two integer numbers and // make up a list out of them? For the moment, just fail throw new IllegalArgumentException( "Cannot encode a range of null values, " + "only single values are handled"); } } }
private void handleNullValues(CoverageDimension[] dimensions) { for (int i = 0; i < dimensions.length; i++) { CoverageDimension cd = dimensions[i]; Double[] nulls = cd.getNullValues(); if(nulls == null) return; if (nulls.length == 1) { element("wcs:NullValue", nulls[0].toString()); } else if (nulls.length >= 1) { // the new specification allows only for a list of values, // Can we assume min and max are two integer numbers and // make up a list out of them? For the moment, just fail throw new IllegalArgumentException("Cannot encode a range of null values, " + "only single values are handled"); } } }
private void handleMetadataLink(MetaDataLink mdl, String linkType) { if (mdl != null) { AttributesImpl attributes = new AttributesImpl(); if ((mdl.getAbout() != null) && (mdl.getAbout() != "")) { attributes.addAttribute("", "about", "about", "", mdl.getAbout()); } if ((mdl.getMetadataType() != null) && (mdl.getMetadataType() != "")) { attributes.addAttribute("", "xlink:type", "xlink:type", "", linkType); } if (attributes.getLength() > 0) { element("ows:Metadata", null, attributes); } } }
protected void handleCoverageDescription(CoverageInfo ci) throws Exception { start("wcs:CoverageDescription"); element("ows:Title", ci.getTitle()); element("ows:Abstract", ci.getDescription()); handleKeywords(ci.getKeywords()); element("wcs:Identifier", ci.getStore().getWorkspace().getName() + ":" + ci.getName()); handleMetadataLinks(ci.getMetadataLinks(), "simple"); handleDomain(ci); handleRange(ci); handleSupportedCRSs(ci); handleSupportedFormats(ci); end("wcs:CoverageDescription"); }
protected void handleSupportedCRSs(CoverageInfo ci) throws Exception { Set supportedCRSs = new LinkedHashSet(); if (ci.getRequestSRS() != null) supportedCRSs.addAll(ci.getRequestSRS()); if (ci.getResponseSRS() != null) supportedCRSs.addAll(ci.getResponseSRS()); for (Iterator it = supportedCRSs.iterator(); it.hasNext(); ) { String crsName = (String) it.next(); CoordinateReferenceSystem crs = CRS.decode(crsName); element("wcs:SupportedCRS", urnIdentifier(crs)); element("wcs:SupportedCRS", crsName); } }
protected void handleInterpolationMethods(CoverageInfo ci) { start("wcs:InterpolationMethods"); for (Iterator it = ci.getInterpolationMethods().iterator(); it.hasNext(); ) { String method = (String) it.next(); String converted = METHOD_NAME_MAP.get(method); if (converted != null) element("wcs:InterpolationMethod", converted); } elementIfNotEmpty("wcs:Default", ci.getDefaultInterpolationMethod()); end("wcs:InterpolationMethods"); }
protected void handleAxis(CoverageInfo ci) { final AttributesImpl attributes = new AttributesImpl(); attributes.addAttribute("", "identifier", "identifier", "", "Bands"); start("wcs:Axis", attributes); start("wcs:AvailableKeys"); List<CoverageDimensionInfo> dimensions = ci.getDimensions(); for (CoverageDimensionInfo cd : dimensions) { element("wcs:Key", cd.getName().replace(' ', '_')); } end("wcs:AvailableKeys"); end("wcs:Axis"); }
private void handleSupportedCRSs(CoverageInfo ci) throws Exception { Set supportedCRSs = new LinkedHashSet(); if (ci.getRequestCRSs() != null) supportedCRSs.addAll(ci.getRequestCRSs()); if (ci.getResponseCRSs() != null) supportedCRSs.addAll(ci.getResponseCRSs()); for (Iterator it = supportedCRSs.iterator(); it.hasNext();) { String crsName = (String) it.next(); CoordinateReferenceSystem crs = CRS.decode(crsName); element("wcs:SupportedCRS", urnIdentifier(crs)); element("wcs:SupportedCRS", crsName); } }
void handleCoverageDescription(CoverageInfo ci) throws Exception { start("wcs:CoverageDescription"); element("ows:Title", ci.getLabel()); element("ows:Abstract", ci.getDescription()); handleKeywords(ci.getKeywords()); element("wcs:Identifier", ci.getName()); handleMetadataLink(ci.getMetadataLink(), "simple"); handleDomain(ci); handleRange(ci); handleSupportedCRSs(ci); handleSupportedFormats(ci); end("wcs:CoverageDescription"); }
private void handleAxis(CoverageInfo ci) { final AttributesImpl attributes = new AttributesImpl(); attributes.addAttribute("", "identifier", "identifier", "", "Bands"); start("wcs:Axis", attributes); start("wcs:AvailableKeys"); CoverageDimension[] dimensions = ci.getDimensions(); for (int i = 0; i < dimensions.length; i++) { element("wcs:Key", dimensions[i].getName().replace(' ', '_')); } end("wcs:AvailableKeys"); end("wcs:Axis"); }
protected void handleKeywords(List kwords) { start("ows:Keywords"); if (kwords != null) { for (Iterator it = kwords.iterator(); it.hasNext(); ) { element("ows:Keyword", it.next().toString()); } } end("ows:Keywords"); }
private void handleInterpolationMethods(CoverageInfo ci) { start("wcs:InterpolationMethods"); for (Iterator it = ci.getInterpolationMethods().iterator(); it.hasNext();) { String method = (String) it.next(); String converted = METHOD_NAME_MAP.get(method); if (converted != null) element("wcs:InterpolationMethod", converted); } elementIfNotEmpty("wcs:Default", ci.getDefaultInterpolationMethod()); end("wcs:InterpolationMethods"); }