01: package org.geoserver.wfsv.response.v1_1_0;
02:
03: import java.io.IOException;
04: import java.io.OutputStream;
05: import java.util.Collections;
06:
07: import net.opengis.wfs.DescribeFeatureTypeType;
08:
09: import org.eclipse.xsd.XSDSchema;
10: import org.eclipse.xsd.util.XSDResourceImpl;
11: import org.geoserver.ows.Response;
12: import org.geoserver.ows.util.RequestUtils;
13: import org.geoserver.platform.GeoServerResourceLoader;
14: import org.geoserver.platform.Operation;
15: import org.geoserver.platform.ServiceException;
16: import org.geoserver.wfs.WFS;
17: import org.geoserver.wfs.xml.FeatureTypeSchemaBuilder;
18: import org.geoserver.wfsv.VersionedDescribeResults;
19: import org.geoserver.wfsv.xml.v1_1_0.WFSVConfiguration;
20: import org.vfny.geoserver.global.Data;
21:
22: public class VersionedXmlSchemaEncoder extends Response {
23: /** wfs configuration */
24: WFS wfs;
25:
26: /** the catalog */
27: Data catalog;
28:
29: /** the geoserver resource loader */
30: GeoServerResourceLoader resourceLoader;
31:
32: WFSVConfiguration configuration;
33:
34: public VersionedXmlSchemaEncoder(WFS wfs, Data catalog,
35: GeoServerResourceLoader resourceLoader,
36: WFSVConfiguration configuration) {
37: super (VersionedDescribeResults.class, Collections
38: .singleton("text/xml; subtype=gml/3.1.1"));
39: this .wfs = wfs;
40: this .catalog = catalog;
41: this .resourceLoader = resourceLoader;
42: this .configuration = configuration;
43: }
44:
45: public String getMimeType(Object value, Operation operation)
46: throws ServiceException {
47: return "text/xml; subtype=gml/3.1.1";
48: }
49:
50: public void write(Object value, OutputStream output,
51: Operation describeFeatureType) throws IOException {
52: VersionedDescribeResults results = (VersionedDescribeResults) value;
53:
54: // create the schema
55: DescribeFeatureTypeType req = (DescribeFeatureTypeType) describeFeatureType
56: .getParameters()[0];
57: String proxifiedBaseUrl = RequestUtils.proxifiedBaseURL(req
58: .getBaseUrl(), wfs.getGeoServer().getProxyBaseUrl());
59: FeatureTypeSchemaBuilder builder = null;
60: if (results.isVersioned()) {
61: builder = new VersionedSchemaBuilder(wfs, catalog,
62: resourceLoader, configuration);
63: } else {
64: builder = new FeatureTypeSchemaBuilder.GML3(wfs, catalog,
65: resourceLoader);
66: }
67:
68: XSDSchema schema = builder.build(results.getFeatureTypeInfo(),
69: proxifiedBaseUrl);
70:
71: // serialize
72: schema.updateElement();
73: XSDResourceImpl.serialize(output, schema.getElement());
74: }
75:
76: public boolean canHandle(Operation operation) {
77: return "DescribeVersionedFeatureType"
78: .equalsIgnoreCase(operation.getId())
79: && operation.getService().getId().equalsIgnoreCase(
80: "wfsv");
81: }
82:
83: }
|