01: /* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
02: * This code is licensed under the GPL 2.0 license, availible at the root
03: * application directory.
04: */
05:
06: package org.geoserver.wfsv.response.v1_1_0;
07:
08: import java.io.IOException;
09: import java.io.OutputStream;
10: import java.util.Collections;
11:
12: import net.opengis.wfs.FeatureCollectionType;
13: import net.opengis.wfs.GetFeatureType;
14: import net.opengis.wfs.QueryType;
15: import net.opengis.wfs.ResultTypeType;
16: import net.opengis.wfs.WfsFactory;
17: import net.opengis.wfsv.GetLogType;
18:
19: import org.geoserver.ows.util.OwsUtils;
20: import org.geoserver.platform.Operation;
21: import org.geoserver.platform.ServiceException;
22: import org.geoserver.wfs.WFS;
23: import org.geoserver.wfs.xml.GML2OutputFormat;
24: import org.geotools.feature.FeatureCollection;
25: import org.geotools.feature.FeatureType;
26: import org.vfny.geoserver.global.Data;
27: import org.vfny.geoserver.global.GeoServer;
28:
29: /**
30: * Extends GML2OutputFormat to allow GetLog output to be encoded in GML2
31: * @author Andrea Aime
32: * @author David Winslow
33: *
34: */
35: public class GetLogGML2OutputFormat extends GML2OutputFormat {
36:
37: public GetLogGML2OutputFormat(WFS wfs, GeoServer geoserver,
38: Data catalog) {
39: super (wfs, geoserver, catalog);
40: }
41:
42: protected void write(FeatureCollectionType featureCollection,
43: OutputStream output, Operation getFeature)
44: throws IOException, ServiceException {
45: GetLogType request = (GetLogType) getFeature.getParameters()[0];
46: GetFeatureType ftRequest = toGetFeatureType(featureCollection,
47: request);
48:
49: prepare(ftRequest.getOutputFormat(), featureCollection,
50: ftRequest);
51: encode(output, featureCollection, ftRequest);
52: }
53:
54: /**
55: * Turns a GetLogType objects into an almost equivalent GetFeatureType object s
56: * that the superclass can do its work
57: * @param featureCollection
58: * @param request
59: * @return
60: */
61: private GetFeatureType toGetFeatureType(
62: FeatureCollectionType featureCollection, GetLogType request) {
63: FeatureCollection features = (FeatureCollection) featureCollection
64: .getFeature().get(0);
65: FeatureType featureType = features.getSchema();
66: GetFeatureType ftRequest = WfsFactory.eINSTANCE
67: .createGetFeatureType();
68: QueryType query = WfsFactory.eINSTANCE.createQueryType();
69: query.setTypeName(Collections.singletonList(featureType
70: .getTypeName()));
71: ftRequest.getQuery().add(query);
72: ftRequest.setBaseUrl(request.getBaseUrl());
73: ftRequest.setHandle(request.getHandle());
74: ftRequest.setMaxFeatures(request.getMaxFeatures());
75: ftRequest.setOutputFormat(request.getOutputFormat());
76: ftRequest.setResultType(ResultTypeType.RESULTS_LITERAL);
77: return ftRequest;
78: }
79:
80: public boolean canHandle(Operation operation) {
81: // GetFeature operation?
82: if ("GetLog".equalsIgnoreCase(operation.getId())) {
83: // also check that the resultType is "results"
84: GetLogType request = (GetLogType) OwsUtils.parameter(
85: operation.getParameters(), GetLogType.class);
86:
87: return request.getResultType() == ResultTypeType.RESULTS_LITERAL;
88: }
89:
90: return false;
91: }
92:
93: }
|