// first, locate the intervalOrPoint part
int openIdx = value.indexOf("(");
int closeIdx = value.indexOf(")");
if (openIdx == -1 || closeIdx == -1 || closeIdx < value.length() - 1) {
throw new OWS20Exception("Invalid syntax, dimension [ , crs ] ( intervalOrPoint ) is expected",
WCS20ExceptionCode.InvalidEncodingSyntax, "subset");
}
// parse the first part, dimension[,crs]
String dimension = null;
String crs = null;
String dimensionCrs = value.substring(0, openIdx);
String[] dcElements = dimensionCrs.split("\\s*,\\s*");
if (dcElements.length == 1) {
dimension = dcElements[0];
crs = null;
} else if (dcElements.length == 2) {
dimension = dcElements[0];
crs = dcElements[1];
} else {
throw new OWS20Exception("Invalid syntax, dimension [ , crs ] ( intervalOrPoint ) is expected",
WCS20ExceptionCode.InvalidEncodingSyntax, "subset");
}
// parse the second part, intervalOrPoint
String valuePoint = value.substring(openIdx + 1, closeIdx);
// split on all commas not contained in quotes
String[] vpElements = valuePoint.split(",\\s*(?=([^\"]*\"[^\"]*\")*[^\"]*$)");
if (vpElements.length == 1) {
// point
String point = parsePoint(vpElements[0], false);
DimensionSliceType slice = Wcs20Factory.eINSTANCE.createDimensionSliceType();
slice.setDimension(dimension);
slice.setCRS(crs);
slice.setSlicePoint(point);
return slice;
} else if (vpElements.length == 2) {
String low = parsePoint(vpElements[0], true);
String high = parsePoint(vpElements[1], true);
DimensionTrimType trim = Wcs20Factory.eINSTANCE.createDimensionTrimType();
trim.setDimension(dimension);
trim.setCRS(crs);
trim.setTrimLow(low);
trim.setTrimHigh(high);
return trim;
} else {
throw new OWS20Exception("Invalid syntax, dimension [ , crs ] ( intervalOrPoint ) "
+ "where interval or point has either 1 or two elements",
WCS20ExceptionCode.InvalidEncodingSyntax, "subset");
}
}