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: package org.geoserver.wfs.xml.v1_1_0;
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.util.RequestUtils;
12: import org.geoserver.platform.GeoServerResourceLoader;
13: import org.geoserver.platform.Operation;
14: import org.geoserver.platform.ServiceException;
15: import org.geoserver.wfs.WFS;
16: import org.geoserver.wfs.WFSDescribeFeatureTypeOutputFormat;
17: import org.geoserver.wfs.xml.FeatureTypeSchemaBuilder;
18: import org.vfny.geoserver.global.Data;
19: import org.vfny.geoserver.global.FeatureTypeInfo;
20: import java.io.IOException;
21: import java.io.OutputStream;
22:
23: public class XmlSchemaEncoder extends
24: WFSDescribeFeatureTypeOutputFormat {
25: /** wfs configuration */
26: WFS wfs;
27:
28: /** the catalog */
29: Data catalog;
30:
31: /** the geoserver resource loader */
32: GeoServerResourceLoader resourceLoader;
33:
34: public XmlSchemaEncoder(WFS wfs, Data catalog,
35: GeoServerResourceLoader resourceLoader) {
36: super ("text/xml; subtype=gml/3.1.1");
37: this .wfs = wfs;
38: this .catalog = catalog;
39: this .resourceLoader = resourceLoader;
40: }
41:
42: public String getMimeType(Object value, Operation operation)
43: throws ServiceException {
44: return "text/xml; subtype=gml/3.1.1";
45: }
46:
47: protected void write(FeatureTypeInfo[] featureTypeInfos,
48: OutputStream output, Operation describeFeatureType)
49: throws IOException {
50: //create the schema
51: DescribeFeatureTypeType req = (DescribeFeatureTypeType) describeFeatureType
52: .getParameters()[0];
53: String proxifiedBaseUrl = RequestUtils.proxifiedBaseURL(req
54: .getBaseUrl(), wfs.getGeoServer().getProxyBaseUrl());
55: FeatureTypeSchemaBuilder builder = new FeatureTypeSchemaBuilder.GML3(
56: wfs, catalog, resourceLoader);
57: XSDSchema schema = builder.build(featureTypeInfos,
58: proxifiedBaseUrl);
59:
60: //serialize
61: schema.updateElement();
62: XSDResourceImpl.serialize(output, schema.getElement());
63: }
64: }
|