Пример #1
0
  @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);
  }
Пример #2
0
  @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);
  }