if (!(response instanceof GetFeatureResponse)) {
return response;
}
final GetFeatureResponse gfr = (GetFeatureResponse) response;
final GetFeatureParser allFeatures = gfr.getFeatures();
final List<SimpleFeature> originalFeatures = new ArrayList<SimpleFeature>();
{
SimpleFeature feature;
while ((feature = allFeatures.parse()) != null) {
originalFeatures.add(feature);
}
}
WFSStrategy strategy = getStrategy();
final Filter serverFiler = ((AbstractWFSStrategy) strategy).splitFilters(typeName,
request.getFilter())[0];
final Diff diff = diff(typeName);
for (Iterator<SimpleFeature> it = originalFeatures.iterator(); it.hasNext();) {
if (!serverFiler.evaluate(it.next())) {
it.remove();
}
}
FeatureReader<SimpleFeatureType, SimpleFeature> allFeaturesReader = null;
if (originalFeatures.size() > 0) {
allFeaturesReader = DataUtilities.reader(originalFeatures);
}
final DiffFeatureReader<SimpleFeatureType, SimpleFeature> serverFilteredReader;
serverFilteredReader = new DiffFeatureReader<SimpleFeatureType, SimpleFeature>(
allFeaturesReader, diff, serverFiler);
final GetFeatureParser filteredParser = new GetFeatureParser() {
@Override
public void setGeometryFactory(GeometryFactory geometryFactory) {
// TODO Auto-generated method stub
}
@Override
public SimpleFeature parse() throws IOException {
if (!serverFilteredReader.hasNext()) {
return null;
}
return serverFilteredReader.next();
}
@Override
public int getNumberOfFeatures() {
if (-1 != allFeatures.getNumberOfFeatures()) {
// only if the original response included number of features (i.e. the server
// does advertise it)
FeatureReader<SimpleFeatureType, SimpleFeature> all = null;
try {
if (originalFeatures.size() > 0) {
all = DataUtilities.reader(originalFeatures);
}
final DiffFeatureReader<SimpleFeatureType, SimpleFeature> serverFiltered;
serverFiltered = new DiffFeatureReader<SimpleFeatureType, SimpleFeature>(
all, diff);
int count = 0;
while (serverFiltered.hasNext()) {
serverFiltered.next();
count++;
}
return count;
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
return -1;
}
@Override
public FeatureType getFeatureType() {
return allFeatures.getFeatureType();
}
@Override
public void close() throws IOException {
//
}
};
try {
return new GetFeatureResponse(request, httpResponse, filteredParser);
} catch (ServiceException e) {
throw new IOException(e);
}
}