/* * This file is part of PetaScope. * * PetaScope is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 3 of * the License, or (at your option) any later version. * * PetaScope is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with PetaScope. If not, see . * * For more information please see * or contact Peter Baumann via . * * Copyright 2009 Jacobs University Bremen, Peter Baumann. */ package petascope.wcs2.server.ops; //~--- non-JDK imports -------------------------------------------------------- import java.util.HashSet; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import petascope.ConfigManager; import petascope.wcps.server.core.CellDomainElement; import petascope.wcps.server.core.DbMetadataSource; import petascope.wcps.server.core.DomainElement; import petascope.wcps.server.core.Metadata; import petascope.wcps.server.core.RangeElement; import petascope.wcs.server.exceptions.WCSException; //~--- JDK imports ------------------------------------------------------------ import java.util.Iterator; import java.util.List; import java.util.Set; import petascope.wcps.server.core.SDU; import petascope.wcs.server.exceptions.InvalidParameterValueException; import petascope.wcs.server.exceptions.InvalidServiceConfigurationException; import petascope.wcs.server.exceptions.NoApplicableCodeException; /** * Describe Coverage operation for WCS 2.0 * * @author Andrei Aiordachioaie */ public class DescribeCoverage implements WcsOperation { public static String DATATYPE_URN_PREFIX = "urn:ogc:def:dataType:OGC:1.1:"; private static Logger LOG = LoggerFactory.getLogger(DescribeCoverage.class); /* Template XMLs for response types */ private String DescribeCoverageResponse; /* Other useful stuff */ private String coverageDescriptionTemplate; private String listOfFormats; private String low, high, axisLabels; private DbMetadataSource meta; private String rangeComponentTemplate; private String rangeComponents, gridDimension, gridId; public DescribeCoverage(DbMetadataSource metadata) throws InvalidServiceConfigurationException { meta = metadata; DescribeCoverageResponse = ConfigManager.WCS2_DESCRIBE_COVERAGE_TEMPLATE; if (DescribeCoverageResponse == null) { throw new InvalidServiceConfigurationException("Could not find template file."); } listOfFormats = "application/xml"; /* Find the CoverageDescription template string */ String starttag = " it = cov.getDomainIterator(); Iterator it2 = cov.getCellDomainIterator(); low = ""; high = ""; axisLabels = ""; while (it.hasNext() && it2.hasNext()) { DomainElement dom = it.next(); CellDomainElement cell = it2.next(); axisLabels += dom.getName() + " "; low += cell.getLo() + " "; high += cell.getHi() + " "; } // Build the range components data structure Iterator it3 = cov.getRangeIterator(); Iterator nilIterator = cov.getNullSetIterator(); rangeComponents = ""; int i = -1; while (it3.hasNext()) { String component = rangeComponentTemplate; RangeElement range = it3.next(); i++; String rangeId = "range-" + cov.getCoverageId() + "-" + range.getName(); component = component.replaceAll("\\{rangeFieldId\\}", rangeId); component = component.replaceAll("\\{fieldName\\}", range.getName()); component = component.replaceAll("\\{datatype\\}", DATATYPE_URN_PREFIX + range.getType()); // Compute the null values for this range field Set nullVals = new HashSet(); Iterator it4 = cov.getNullSetIterator(); while (it4.hasNext()) { List nilVal = SDU.str2string(it4.next()); nullVals.add(nilVal.get(i)); } StringBuffer nullValsString = new StringBuffer(); it4 = nullVals.iterator(); while (it4.hasNext()) { nullValsString.append(" " + it4.next()); } component = component.replaceAll("\\{nilValues\\}", nullValsString.toString().substring(1)); // And add this range field to the range structure rangeComponents += component; } desc = coverageDescriptionTemplate.replaceAll("\\{coverageId\\}", coverageId); gridId = "grid" + coverageId; desc = desc.replaceAll("\\{gridId\\}", gridId); gridDimension = String.valueOf(cov.getDimension()); desc = desc.replaceAll("\\{gridDimension\\}", gridDimension); desc = desc.replaceAll("\\{low\\}", low); desc = desc.replaceAll("\\{high\\}", high); desc = desc.replaceAll("\\{axisLabels\\}", axisLabels); desc = desc.replaceAll("\\{rangeFields\\}", rangeComponents); desc = desc.replaceAll("\\{rangeStructureId\\}", "rangeStructure-" + coverageId); desc = desc.replaceAll("\\{supportedFormats\\}", listOfFormats); listOfCoverageDescriptions += desc; } else { throw new InvalidParameterValueException("gml:id"); } } output = DescribeCoverageResponse.replaceAll("\\{listOfCoverageDescriptions\\}", listOfCoverageDescriptions); output = output.replaceAll("\\{wcsSchemaUrl\\}", ConfigManager.WCS2_SCHEMA_URL); return output; } }