@Override protected void encode(FeatureCollectionResponse hits, OutputStream output, WFSInfo wfs) throws IOException { hits.setNumberOfFeatures(BigInteger.valueOf(0)); Encoder e = new Encoder(new WFSConfiguration()); e.setEncoding(Charset.forName(wfs.getGeoServer().getSettings().getCharset())); e.setSchemaLocation( WFS.NAMESPACE, ResponseUtils.appendPath(wfs.getSchemaBaseURL(), "wfs/2.0/wfs.xsd")); e.encode(hits.getAdaptee(), WFS.FeatureCollection, output); } }
result.setNumberOfFeatures(BigInteger.valueOf(count)); result.setTotalNumberOfFeatures(total); result.setTimeStamp(Calendar.getInstance());
public void write(Object value, OutputStream output, Operation operation) throws IOException, ServiceException { WFSInfo wfs = getInfo(); FeatureCollectionResponse featureCollection = (FeatureCollectionResponse) value; // create a new feautre collcetion type with just the numbers FeatureCollectionResponse hits = featureCollection.create(); if (GML3OutputFormat.isComplexFeature(featureCollection)) { // we have to count the number of features here manually because complex feature // collection size() now returns 0. In order to count the number of features, // we have to build the features to count them and this has great performance // impact. Unless we introduce joins in our fetching of // data, we will have to count the number of features manually when needed. In // GML3Outputformat I use xslt to populate numberOfFeatures attribute. hits.setNumberOfFeatures(countFeature(featureCollection)); } else { hits.setNumberOfFeatures(featureCollection.getNumberOfFeatures()); } hits.setTotalNumberOfFeatures(featureCollection.getTotalNumberOfFeatures()); hits.setNext(featureCollection.getNext()); hits.setPrevious(featureCollection.getPrevious()); hits.setTimeStamp(featureCollection.getTimeStamp()); encode(hits, output, wfs); }
@Override protected void encode(FeatureCollectionResponse hits, OutputStream output, WFSInfo wfs) throws IOException { hits.setNumberOfFeatures(BigInteger.ZERO); // instantiate the XML encoder Encoder encoder = new Encoder(new WFSConfiguration()); encoder.setEncoding(Charset.forName(wfs.getGeoServer().getSettings().getCharset())); encoder.setSchemaLocation( WFS.NAMESPACE, ResponseUtils.appendPath(wfs.getSchemaBaseURL(), "wfs/2.0/wfs.xsd")); Document document; try { // encode the HITS result using FeatureCollection as the root XML element document = encoder.encodeAsDOM(hits.getAdaptee(), WFS.FeatureCollection); } catch (Exception exception) { throw new RuntimeException("Error encoding INDEX result.", exception); } // add the resultSetID attribute to the result addResultSetIdElement(document, resultSetId); // write the XML document to response output stream writeDocument(document, output); }