@SuppressWarnings("boxing") private static GetFeature parse110(Map<String, String> kvpParams) throws Exception { StandardPresentationParams presentationParams = parseStandardPresentationParameters110(kvpParams); ResolveParams resolveParams = parseStandardResolveParameters110(kvpParams); // optional: 'NAMESPACE' Map<String, String> nsBindings = extractNamespaceBindings110(kvpParams); if (nsBindings == null) { nsBindings = Collections.emptyMap(); } NamespaceBindings nsContext = new NamespaceBindings(); if (nsBindings != null) { for (String key : nsBindings.keySet()) { nsContext.addNamespace(key, nsBindings.get(key)); } } // optional: SRSNAME String srsName = kvpParams.get("SRSNAME"); ICRS srs = null; if (srsName != null) { srs = CRSManager.getCRSRef(srsName); } // optional: 'PROPERTYNAME' String propertyStr = kvpParams.get("PROPERTYNAME"); PropertyName[][] propertyNames = getPropertyNames(propertyStr, nsContext); // optional: SORTBY String sortbyStr = kvpParams.get("SORTBY"); SortProperty[] sortBy = getSortBy(sortbyStr, nsContext); // optional: FEATUREVERSION String featureVersion = kvpParams.get("FEATUREVERSION"); // mandatory: TYPENAME, but optional if FEATUREID is specified String typeStrList = kvpParams.get("TYPENAME"); TypeName[] typeNames = getTypeNames(typeStrList, nsBindings); // optional: FEATUREID String featureIdStr = kvpParams.get("FEATUREID"); String[] featureIds = null; if (featureIdStr != null) { featureIds = featureIdStr.split(","); } // optional: BBOX String bboxStr = kvpParams.get("BBOX"); // optional: FILTER String filterStr = kvpParams.get("FILTER"); // optional: 'PROPTRAVXLINKDEPTH' String propTravXlinkDepth = kvpParams.get("PROPTRAVXLINKDEPTH"); String[][] ptxDepthAr = null; if (propTravXlinkDepth != null) { ptxDepthAr = parseParamList(propTravXlinkDepth); } // optional: 'PROPTRAVXLINKEXPIRY' String propTravXlinkExpiry = kvpParams.get("PROPTRAVXLINKEXPIRY"); Integer[][] ptxExpAr = null; if (propTravXlinkExpiry != null) { ptxExpAr = parseParamListAsInts(propTravXlinkDepth); } propertyNames = getXLinkPropNames(propertyNames, ptxDepthAr, ptxExpAr); List<Query> queries = new ArrayList<Query>(); if ((featureIdStr != null && bboxStr != null) || (featureIdStr != null && filterStr != null) || (bboxStr != null && filterStr != null)) { // TODO make new exception throw new Exception("The FEATUREID, BBOX and FILTER keywords are mutually exclusive!"); } if (featureIdStr != null) { if (typeStrList == null && propertyNames == null) { queries.add(new FeatureIdQuery(null, null, featureVersion, srs, null, sortBy, featureIds)); } else { for (int i = 0; i < featureIds.length; i++) { String[] fid = new String[] {featureIds[i]}; TypeName[] typeName = new TypeName[0]; if (typeStrList != null) { typeName = new TypeName[] {typeNames[i]}; } PropertyName[] projectionClauses = null; if (propertyNames != null) { projectionClauses = propertyNames[i]; } queries.add( new FeatureIdQuery( null, typeName, featureVersion, srs, projectionClauses, sortBy, fid)); } } } else if (bboxStr != null) { if (typeNames == null) { // TODO make new exception throw new Exception("The TYPENAME keyword is mandatory if BBOX is present!"); } String[] coordList = bboxStr.split(","); // NOTE: Contradiction between spec and CITE tests (for omitted crsUri) // - WFS 1.1.0 spec, 14.3.3: coordinates should be in WGS84 // - CITE tests, wfs:wfs-1.1.0-Basic-GetFeature-tc8.1: If no CRS reference is provided, a // service-defined // default value must be assumed. ICRS bboxCrs = null; if (coordList.length % 2 == 1) { bboxCrs = CRSManager.getCRSRef(coordList[coordList.length - 1]); } Envelope bbox = createEnvelope(bboxStr, bboxCrs); for (int i = 0; i < typeNames.length; i++) { TypeName typeName = typeNames[i]; PropertyName[] projectionClauses = null; if (propertyNames != null) { projectionClauses = propertyNames[i]; } queries.add( new BBoxQuery( null, new TypeName[] {typeName}, featureVersion, srs, projectionClauses, sortBy, bbox)); } } else if (filterStr != null || typeNames != null) { if (typeNames == null) { // TODO make new exception throw new Exception("The FILTER element requires the TYPENAME element"); } int length = typeNames.length; String[] filters = getFilters(filterStr); for (int i = 0; i < length; i++) { Filter filter = null; if (filters != null) { StringReader sr = new StringReader(filters[i]); XMLAdapter adapter = new XMLAdapter(sr); XMLStreamReaderWrapper streamWrapper = new XMLStreamReaderWrapper( adapter.getRootElement().getXMLStreamReaderWithoutCaching(), adapter.getSystemId()); try { streamWrapper.nextTag(); filter = Filter110XMLDecoder.parse(streamWrapper); } catch (XMLParsingException e) { e.printStackTrace(); // TODO raise exception } catch (XMLStreamException e) { e.printStackTrace(); // TODO raise exception } } if (propertyNames != null) { queries.add( new FilterQuery( null, new TypeName[] {typeNames[i]}, featureVersion, srs, propertyNames[i], sortBy, filter)); } else { queries.add( new FilterQuery( null, new TypeName[] {typeNames[i]}, featureVersion, srs, null, sortBy, filter)); } } } return new GetFeature(VERSION_110, null, presentationParams, resolveParams, queries); }
public static Query getQuery(OMElement omElement) { if (new QName(CSWConstants.CSW_202_NS, "Query").equals(omElement.getQName())) { XMLAdapter adapter = new XMLAdapter(omElement); SortProperty[] sortProps = null; Filter constraint = null; ReturnableElement elementSetName = null; String[] elementName = null; ConstraintLanguage constraintLanguage = null; List<OMElement> queryChildElements = adapter.getRequiredElements(omElement, new XPath("*", nsContext)); String typeQuery = adapter.getNodeAsString(omElement, new XPath("./@typeNames", nsContext), ""); if ("".equals(typeQuery)) { String msg = "ERROR in XML document: Required attribute \"typeNames\" in element \"Query\" is missing!"; throw new MissingParameterException(msg); } String[] queryTypeNamesString = StringUtils.split(typeQuery, " "); QName[] queryTypeNames = new QName[queryTypeNamesString.length]; int counterQName = 0; for (String s : queryTypeNamesString) { LOG.debug("Parsing typeName '" + s + "' of Query as QName. "); QName qname = adapter.parseQName(s, adapter.getRootElement()); queryTypeNames[counterQName++] = qname; } elementName = adapter.getNodesAsStrings(omElement, new XPath("./csw:ElementName", nsContext)); QName[] returnTypeNames = null; for (OMElement omQueryElement : queryChildElements) { // TODO mandatory exclusiveness between ElementSetName vs. ElementName not implemented yet if (new QName(CSWConstants.CSW_202_NS, "ElementSetName") .equals(omQueryElement.getQName())) { String elementSetNameString = omQueryElement.getText(); elementSetName = ReturnableElement.determineReturnableElement(elementSetNameString); // elementSetNameTypeNames = getNodesAsQNames( omQueryElement, new XPath( "@typeNames", // nsContext ) ); String typeElementSetName = adapter .getNodeAsString(omQueryElement, new XPath("./@typeNames", nsContext), "") .trim(); String[] elementSetNameTypeNamesString = StringUtils.split(typeElementSetName, " "); returnTypeNames = new QName[elementSetNameTypeNamesString.length]; for (int i = 0; i < elementSetNameTypeNamesString.length; i++) { returnTypeNames[i] = adapter.parseQName(elementSetNameTypeNamesString[i], omElement); } } Pair<Filter, ConstraintLanguage> parsedConstraint = parseConstraint(adapter, omQueryElement); if (parsedConstraint != null) { constraintLanguage = parsedConstraint.second; constraint = parsedConstraint.first; } if (new QName(OGCNS, "SortBy").equals(omQueryElement.getQName())) { List<OMElement> sortPropertyElements = adapter.getRequiredElements(omQueryElement, new XPath("ogc:SortProperty", nsContext)); sortProps = new SortProperty[sortPropertyElements.size()]; int counter = 0; for (OMElement sortPropertyEl : sortPropertyElements) { OMElement propNameEl = adapter.getRequiredElement( sortPropertyEl, new XPath("ogc:PropertyName", nsContext)); String sortOrder = adapter.getNodeAsString( sortPropertyEl, new XPath("ogc:SortOrder", nsContext), "ASC"); SortProperty sortProp = new SortProperty( new ValueReference( propNameEl.getText(), adapter.getNamespaceContext(propNameEl)), sortOrder.equals("ASC")); sortProps[counter++] = sortProp; } } } return new Query( elementSetName, elementName, constraint, constraintLanguage, sortProps, queryTypeNames, returnTypeNames); } return null; }
@SuppressWarnings("boxing") private static GetFeature parse100(Map<String, String> kvpParams, Map<String, String> nsMap) throws Exception { NamespaceBindings nsContext = new NamespaceBindings(); if (nsMap != null) { for (String key : nsMap.keySet()) { nsContext.addNamespace(key, nsMap.get(key)); } } StandardPresentationParams presentationParams = parseStandardPresentationParameters100(kvpParams); // optional: 'PROPERTYNAME' String propertyStr = kvpParams.get("PROPERTYNAME"); PropertyName[][] propertyNames = getPropertyNames(propertyStr, nsContext); // optional: FEATUREVERSION String featureVersion = kvpParams.get("FEATUREVERSION"); // mandatory: TYPENAME, but optional if FEATUREID is specified String typeStrList = kvpParams.get("TYPENAME"); TypeName[] typeNames = getTypeNames100(typeStrList); // optional: FEATUREID String featureIdStr = kvpParams.get("FEATUREID"); String[] featureIds = null; if (featureIdStr != null) { featureIds = featureIdStr.split(","); } // optional: BBOX String bboxStr = kvpParams.get("BBOX"); // optional: FILTER String filterStr = kvpParams.get("FILTER"); // optional: SRSNAME (not specified in WFS 1.0.0, deegree extension) String srsName = kvpParams.get("SRSNAME"); ICRS srs = null; if (srsName != null) { srs = CRSManager.getCRSRef(srsName); } List<Query> queries = new ArrayList<Query>(); if ((featureIdStr != null && bboxStr != null) || (featureIdStr != null && filterStr != null) || (bboxStr != null && filterStr != null)) { // TODO make new exception throw new Exception("The FEATUREID, BBOX and FILTER keywords are mutually exclusive!"); } if (featureIdStr != null) { if (typeStrList == null && propertyNames == null) { queries.add(new FeatureIdQuery(null, null, featureVersion, srs, null, null, featureIds)); } else { for (int i = 0; i < featureIds.length; i++) { String[] fids = new String[] {featureIds[i]}; TypeName[] typeName = new TypeName[0]; if (typeStrList != null) { typeName = new TypeName[] {typeNames[i]}; } PropertyName[] projectionClauses = null; if (propertyNames != null) { if (propertyNames.length > 1) { projectionClauses = propertyNames[i]; } else { projectionClauses = propertyNames[0]; } } queries.add( new FeatureIdQuery( null, typeName, featureVersion, srs, projectionClauses, null, fids)); } } } else if (bboxStr != null) { if (typeNames == null) { // TODO make new exception throw new Exception("The TYPENAME keyword is mandatory if BBOX is present!"); } String[] coordList = bboxStr.split(","); ICRS bboxCrs = null; if (coordList.length % 2 == 1) { bboxCrs = CRSManager.getCRSRef(coordList[coordList.length - 1]); } Envelope bbox = createEnvelope(bboxStr, bboxCrs); for (int i = 0; i < typeNames.length; i++) { TypeName typeName = typeNames[i]; PropertyName[] projectionClauses = null; if (propertyNames != null) { projectionClauses = propertyNames[i]; } queries.add( new BBoxQuery( null, new TypeName[] {typeName}, featureVersion, srs, projectionClauses, null, bbox)); } } else if (filterStr != null || typeNames != null) { if (typeNames == null) { // TODO make new exception throw new Exception("The FILTER element requires the TYPENAME element"); } int length = typeNames.length; String[] filters = getFilters(filterStr); for (int i = 0; i < length; i++) { Filter filter = null; if (filters != null) { StringReader sr = new StringReader(filters[i]); XMLAdapter adapter = new XMLAdapter(sr); XMLStreamReaderWrapper streamWrapper = new XMLStreamReaderWrapper( adapter.getRootElement().getXMLStreamReaderWithoutCaching(), adapter.getSystemId()); try { streamWrapper.nextTag(); filter = Filter100XMLDecoder.parse(streamWrapper); } catch (XMLParsingException e) { e.printStackTrace(); // TODO raise exception } catch (XMLStreamException e) { e.printStackTrace(); // TODO raise exception } } if (propertyNames != null) { queries.add( new FilterQuery( null, new TypeName[] {typeNames[i]}, featureVersion, srs, propertyNames[i], null, filter)); } else { queries.add( new FilterQuery( null, new TypeName[] {typeNames[i]}, featureVersion, srs, null, null, filter)); } } } return new GetFeature(VERSION_100, null, presentationParams, null, queries); }