summaryrefslogtreecommitdiffstats
path: root/petascope/src/petascope/wcs2/server
diff options
context:
space:
mode:
Diffstat (limited to 'petascope/src/petascope/wcs2/server')
-rw-r--r--petascope/src/petascope/wcs2/server/Wcs2Server.java120
-rw-r--r--petascope/src/petascope/wcs2/server/ops/DescribeCoverage.java204
-rw-r--r--petascope/src/petascope/wcs2/server/ops/GetCapabilities.java85
-rw-r--r--petascope/src/petascope/wcs2/server/ops/GetCoverage.java529
-rw-r--r--petascope/src/petascope/wcs2/server/ops/WcsOperation.java36
-rw-r--r--petascope/src/petascope/wcs2/server/templates/DescribeCoverageTemplate.xml38
-rw-r--r--petascope/src/petascope/wcs2/server/templates/GetCapabilitiesTemplate.xml92
-rw-r--r--petascope/src/petascope/wcs2/server/templates/GetCoverageTemplate.xml38
-rw-r--r--petascope/src/petascope/wcs2/server/templates/WcsNamespaceContext.java59
9 files changed, 0 insertions, 1201 deletions
diff --git a/petascope/src/petascope/wcs2/server/Wcs2Server.java b/petascope/src/petascope/wcs2/server/Wcs2Server.java
deleted file mode 100644
index cb5f6f9..0000000
--- a/petascope/src/petascope/wcs2/server/Wcs2Server.java
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * This file is part of rasdaman community.
- *
- * Rasdaman community is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Rasdaman community 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with rasdaman community. If not, see <http://www.gnu.org/licenses/>.
- *
- * Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
- rasdaman GmbH.
- *
- * For more information please see <http://www.rasdaman.org>
- * or contact Peter Baumann via <baumann@rasdaman.com>.
- */
-package petascope.wcs2.server;
-
-//~--- non-JDK imports --------------------------------------------------------
-import javax.servlet.ServletException;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import petascope.ConfigManager;
-
-import petascope.wcps.server.core.DbMetadataSource;
-
-import petascope.wcs.server.exceptions.WCSException;
-
-import petascope.wcs2.server.ops.DescribeCoverage;
-import petascope.wcs2.server.ops.GetCapabilities;
-import petascope.wcs2.server.ops.GetCoverage;
-
-//~--- JDK imports ------------------------------------------------------------
-/**
- * The Web Coverage Service (WcsServer)
- * This class provides methods for each of the WCS operations:
- * - GetCapabilities
- * - DescribeCoverage
- * - GetCoverage
- *
- * @author Andrei Aiordachioaie
- */
-public class Wcs2Server {
-
- private static Logger LOG = LoggerFactory.getLogger(Wcs2Server.class);
-
- /* The Operations to delegate to */
- private GetCapabilities capa;
- private DescribeCoverage desc;
- private GetCoverage getcov;
-
- /* Globals */
- private DbMetadataSource meta;
-
- /**
- * constructor
- * @param settingsPath path to the "settings.properties" file
- */
- public Wcs2Server(String settingsPath, DbMetadataSource source) throws ServletException {
- ConfigManager.getInstance(settingsPath, null);
- meta = source;
-
- try {
- capa = new GetCapabilities(meta);
- desc = new DescribeCoverage(meta);
- getcov = new GetCoverage(meta);
- } catch (Exception e) {
- LOG.error("Could not init WCS 2.0");
-
- throw new RuntimeException("Could not initialize WCS 2.0", e);
- }
- }
-
- /**
- * WcsServer GetCapabilities operation
- */
- public String GetCapabilities(String stringXml) throws WCSException {
- LOG.trace("Received input:\n{}", stringXml);
- LOG.info("Executing operation GetCapabilities...");
- String result = capa.execute(stringXml);
-
- LOG.info("GetCapabilities finished");
-
- return result;
- }
-
- /**
- * WcsServer DescribeCoverage operation
- */
- public String DescribeCoverage(String stringXml) throws WCSException {
- LOG.trace("Received input:\n{}", stringXml);
- LOG.info("Executing operation DescribeCoverage...");
- String result = desc.execute(stringXml);
-
- LOG.info("DescribeCoverage finished");
-
- return result;
- }
-
- /**
- * WcsServer GetCoverage operation
- */
- public String GetCoverage(String stringXml) throws WCSException {
- LOG.trace("Received input:\n{}", stringXml);
- LOG.info("Executing operation GetCoverage...");
- String result = getcov.execute(stringXml);
-
- LOG.info("GetCoverage finished");
-
- return result;
- }
-}
diff --git a/petascope/src/petascope/wcs2/server/ops/DescribeCoverage.java b/petascope/src/petascope/wcs2/server/ops/DescribeCoverage.java
deleted file mode 100644
index 6f4e752..0000000
--- a/petascope/src/petascope/wcs2/server/ops/DescribeCoverage.java
+++ /dev/null
@@ -1,204 +0,0 @@
-/*
- * This file is part of rasdaman community.
- *
- * Rasdaman community is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Rasdaman community 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with rasdaman community. If not, see <http://www.gnu.org/licenses/>.
- *
- * Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
- rasdaman GmbH.
- *
- * For more information please see <http://www.rasdaman.org>
- * or contact Peter Baumann via <baumann@rasdaman.com>.
- */
-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 = "<wcs:CoverageDescription ", endtag = "</wcs:CoverageDescription>";
- int start = DescribeCoverageResponse.indexOf(starttag);
- int end = DescribeCoverageResponse.indexOf(endtag);
-
- coverageDescriptionTemplate = DescribeCoverageResponse.substring(start, end + endtag.length());
- String newResponse = DescribeCoverageResponse.substring(0, start - 1) + DescribeCoverageResponse.substring(end + endtag.length());
-
- DescribeCoverageResponse = newResponse;
-
- /* Find the RangeComponent template string */
- starttag = "<gmlwcs:rangeField";
- endtag = "</gmlwcs:rangeField>";
- start = coverageDescriptionTemplate.indexOf(starttag);
- end = coverageDescriptionTemplate.indexOf(endtag);
- rangeComponentTemplate = coverageDescriptionTemplate.substring(start, end + endtag.length());
- String newTemplate = coverageDescriptionTemplate.substring(0, start - 1) + coverageDescriptionTemplate.substring(end + endtag.length());
-
- coverageDescriptionTemplate = newTemplate;
- }
-
- @Override
- public String execute(String stringXml) throws WCSException {
- String output;
- String desc = "";
-
- String listOfCoverageDescriptions = "";
- int start, end;
-
- start = stringXml.indexOf("gml:id=\"");
- while (start != -1) {
- end = stringXml.substring(start + 8).indexOf("\"");
- String coverageId = stringXml.substring(start + 8, start + 8 + end);
-
- stringXml = stringXml.substring(start + 8 + end + 1);
- start = stringXml.indexOf("gml:id=\"");
-
- // Describe "coverageId"
- if (meta.existsCoverageName(coverageId)) {
- Metadata cov = null;
-
- // Read in coverage metadata
- try {
- cov = meta.read(coverageId);
- } catch (Exception e) {
- e.printStackTrace();
-
- throw new NoApplicableCodeException("Metadata for coverage '" + coverageId + "' is not valid.");
- }
-
- // Analyze the grid components and their values
- Iterator<DomainElement> it = cov.getDomainIterator();
- Iterator<CellDomainElement> 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<RangeElement> it3 = cov.getRangeIterator();
- Iterator<String> 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<String> nullVals = new HashSet<String>();
- Iterator<String> it4 = cov.getNullSetIterator();
- while (it4.hasNext()) {
- List<String> 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;
- }
-}
diff --git a/petascope/src/petascope/wcs2/server/ops/GetCapabilities.java b/petascope/src/petascope/wcs2/server/ops/GetCapabilities.java
deleted file mode 100644
index b64d3f2..0000000
--- a/petascope/src/petascope/wcs2/server/ops/GetCapabilities.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * This file is part of rasdaman community.
- *
- * Rasdaman community is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Rasdaman community 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with rasdaman community. If not, see <http://www.gnu.org/licenses/>.
- *
- * Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
- rasdaman GmbH.
- *
- * For more information please see <http://www.rasdaman.org>
- * or contact Peter Baumann via <baumann@rasdaman.com>.
- */
-package petascope.wcs2.server.ops;
-
-//~--- non-JDK imports --------------------------------------------------------
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import petascope.ConfigManager;
-
-import petascope.wcps.server.core.DbMetadataSource;
-import petascope.wcps.server.exceptions.ResourceException;
-
-//~--- JDK imports ------------------------------------------------------------
-
-import java.util.Iterator;
-import petascope.wcs.server.exceptions.InvalidServiceConfigurationException;
-
-/**
- * GetCapabilities operation for The Web Coverage Service 2.0
- *
- * @author Andrei Aiordachioaie
- */
-public class GetCapabilities implements WcsOperation {
-
- private static Logger LOG = LoggerFactory.getLogger(GetCapabilities.class);
- /* Template XMLs for response types */
- private String GetCapabilitiesResponse;
- private DbMetadataSource meta;
- /* Other useful vars */
- private String xmlListOfCoverages;
-
- public GetCapabilities(DbMetadataSource metadata) throws InvalidServiceConfigurationException {
- meta = metadata;
-
- GetCapabilitiesResponse = ConfigManager.WCS2_GET_CAPABILITIES_TEMPLATE;
- if (GetCapabilitiesResponse == null) {
- throw new InvalidServiceConfigurationException("Could not find template file.");
- }
- }
-
- @Override
- public String execute(String input) {
- String output;
-
- // Create the output by replacing placeholders
- output = GetCapabilitiesResponse.replaceAll("\\{URL\\}",
- ConfigManager.PETASCOPE_SERVLET_URL);
- Iterator<String> it;
-
- try {
- it = meta.coverages().iterator();
- xmlListOfCoverages = "";
- while (it.hasNext()) {
- xmlListOfCoverages += "<wcs:id gml:id=\"" + it.next() + "\"/>";
- }
- } catch (ResourceException ex) {
- ex.printStackTrace();
- }
- output = output.replaceAll("\\{Coverages\\}", xmlListOfCoverages);
- output = output.replaceAll("\\{wcsSchemaUrl\\}", ConfigManager.WCS2_SCHEMA_URL);
-
- return output;
- }
-}
diff --git a/petascope/src/petascope/wcs2/server/ops/GetCoverage.java b/petascope/src/petascope/wcs2/server/ops/GetCoverage.java
deleted file mode 100644
index a6ddcff..0000000
--- a/petascope/src/petascope/wcs2/server/ops/GetCoverage.java
+++ /dev/null
@@ -1,529 +0,0 @@
-/*
- * This file is part of rasdaman community.
- *
- * Rasdaman community is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Rasdaman community 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with rasdaman community. If not, see <http://www.gnu.org/licenses/>.
- *
- * Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
- rasdaman GmbH.
- *
- * For more information please see <http://www.rasdaman.org>
- * or contact Peter Baumann via <baumann@rasdaman.com>.
- */
-package petascope.wcs2.server.ops;
-
-//~--- non-JDK imports --------------------------------------------------------
-import org.apache.commons.io.IOUtils;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.w3c.dom.Document;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-import org.xml.sax.SAXException;
-
-import petascope.ConfigManager;
-
-import petascope.wcps.server.core.DbMetadataSource;
-import petascope.wcps.server.core.Metadata;
-
-import petascope.wcs.server.exceptions.WCSException;
-
-//~--- JDK imports ------------------------------------------------------------
-
-import java.io.IOException;
-
-import java.math.BigInteger;
-import java.util.HashSet;
-import java.util.Iterator;
-
-import java.util.List;
-import java.util.Set;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.xpath.XPath;
-import javax.xml.xpath.XPathConstants;
-import javax.xml.xpath.XPathExpressionException;
-import javax.xml.xpath.XPathFactory;
-import org.odmg.DBag;
-import org.odmg.Database;
-import org.odmg.Implementation;
-import org.odmg.ODMGException;
-import org.odmg.OQLQuery;
-import org.odmg.QueryException;
-import org.odmg.Transaction;
-import rasj.RasGMArray;
-import rasj.RasImplementation;
-import petascope.wcps.server.core.CellDomainElement;
-import petascope.wcps.server.core.DomainElement;
-import petascope.wcps.server.core.RangeElement;
-import petascope.wcps.server.core.SDU;
-import petascope.wcs.server.exceptions.InputOutputException;
-import petascope.wcs.server.exceptions.InternalComponentException;
-import petascope.wcs.server.exceptions.InvalidParameterValueException;
-import petascope.wcs.server.exceptions.InvalidServiceConfigurationException;
-import petascope.wcs.server.exceptions.NoApplicableCodeException;
-import petascope.wcs.server.exceptions.WcsRuntimeException;
-import petascope.wcs.server.exceptions.XmlNotValidException;
-import petascope.wcs2.server.templates.WcsNamespaceContext;
-
-/**
- * Get Coverage operation for WCS 2.0
- *
- * @author Andrei Aiordachioaie
- */
-public class GetCoverage implements WcsOperation {
-
- private static Logger LOG = LoggerFactory.getLogger(GetCoverage.class);
- private DocumentBuilder builder = null;
- private XPathFactory xpathFactory = XPathFactory.newInstance();
- /* Template XMLs for response types */
- private String GetCoverageResponse;
- private String rangeComponentTemplate;
- /* Xml request */
- private Document doc;
- /* for Metadata */
- private DbMetadataSource meta;
- /* The new coverage domain */
- private String lowPoint, highPoint, newAxesLabels;
-
- public GetCoverage(DbMetadataSource metadata) throws WCSException {
- meta = metadata;
- GetCoverageResponse = ConfigManager.WCS2_GET_COVERAGE_TEMPLATE;
- if (GetCoverageResponse == null) {
- throw new InvalidServiceConfigurationException("Could not find template file.");
- }
-
- /* Find the RangeField template string */
- String starttag = "<gmlwcs:rangeField", endtag = "</gmlwcs:rangeField>";
- int start = GetCoverageResponse.indexOf(starttag);
- int end = GetCoverageResponse.indexOf(endtag);
- rangeComponentTemplate = GetCoverageResponse.substring(start, end + endtag.length());
- String newTemplate = GetCoverageResponse.substring(0, start - 1) + GetCoverageResponse.substring(end + endtag.length());
- GetCoverageResponse = newTemplate;
-
- /* init XML parser */
- DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
- domFactory.setNamespaceAware(true); // never forget this!
- try {
- builder = domFactory.newDocumentBuilder();
- } catch (Exception e) {
- throw new NoApplicableCodeException("Error initializing XML parser", e);
- }
- }
-
- @Override
- public String execute(String stringXml) throws WCSException {
- String output;
- Metadata cov;
-
- try {
- doc = builder.parse(IOUtils.toInputStream(stringXml));
- cov = readCoverageMetadata();
- } catch (SAXException e) {
- throw new XmlNotValidException("Could not parse input request.", e);
- } catch (IOException e) {
- throw new InputOutputException("Could not read input request", e);
- } catch (XPathExpressionException e) {
- throw new InternalComponentException("Invalid XPath expression", e);
- }
-
- // Analyze input and build trim/slice info structures
- String subsetting = computeRequestSubsettingLimits(cov);
- String coverageName = cov.getCoverageName();
-
- // Evaluate all bands and then perform string processing to get coverage data
- String coverageData = buildCoverageData(cov, subsetting);
-
- // Build response xml document
- output = buildOutputXml(coverageData, cov);
-
- return output;
- }
-
- private NodeList evalXPathList(String query, Object context) throws WCSException {
- try {
- LOG.debug("Evaluating XPath: {}", query);
- XPath xpath = xpathFactory.newXPath();
-
- xpath.setNamespaceContext(new WcsNamespaceContext());
- NodeList result = (NodeList) xpath.evaluate(query, context, XPathConstants.NODESET);
-
- for (int i = 0; i < result.getLength(); i++) {
- LOG.trace("Result {}: {}", i, result.item(i).getNodeValue());
- }
-
- return (NodeList) result;
- } catch (XPathExpressionException e) {
- LOG.error("Could not execute XPath expression '{}'", query);
-
- throw new WcsRuntimeException("Could not execute XPath expression", e);
- }
- }
-
- private String getCoverageName(Document doc) throws WCSException {
- NodeList nodes = evalXPathList("//wcs:id/@gml:id", doc);
-
- if (nodes.getLength() != 1) {
- LOG.error("Could not retrieve coverage name from XML document.");
-
- return null;
- }
-
- return nodes.item(0).getNodeValue();
- }
-
- private Metadata readCoverageMetadata() throws WCSException, XPathExpressionException {
- String coverageId = getCoverageName(doc);
-
- if (meta.existsCoverageName(coverageId)) {
- try {
- Metadata cov = meta.read(coverageId);
-
- return cov;
- } catch (Exception e) {
- e.printStackTrace();
-
- throw new NoApplicableCodeException("Metadata for coverage '"
- + coverageId + "' is not valid.");
- }
- } else {
- throw new InvalidParameterValueException("gml:id");
- }
- }
-
- /** Computes the domain of the new coverage, and returns a string that can be
- * used to do subsetting on the original coverage. Also computes the low, high
- * and the axis labels for the new coverage.
- *
- * @param coverage
- * @return
- * @throws WCSException
- */
- private String computeRequestSubsettingLimits(Metadata coverage) throws WCSException {
- int dims = coverage.getDimension(), i = 0;
- String[] limits = new String[dims];
- BigInteger[] high = new BigInteger[dims];
- BigInteger[] low = new BigInteger[dims];
- String[] axesLabels = new String[dims];
- boolean[] sliced = new boolean[dims];
- boolean[] trimmed = new boolean[dims];
-
- Iterator<CellDomainElement> it = coverage.getCellDomainIterator();
- Iterator<DomainElement> it2 = coverage.getDomainIterator();
- i = 0;
- while (it.hasNext() && it2.hasNext()) {
- CellDomainElement cell = it.next();
- DomainElement dom = it2.next();
- LOG.trace(cell.toString());
- LOG.trace(dom.toString());
- high[i] = cell.getHi();
- low[i] = cell.getLo();
- axesLabels[i] = dom.getName();
- limits[i] = low[i] + ":" + high[i];
- sliced[i] = false;
- trimmed[i] = false;
- i++;
- }
-
- NodeList list = null;
- int axisIndex;
- String axis, root;
- NodeList trims, slices;
-
- trims = evalXPathList("//wcs:trimDimension", doc);
- for (i = 0; i < trims.getLength(); i++) {
- Node trim = trims.item(i);
-
- list = evalXPathList("wcs:dimension/text()", trim);
- axis = list.item(0).getNodeValue();
- axisIndex = coverage.getDomainIndexByName(axis);
- if (axisIndex == -1) {
- throw new InvalidParameterValueException("dimension. Explanation: Unknown axis: " + axis);
- }
- if (trimmed[axisIndex] || sliced[axisIndex]) {
- throw new NoApplicableCodeException("Already performed one subsetting operation on axis: " + axis);
- }
-
- list = evalXPathList("wcs:trimLow/text()", trim);
- if (list.getLength() > 0) {
- try {
- long val = Long.parseLong(list.item(0).getNodeValue());
- low[axisIndex] = BigInteger.valueOf(val);
- } catch (NumberFormatException e) {
- throw new InvalidParameterValueException("trimLow. Explanation: invalid integer number: " + list.item(0).getNodeValue());
- }
- }
- list = evalXPathList("wcs:trimHigh/text()", trim);
- if (list.getLength() > 0) {
- try {
- long val = Long.parseLong(list.item(0).getNodeValue());
- high[axisIndex] = BigInteger.valueOf(val);
- } catch (NumberFormatException e) {
- throw new InvalidParameterValueException("trimHigh. Explanation: invalid integer number: " + list.item(0).getNodeValue());
- }
- }
-
- trimmed[axisIndex] = true;
- limits[axisIndex] = low[axisIndex] + ":" + high[axisIndex];
- LOG.debug("New limits for axis {}: {}", axis, limits[axisIndex]);
- }
-
- slices = evalXPathList("//wcs:sliceDimension", doc);
- for (i = 0; i < slices.getLength(); i++) {
- Node slice = slices.item(i);
-
- list = evalXPathList("wcs:dimension/text()", slice);
- axis = list.item(0).getNodeValue();
- axisIndex = coverage.getDomainIndexByName(axis);
- if (axisIndex == -1) {
- throw new InvalidParameterValueException("dimension. Explanation: Unknown axis name: " + axis);
- }
- if (trimmed[axisIndex] || sliced[axisIndex]) {
- throw new NoApplicableCodeException("Already performed one subsetting operation on axis: " + axis);
- }
-
- list = evalXPathList("wcs:slicePoint/text()", slice);
- if (list.getLength() > 0) {
- try {
- long point = Long.parseLong(list.item(0).getNodeValue());
- low[axisIndex] = BigInteger.valueOf(point);
- } catch (NumberFormatException e) {
- throw new InvalidParameterValueException("slicePoint. Explanation: invalid integer number: " + list.item(0).getNodeValue());
- }
- high[axisIndex] = low[axisIndex];
- limits[axisIndex] = list.item(0).getNodeValue();
- }
-
- sliced[axisIndex] = true;
- LOG.debug("New limits for axis {}: {}", axis, limits[axisIndex]);
- }
-
- // Compute the lowest, highest point and the labels
- lowPoint = "";
- highPoint = "";
- newAxesLabels = "";
- int first = 0;
- for (i = 0; i < dims; i++) {
- if (sliced[i] == false) {
- if (first == 0) {
- lowPoint = low[i].toString();
- highPoint = high[i].toString();
- newAxesLabels = axesLabels[i];
- first++;
- } else {
- lowPoint += " " + low[i];
- highPoint += " " + high[i];
- newAxesLabels += " " + axesLabels[i];
- }
- }
- }
-
- // Concatenate all limits into a single string
- String result = limits[0];
-
- for (i = 1; i < dims; i++) {
- result += ", " + limits[i];
- }
-
- return result;
- }
-
- public String executeRasqlQuery(String query) throws WCSException {
- byte[] result = null;
-
- Implementation impl = new RasImplementation(ConfigManager.RASDAMAN_URL);
- Database db = impl.newDatabase();
-
- try {
- db.open(ConfigManager.RASDAMAN_DATABASE, Database.OPEN_READ_ONLY);
- } catch (ODMGException odmge) {
- try {
- db.close();
- } catch (ODMGException e) {
- }
-
- throw new InternalComponentException("Could not connect to rasdaman server at " + ConfigManager.RASDAMAN_URL + ", database " + ConfigManager.RASDAMAN_DATABASE, odmge);
- }
-
- Transaction tr = impl.newTransaction();
-
- tr.begin();
- OQLQuery q = impl.newOQLQuery();
- DBag resultSet;
-
- try {
- q.create(query);
- resultSet = (DBag) q.execute();
-
- if (resultSet != null) {
- Iterator resultIterator = resultSet.iterator();
-
- if (resultIterator.hasNext()) {
- Object current = resultIterator.next();
-
- try {
- RasGMArray resultArray = (RasGMArray) current;
- result = resultArray.getArray();
- } catch (ClassCastException e) {
- LOG.error("result=" + current.toString());
- result = current.toString().getBytes();
- }
- }
- }
- } catch (QueryException qe) {
- tr.commit();
-
- try {
- db.close();
- } catch (ODMGException odmge) {
- }
-
- throw new InternalComponentException("Could not evaluate rasdaman query: '" + query + "'. Cause: " + qe.getMessage(), qe);
- }
-
- tr.commit();
-
- try {
- db.close();
- } catch (ODMGException odmge) {
- }
-
- return new String(result);
- }
-
- /** Creates a string with the contents of the GetCoverage response XML */
- private String buildOutputXml(String coverageData, Metadata coverage) {
- String xml = GetCoverageResponse;
- xml = xml.replaceAll("\\{coverageId\\}", coverage.getCoverageName() + Math.random());
- xml = xml.replaceAll("\\{gridDimension\\}", String.valueOf(coverage.getDimension()));
- xml = xml.replaceAll("\\{gridId\\}", "grid-" + coverage.getCoverageName());
- // low
- xml = xml.replaceAll("\\{low\\}", lowPoint);
- // high
- xml = xml.replaceAll("\\{high\\}", highPoint);
- // axisLabels
- xml = xml.replaceAll("\\{axisLabels\\}", newAxesLabels);
- // coverageData
- xml = xml.replaceAll("\\{coverageData\\}", coverageData);
-
-
-
- // Build the range structure
- Iterator<RangeElement> it3 = coverage.getRangeIterator();
- int i = -1;
- String rangeComponents = "";
- while (it3.hasNext()) {
- String component = rangeComponentTemplate;
- RangeElement range = it3.next();
- i++;
- String rangeId = "range-" + coverage.getCoverageId() + "-" + range.getName();
- LOG.trace(range.toString());
-
- component = component.replaceAll("\\{rangeFieldId\\}", rangeId);
- component = component.replaceAll("\\{fieldName\\}", range.getName());
- component = component.replaceAll("\\{datatype\\}", DescribeCoverage.DATATYPE_URN_PREFIX + range.getType());
-
- // Compute the null values for this range field
- Set<String> nullVals = new HashSet<String>();
- Iterator<String> it = coverage.getNullSetIterator();
- while (it.hasNext()) {
- List<String> nilVal = SDU.str2string(it.next());
- nullVals.add(nilVal.get(i));
- }
- StringBuffer nullValsString = new StringBuffer();
- it = nullVals.iterator();
- while (it.hasNext()) {
- nullValsString.append(" " + it.next());
- }
- component = component.replaceAll("\\{nilValues\\}", nullValsString.toString().substring(1));
-
- // And add this range field to the range structure
- rangeComponents += component;
- }
-
- xml = xml.replaceAll("\\{rangeFields\\}", rangeComponents);
- xml = xml.replaceAll("\\{rangeStructureId\\}", "rangeStructure-" + coverage.getCoverageId());
-
- xml = xml.replaceAll("\\{wcsSchemaUrl\\}", ConfigManager.WCS2_SCHEMA_URL);
-
- return xml;
- }
-
- /**
- * Retrieve the coverage data for a multi-band coverage,
- * with particular subsetting parameters.
- * @param coverage metadata for the coverage we want
- * @param subsetting subsetting string, to be used in the RasQL query
- * @return a string of space-separated values, where various bands of one
- * pixel are comma-separated. For example, the string "1,2 3,4 5,6" can
- * be the coverage data of a 1-by-3 coverage, with two bands
- */
- private String buildCoverageData(Metadata coverage, String subsetting) throws WCSException {
- String coverageName = coverage.getCoverageName();
- Iterator<RangeElement> it = coverage.getRangeIterator();
- int bandcount = 0;
- while (it.hasNext()) {
- it.next();
- bandcount++;
- }
- LOG.debug("Coverage {} has {} bands", coverageName, bandcount);
- String[][] pixels = new String[bandcount][];
- String currentBand = "";
- /* For all bands of the coverage, execute a rasql query */
- for (int band = 0; band < bandcount; band++) {
- LOG.trace("Processing band {}", band);
- // Construct rasql query
- currentBand = "." + band;
- // If this is a one-band image, then band-subsetting would result in an error
- if (bandcount == 1) {
- currentBand = "";
- }
- String rasqlQuery = "select csv(cov[" + subsetting + "]" + currentBand + ") "
- + "from " + coverageName + " as cov";
-
- // Execute RasQl query => coverage data
- LOG.trace("Executing query {}", rasqlQuery);
- String output = executeRasqlQuery(rasqlQuery);
-
- // Remove the curly braces from the rasql output
- LOG.trace("Removing curly braces...");
- output = output.replaceAll("\\{", "");
- output = output.replaceAll("\\}", "");
-
- // Tokenize the input to get the pixel values of the current band
- LOG.trace("Splitting values with comma...");
- pixels[band] = output.split(",");
-
- LOG.trace("Done processing band {}.", band);
- }
-
- /* Combine all bands into one single string */
- int pixelcount = pixels[0].length;
- StringBuilder data = new StringBuilder(pixelcount * bandcount);
- LOG.debug("Going to combine {} pixels with {} bands...", pixelcount, bandcount);
- for (int pix = 0; pix < pixelcount; pix++) {
- if (pixelcount > 20 && pix % (pixelcount / 20) == 0) {
- LOG.debug("Processing Pixel {} of " + pixelcount + " - {}%", pix, pix * 100 / (pixelcount - 1));
- }
- for (int b = 0; b < bandcount - 1; b++) {
- data.append(pixels[b][pix] + ",");
- }
- data.append(pixels[bandcount - 1][pix]);
- data.append(" ");
- }
- return data.substring(0, data.length() - 2);
- }
-}
diff --git a/petascope/src/petascope/wcs2/server/ops/WcsOperation.java b/petascope/src/petascope/wcs2/server/ops/WcsOperation.java
deleted file mode 100644
index 1ad8eae..0000000
--- a/petascope/src/petascope/wcs2/server/ops/WcsOperation.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * This file is part of rasdaman community.
- *
- * Rasdaman community is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Rasdaman community 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with rasdaman community. If not, see <http://www.gnu.org/licenses/>.
- *
- * Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
- rasdaman GmbH.
- *
- * For more information please see <http://www.rasdaman.org>
- * or contact Peter Baumann via <baumann@rasdaman.com>.
- */
-package petascope.wcs2.server.ops;
-
-//~--- non-JDK imports --------------------------------------------------------
-import petascope.wcs.server.exceptions.WCSException;
-
-/**
- * Interface for all WCS Operations.
- * @author Andrei Aiordachioaie
- */
-public interface WcsOperation {
-
- /** Execute the operation */
- public String execute(String input) throws WCSException;
-}
diff --git a/petascope/src/petascope/wcs2/server/templates/DescribeCoverageTemplate.xml b/petascope/src/petascope/wcs2/server/templates/DescribeCoverageTemplate.xml
deleted file mode 100644
index c431723..0000000
--- a/petascope/src/petascope/wcs2/server/templates/DescribeCoverageTemplate.xml
+++ /dev/null
@@ -1,38 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<wcs:CoverageDescriptions xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
- xmlns:gmlwcs='http://www.opengis.net/wcs/2.0/gml'
- xmlns:gml='http://www.opengis.net/gml/3.2'
- xmlns:wcs='http://www.opengis.net/wcs/2.0'
- xmlns='http://www.opengis.net/gml/3.2'
- xsi:schemaLocation='http://www.opengis.net/wcs/2.0 {wcsSchemaUrl}/wcsAll.xsd'>
- {listOfCoverageDescriptions}
- <wcs:CoverageDescription gml:id="{coverageId}">
- <domainSet>
- <Grid dimension="{gridDimension}" gml:id="{gridId}">
- <limits>
- <GridEnvelope>
- <low>{low}</low>
- <high>{high}</high>
- </GridEnvelope>
- </limits>
- <axisLabels>{axisLabels}</axisLabels>
- </Grid>
- </domainSet>
- <gmlwcs:rangeStructure>
- <gmlwcs:RangeStructure gml:id="{rangeStructureId}">
- {rangeFields}
- <gmlwcs:rangeField>
- <gmlwcs:RangeField gml:id="{rangeFieldId}">
- <gml:name>{fieldName}</gml:name>
- <gmlwcs:dataType>{datatype}</gmlwcs:dataType>
- <gmlwcs:nilValueList>{nilValues}</gmlwcs:nilValueList>
- </gmlwcs:RangeField>
- </gmlwcs:rangeField>
- </gmlwcs:RangeStructure>
- </gmlwcs:rangeStructure>
- <wcs:ServiceParameters>
- <wcs:supportedCrsList/>
- <wcs:supportedFormatList>{supportedFormats}</wcs:supportedFormatList>
- </wcs:ServiceParameters>
- </wcs:CoverageDescription>
-</wcs:CoverageDescriptions>
diff --git a/petascope/src/petascope/wcs2/server/templates/GetCapabilitiesTemplate.xml b/petascope/src/petascope/wcs2/server/templates/GetCapabilitiesTemplate.xml
deleted file mode 100644
index 86631bf..0000000
--- a/petascope/src/petascope/wcs2/server/templates/GetCapabilitiesTemplate.xml
+++ /dev/null
@@ -1,92 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<wcs:Capabilities xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
- xmlns:ows='http://www.opengis.net/ows/1.1'
- xmlns:wcs='http://www.opengis.net/wcs/2.0'
- xmlns:gml='http://www.opengis.net/gml/3.2'
- xmlns='http://www.opengis.net/ows/1.1'
- xmlns:xlink='http://www.w3.org/1999/xlink'
- xsi:schemaLocation='http://www.opengis.net/wcs/2.0 {wcsSchemaUrl}/wcsAll.xsd' version="2.0.0">
- <ServiceIdentification>
- <Title>WCS 2.0 Coverage Server @ Jacobs University</Title>
- <Abstract>WCS 2.0 Server developed at jacobs University</Abstract>
- <ServiceType>OGC WCS</ServiceType>
- <ServiceTypeVersion>2.0.0</ServiceTypeVersion>
- <Profile>urn:ogc:def:extension:OGC-WCS:2.0:protocol:post</Profile>
- <Profile>urn:ogc:def:extension:OGC-WCS:2.0:serviceModel:wcps:1.0</Profile>
- <Profile>urn:ogc:def:extension:OGC-WCS:2.0:serviceModel:wcst:1.0</Profile>
- </ServiceIdentification>
- <ServiceProvider>
- <ProviderName>Jacobs University Bremen</ProviderName>
- <ows:ProviderSite xlink:href="http://www.petascope.org/"/>
- <ServiceContact>
- <ows:IndividualName>Prof. Dr. Peter Baumann</ows:IndividualName>
- <ows:ContactInfo>
- <ows:Address>
- <ows:City>Bremen</ows:City>
- <ows:PostalCode>28717</ows:PostalCode>
- <ows:Country>Germany</ows:Country>
- <ows:ElectronicMailAddress>p.baumann@jacobs-university.de</ows:ElectronicMailAddress>
- </ows:Address>
- </ows:ContactInfo>
- <ows:Role>Project Leader</ows:Role>
- </ServiceContact>
- </ServiceProvider>
- <OperationsMetadata>
- <Operation name="GetCapabilities">
- <DCP>
- <HTTP>
- <Get xlink:href="{URL}"/>
- </HTTP>
- </DCP>
- <Parameter name="Format">
- <AllowedValues>
- <Value>text/xml</Value>
- </AllowedValues>
- </Parameter>
- <Constraint name="PostEncoding">
- <AllowedValues>
- <Value>XML</Value>
- </AllowedValues>
- </Constraint>
- </Operation>
- <Operation name="DescribeCoverage">
- <DCP>
- <HTTP>
- <Get xlink:href="{URL}"/>
- </HTTP>
- </DCP>
- <Parameter name="Format">
- <AllowedValues>
- <Value>text/xml</Value>
- </AllowedValues>
- </Parameter>
- <Constraint name="PostEncoding">
- <AllowedValues>
- <Value>XML</Value>
- </AllowedValues>
- </Constraint>
- </Operation>
- <Operation name="GetCoverage">
- <DCP>
- <HTTP>
- <Get xlink:href="{URL}"/>
- </HTTP>
- </DCP>
- <Parameter name="Format">
- <AllowedValues>
- <Value>text/xml</Value>
- </AllowedValues>
- </Parameter>
- <Constraint name="PostEncoding">
- <AllowedValues>
- <Value>XML</Value>
- </AllowedValues>
- </Constraint>
- </Operation>
- </OperationsMetadata>
- <wcs:Contents>
- {Coverages}
- </wcs:Contents>
- <wcs:WcsServiceMetadata />
-
-</wcs:Capabilities>
diff --git a/petascope/src/petascope/wcs2/server/templates/GetCoverageTemplate.xml b/petascope/src/petascope/wcs2/server/templates/GetCoverageTemplate.xml
deleted file mode 100644
index 9b76cc9..0000000
--- a/petascope/src/petascope/wcs2/server/templates/GetCoverageTemplate.xml
+++ /dev/null
@@ -1,38 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<gmlwcs:GridCoverage xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
- xmlns:gml='http://www.opengis.net/gml/3.2'
- xmlns='http://www.opengis.net/gml/3.2'
- xmlns:gmlwcs='http://www.opengis.net/wcs/2.0/gml'
- xsi:schemaLocation='http://www.opengis.net/wcs/2.0/gml {wcsSchemaUrl}/gml/gmlwcsAll.xsd' gml:id="{coverageId}">
- <domainSet>
- <Grid dimension="{gridDimension}" gml:id="{gridId}">
- <limits>
- <GridEnvelope>
- <low>{low}</low>
- <high>{high}</high>
- </GridEnvelope>
- </limits>
- <axisLabels>{axisLabels}</axisLabels>
- </Grid>
- </domainSet>
- <rangeSet>
- <DataBlock>
- <rangeParameters/>
- <tupleList>
- {coverageData}
- </tupleList>
- </DataBlock>
- </rangeSet>
- <gmlwcs:rangeStructure>
- <gmlwcs:RangeStructure gml:id="{rangeStructureId}">
- {rangeFields}
- <gmlwcs:rangeField>
- <gmlwcs:RangeField gml:id="{rangeFieldId}">
- <gml:name>{fieldName}</gml:name>
- <gmlwcs:dataType>{datatype}</gmlwcs:dataType>
- <gmlwcs:nilValueList>{nilValues}</gmlwcs:nilValueList>
- </gmlwcs:RangeField>
- </gmlwcs:rangeField>
- </gmlwcs:RangeStructure>
- </gmlwcs:rangeStructure>
-</gmlwcs:GridCoverage>
diff --git a/petascope/src/petascope/wcs2/server/templates/WcsNamespaceContext.java b/petascope/src/petascope/wcs2/server/templates/WcsNamespaceContext.java
deleted file mode 100644
index 1f713e4..0000000
--- a/petascope/src/petascope/wcs2/server/templates/WcsNamespaceContext.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * This file is part of rasdaman community.
- *
- * Rasdaman community is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Rasdaman community 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with rasdaman community. If not, see <http://www.gnu.org/licenses/>.
- *
- * Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
- rasdaman GmbH.
- *
- * For more information please see <http://www.rasdaman.org>
- * or contact Peter Baumann via <baumann@rasdaman.com>.
- */
-package petascope.wcs2.server.templates;
-
-import java.util.Iterator;
-import javax.xml.XMLConstants;
-import javax.xml.namespace.NamespaceContext;
-
-/**
- *
- * @author Andrei Aiordachioaie
- */
-public class WcsNamespaceContext implements NamespaceContext {
-
- @Override
- public String getNamespaceURI(String prefix) {
- if (prefix == null) {
- throw new NullPointerException("Null prefix");
- } else if ("wcs".equals(prefix)) {
- return "http://www.opengis.net/wcs/2.0";
- } else if ("gml".equals(prefix)) {
- return "http://www.opengis.net/gml/3.2";
- }
-
- return XMLConstants.NULL_NS_URI;
- }
-
- // This method isn't necessary for XPath processing.
- @Override
- public String getPrefix(String uri) {
- throw new UnsupportedOperationException();
- }
-
- // This method isn't necessary for XPath processing either.
- @Override
- public Iterator getPrefixes(String uri) {
- throw new UnsupportedOperationException();
- }
-}