📄 capabilitiestransformer.java
字号:
/* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
* This code is licensed under the GPL 2.0 license, availible at the root
* application directory.
*/
package org.geoserver.wfs;
import com.vividsolutions.jts.geom.Envelope;
import net.opengis.wfs.GetCapabilitiesType;
import org.geoserver.ows.util.RequestUtils;
import org.geoserver.ows.util.ResponseUtils;
import org.geoserver.ows.xml.v1_0.OWS;
import org.geoserver.platform.GeoServerExtensions;
import org.geoserver.wfs.response.GetCapabilitiesResponse;
import org.geotools.factory.FactoryRegistry;
import org.geotools.filter.FunctionExpression;
import org.geotools.filter.v1_0.OGC;
import org.geotools.gml3.bindings.GML;
import org.geotools.xlink.bindings.XLINK;
import org.geotools.xml.transform.TransformerBase;
import org.geotools.xml.transform.Translator;
import org.opengis.filter.expression.Function;
import org.vfny.geoserver.global.Data;
import org.vfny.geoserver.global.FeatureTypeInfo;
import org.vfny.geoserver.global.FeatureTypeInfoTitleComparator;
import org.vfny.geoserver.global.NameSpaceInfo;
import org.xml.sax.ContentHandler;
import org.xml.sax.helpers.AttributesImpl;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Based on the <code>org.geotools.xml.transform</code> framework, does the job
* of encoding a WFS 1.0 Capabilities document.
*
* @author Gabriel Roldan, Axios Engineering
* @author Chris Holmes
* @author Justin Deoliveira
*
* @version $Id: CapabilitiesTransformer.java 7746 2007-11-13 15:38:35Z aaime $
*/
public abstract class CapabilitiesTransformer extends TransformerBase {
/** logger */
private static final Logger LOGGER = org.geotools.util.logging.Logging.getLogger(CapabilitiesTransformer.class.getPackage()
.getName());
/** identifer of a http get + post request */
private static final String HTTP_GET = "Get";
private static final String HTTP_POST = "Post";
/** wfs namespace */
protected static final String WFS_URI = "http://www.opengis.net/wfs";
/** xml schema namespace + prefix */
protected static final String XSI_PREFIX = "xsi";
protected static final String XSI_URI = "http://www.w3.org/2001/XMLSchema-instance";
/** filter namesapce + prefix */
protected static final String OGC_PREFIX = "ogc";
protected static final String OGC_URI = OGC.NAMESPACE;
/** wfs service */
protected WFS wfs;
/** catalog */
protected Data catalog;
/**
* Creates a new CapabilitiesTransformer object.
*/
public CapabilitiesTransformer(WFS wfs, Data catalog) {
super();
setNamespaceDeclarationEnabled(false);
this.wfs = wfs;
this.catalog = catalog;
}
/**
* Transformer for wfs 1.0 capabilities document.
*
* @author Justin Deoliveira, The Open Planning Project
*
*/
public static class WFS1_0 extends CapabilitiesTransformer {
public WFS1_0(WFS wfs, Data catalog) {
super(wfs, catalog);
}
public Translator createTranslator(ContentHandler handler) {
return new CapabilitiesTranslator1_0(handler);
}
class CapabilitiesTranslator1_0 extends TranslatorSupport {
GetCapabilitiesType request;
public CapabilitiesTranslator1_0(ContentHandler handler) {
super(handler, null, null);
}
public void encode(Object object) throws IllegalArgumentException {
request = (GetCapabilitiesType)object;
String proxifiedBaseUrl = RequestUtils.proxifiedBaseURL(request.getBaseUrl(), wfs.getGeoServer().getProxyBaseUrl());
AttributesImpl attributes = new AttributesImpl();
attributes.addAttribute("", "version", "version", "", "1.0.0");
attributes.addAttribute("", "xmlns", "xmlns", "", WFS_URI);
NameSpaceInfo[] namespaces = catalog.getNameSpaces();
for (int i = 0; i < namespaces.length; i++) {
NameSpaceInfo namespace = namespaces[i];
String prefix = namespace.getPrefix();
String uri = namespace.getURI();
if ("xml".equals(prefix)) {
continue;
}
String prefixDef = "xmlns:" + prefix;
attributes.addAttribute("", prefixDef, prefixDef, "", uri);
}
//filter
attributes.addAttribute("", "xmlns:" + OGC_PREFIX, "xmlns:" + OGC_PREFIX, "",
OGC_URI);
//xml schema
attributes.addAttribute("", "xmlns:" + XSI_PREFIX, "xmlns:" + XSI_PREFIX, "",
XSI_URI);
String locationAtt = XSI_PREFIX + ":schemaLocation";
String locationDef = WFS_URI + " "
+ ResponseUtils.appendPath(proxifiedBaseUrl,
"schemas/wfs/1.0.0/WFS-capabilities.xsd");
attributes.addAttribute("", locationAtt, locationAtt, "", locationDef);
start("WFS_Capabilities", attributes);
handleService();
handleCapability();
handleFeatureTypes();
handleFilterCapabilities();
end("WFS_Capabilities");
}
/**
* Encodes the wfs:Service element.
*
* <pre>
* <xsd:complexType name="ServiceType">
* <xsd:sequence>
* <xsd:element name="Name" type="xsd:string"/>
* <xsd:element ref="wfs:Title"/>
* <xsd:element ref="wfs:Abstract" minOccurs="0"/>
* <xsd:element ref="wfs:Keywords" minOccurs="0"/>
* <xsd:element ref="wfs:OnlineResource"/>
* <xsd:element ref="wfs:Fees" minOccurs="0"/>
* <xsd:element ref="wfs:AccessConstraints" minOccurs="0"/>
* </xsd:sequence>
* </xsd:complexType>
*
* </pre>
*
*/
private void handleService() {
start("Service");
element("Name", wfs.getName());
element("Title", wfs.getTitle());
element("Abstract", wfs.getAbstract());
handleKeywords(wfs.getKeywords());
String proxifiedBaseUrl = RequestUtils.proxifiedBaseURL(request.getBaseUrl(), wfs.getGeoServer().getProxyBaseUrl());
element("OnlineResource", ResponseUtils.appendPath(proxifiedBaseUrl, "wfs"));
element("Fees", wfs.getFees());
element("AccessConstraints", wfs.getAccessConstraints());
end("Service");
}
/**
* Encodes the wfs:Keywords element.
* <p>
*
* <pre>
* <!-- Short words to help catalog searching.
* Currently, no controlled vocabulary has
* been defined. -->
* <xsd:element name="Keywords" type="xsd:string"/>
* </pre>
*
* </p>
*
*/
private void handleKeywords(String[] kwlist) {
if (kwlist == null) {
handleKeywords((List) null);
} else {
handleKeywords(Arrays.asList(kwlist));
}
}
/**
* Encodes the wfs:Keywords element.
* <p>
*
* <pre>
* <!-- Short words to help catalog searching.
* Currently, no controlled vocabulary has
* been defined. -->
* <xsd:element name="Keywords" type="xsd:string"/>
* </pre>
*
* </p>
*
*/
private void handleKeywords(List kwlist) {
StringBuffer kwds = new StringBuffer();
for (int i = 0; (kwlist != null) && (i < kwlist.size()); i++) {
kwds.append(kwlist.get(i));
if (i != (kwlist.size() - 1)) {
kwds.append(", ");
}
}
element("Keywords", kwds.toString());
}
/**
* Encodes the wfs:Capability element.
* <p>
*
* <pre>
* <xsd:complexType name="CapabilityType">
* <xsd:sequence>
* <xsd:element name="Request" type="wfs:RequestType"/>
* <!-- The optional VendorSpecificCapabilities element lists any
* capabilities unique to a particular server. Because the
* information is not known a priori, it cannot be constrained
* by this particular schema document. A vendor-specific schema
* fragment must be supplied at the start of the XML capabilities
* document, after the reference to the general WFS_Capabilities
* schema. -->
* <xsd:element ref="wfs:VendorSpecificCapabilities" minOccurs="0"/>
* </xsd:sequence>
* </xsd:complexType>
* </pre>
*
* </p>
*/
private void handleCapability() {
start("Capability");
start("Request");
handleGetCapabilities();
handleDescribeFT();
handleGetFeature();
if (wfs.getServiceLevel() >= WFS.TRANSACTIONAL) {
handleTransaction();
}
if (wfs.getServiceLevel() == WFS.COMPLETE) {
handleLock();
handleFeatureWithLock();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -