Exemplo n.º 1
0
  protected static Pair<Filter, ConstraintLanguage> parseConstraint(
      XMLAdapter adapter, OMElement omQueryElement) {
    Pair<Filter, ConstraintLanguage> pc = null;
    if (omQueryElement != null
        && new QName(CSWConstants.CSW_202_NS, "Constraint").equals(omQueryElement.getQName())) {
      Version versionConstraint =
          adapter.getRequiredNodeAsVersion(omQueryElement, new XPath("@version", nsContext));

      OMElement filterEl = omQueryElement.getFirstChildWithName(new QName(OGCNS, "Filter"));
      OMElement cqlTextEl = omQueryElement.getFirstChildWithName(new QName("", "CQLTEXT"));
      if ((filterEl != null) && (cqlTextEl == null)) {

        ConstraintLanguage constraintLanguage = ConstraintLanguage.FILTER;
        Filter constraint;
        try {
          // TODO remove usage of wrapper (necessary at the moment to work around problems
          // with AXIOM's

          XMLStreamReader xmlStream =
              new XMLStreamReaderWrapper(filterEl.getXMLStreamReaderWithoutCaching(), null);
          // skip START_DOCUMENT
          xmlStream.nextTag();

          if (versionConstraint.equals(new Version(1, 1, 0))) {

            constraint = Filter110XMLDecoder.parse(xmlStream);

          } else if (versionConstraint.equals(new Version(1, 0, 0))) {
            constraint = Filter100XMLDecoder.parse(xmlStream);
          } else {
            String msg =
                Messages.get(
                    "CSW_FILTER_VERSION_NOT_SPECIFIED",
                    versionConstraint,
                    Version.getVersionsString(new Version(1, 1, 0)),
                    Version.getVersionsString(new Version(1, 0, 0)));
            LOG.info(msg);
            throw new InvalidParameterValueException(msg);
          }
        } catch (XMLStreamException e) {
          String msg =
              "FilterParsingException: There went something wrong while parsing the filter expression, so please check this!";
          LOG.debug(msg);
          throw new XMLParsingException(adapter, filterEl, e.getMessage());
        }
        pc = new Pair<Filter, CSWConstants.ConstraintLanguage>(constraint, constraintLanguage);
      } else if ((filterEl == null) && (cqlTextEl != null)) {
        String msg = Messages.get("CSW_UNSUPPORTED_CQL_FILTER");
        LOG.info(msg);
        throw new NotImplementedError(msg);
      } else {
        String msg = Messages.get("CSW_MISSING_FILTER_OR_CQL");
        LOG.debug(msg);
        throw new InvalidParameterValueException(msg);
      }
    }
    return pc;
  }
Exemplo n.º 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);
  }