📄 capabilitiestransformer.java
字号:
* </p>
* @param ftype The FeatureType configuration to report capabilities
* on.
*
* @throws RuntimeException For any errors.
*/
private void handleFeatureType(FeatureTypeInfo info) {
Envelope bbox = null;
try {
bbox = info.getLatLongBoundingBox();
} catch (IOException e) {
String msg = "Could not calculate bbox for: " + info.getName();
LOGGER.log(Level.SEVERE, msg, e);
return;
}
start("FeatureType");
element("Name", info.getName());
element("Title", info.getTitle());
element("Abstract", info.getAbstract());
handleKeywords(info.getKeywords());
/**
* @task REVISIT: should getSRS() return the full URL?
*/
element("SRS", "EPSG:" + info.getSRS());
String minx = String.valueOf(bbox.getMinX());
String miny = String.valueOf(bbox.getMinY());
String maxx = String.valueOf(bbox.getMaxX());
String maxy = String.valueOf(bbox.getMaxY());
AttributesImpl bboxAtts = new AttributesImpl();
bboxAtts.addAttribute("", "minx", "minx", "", minx);
bboxAtts.addAttribute("", "miny", "miny", "", miny);
bboxAtts.addAttribute("", "maxx", "maxx", "", maxx);
bboxAtts.addAttribute("", "maxy", "maxy", "", maxy);
element("LatLongBoundingBox", null, bboxAtts);
end("FeatureType");
}
/**
* Encodes the ogc:Filter_Capabilities element.
* <p>
* <pre>
* <xsd:element name="Filter_Capabilities">
* <xsd:complexType>
* <xsd:sequence>
* <xsd:element name="Spatial_Capabilities" type="ogc:Spatial_CapabilitiesType"/>
* <xsd:element name="Scalar_Capabilities" type="ogc:Scalar_CapabilitiesType"/>
* </xsd:sequence>
* </xsd:complexType>
*</xsd:element>
* </pre>
* </p>
*/
private void handleFilterCapabilities() {
String ogc = "ogc:";
//REVISIT: for now I"m just prepending ogc onto the name element.
//Is the proper way to only do that for the qname? I guess it
//would only really matter if we're going to be producing capabilities
//documents that aren't qualified, and I don't see any reason to
//do that.
start(ogc + "Filter_Capabilities");
start(ogc + "Spatial_Capabilities");
start(ogc + "Spatial_Operators");
element(ogc + "Disjoint", null);
element(ogc + "Equals", null);
element(ogc + "DWithin", null);
element(ogc + "Beyond", null);
element(ogc + "Intersect", null);
element(ogc + "Touches", null);
element(ogc + "Crosses", null);
element(ogc + "Within", null);
element(ogc + "Contains", null);
element(ogc + "Overlaps", null);
element(ogc + "BBOX", null);
end(ogc + "Spatial_Operators");
end(ogc + "Spatial_Capabilities");
start(ogc + "Scalar_Capabilities");
element(ogc + "Logical_Operators", null);
start(ogc + "Comparison_Operators");
element(ogc + "Simple_Comparisons", null);
element(ogc + "Between", null);
element(ogc + "Like", null);
element(ogc + "NullCheck", null);
end(ogc + "Comparison_Operators");
start(ogc + "Arithmetic_Operators");
element(ogc + "Simple_Arithmetic", null);
handleFunctions(ogc); //djb: list functions
end(ogc + "Arithmetic_Operators");
end(ogc + "Scalar_Capabilities");
end(ogc + "Filter_Capabilities");
}
/**
* <xsd:complexType name="FunctionsType">
* <xsd:sequence>
* <xsd:element name="Function_Names" type="ogc:Function_NamesType"/>
* </xsd:sequence>
* </xsd:complexType>
*
*/
private void handleFunctions(String prefix) {
start(prefix + "Functions");
start(prefix + "Function_Names");
Iterator it = FactoryRegistry.lookupProviders(Function.class);
//Sort them up for easier visual inspection
SortedSet sortedFunctions = new TreeSet(new Comparator() {
public int compare(Object o1, Object o2) {
String n1 = ((Function) o1)
.getName();
String n2 = ((Function) o2).getName();
return n1.toLowerCase().compareTo(n2.toLowerCase());
}
});
while (it.hasNext()) {
sortedFunctions.add(it.next());
}
//write them now that functions are sorted by name
it = sortedFunctions.iterator();
while (it.hasNext()) {
Function fe = (Function) it.next();
//TODO: as of now the geoapi Function interface
// does not allow use to report back properly the number of
// parameters, so we check for instances of FunctionExpression
// for now
if (fe instanceof FunctionExpression) {
String funName = fe.getName();
int funNArgs = ((FunctionExpression) fe).getArgCount();
AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "nArgs", "nArgs", "", funNArgs + "");
element(prefix + "Function_Name", funName, atts);
}
}
end(prefix + "Function_Names");
end(prefix + "Functions");
}
}
}
/**
* Transformer for wfs 1.1 capabilities document.
*
* @author Justin Deoliveira, The Open Planning Project
*
*/
public static class WFS1_1 extends CapabilitiesTransformer {
public WFS1_1(WFS wfs, Data catalog) {
super(wfs, catalog);
}
public Translator createTranslator(ContentHandler handler) {
return new CapabilitiesTranslator1_1(handler);
}
class CapabilitiesTranslator1_1 extends TranslatorSupport {
GetCapabilitiesType request;
public CapabilitiesTranslator1_1(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 = attributes(new String[] {
"version", "1.1.0", "xmlns:xsi", XSI_URI, "xmlns", WFS_URI, "xmlns:wfs",
WFS_URI, "xmlns:ows", OWS.NAMESPACE, "xmlns:gml", GML.NAMESPACE,
"xmlns:ogc", OGC.NAMESPACE, "xmlns:xlink", XLINK.NAMESPACE,
"xsi:schemaLocation",
org.geoserver.wfs.xml.v1_1_0.WFS.NAMESPACE + " "
+ ResponseUtils.appendPath(proxifiedBaseUrl, "schemas/wfs/1.1.0/wfs.xsd")
});
NameSpaceInfo[] namespaces = catalog.getNameSpaces();
for (int i = 0; i < namespaces.length; i++) {
NameSpaceInfo namespace = namespaces[i];
String prefix = namespace.getPrefix();
String uri = namespace.getURI();
//ignore xml prefix
if ("xml".equals(prefix)) {
continue;
}
String prefixDef = "xmlns:" + prefix;
attributes.addAttribute("", prefixDef, prefixDef, "", uri);
}
start("wfs:WFS_Capabilities", attributes);
serviceIdentification();
serviceProvider();
operationsMetadata();
featureTypeList();
//supportsGMLObjectTypeList();
filterCapabilities();
end("wfs:WFS_Capabilities");
}
/**
* Encodes the ows:ServiceIdentification element.
* <p>
* <pre>
* <complexType>
* <complexContent>
* <extension base="ows:DescriptionType">
* <sequence>
* <element name="ServiceType" type="ows:CodeType">
* <annotation>
* <documentation>A service type name from a registry of services.
* For example, the values of the codeSpace URI and name and code string may
* be "OGC" and "catalogue." This type name is normally used for
* machine-to-machine communication.</documentation>
* </annotation>
* </element>
* <element name="ServiceTypeVersion" type="ows:VersionType" maxOccurs="unbounded">
* <annotation>
* <documentation>Unordered list of one or more versions of this service
* type implemented by this server. This information is not adequate for
* version negotiation, and shall not be used for that purpose. </documentation>
* </annotation>
* </element>
* <element ref="ows:Fees" minOccurs="0">
* <annotation>
* <documentation>If this element is omitted, no meaning is implied. </documentation>
* </annotation>
* </element>
* <element ref="ows:AccessConstraints" minOccurs="0" maxOccurs="unbounded">
* <annotation>
* <documentation>Unordered list of access constraints applied to assure
* the protection of privacy or intellectual property, and any other
* restrictions on retrieving or using data from or otherwise using this
* server. The reserved value NONE (case insensitive) shall be used to
* mean no access constraints are imposed. If this element is omitted,
* no meaning is implied. </documentation>
* </annotation>
* </element>
* </sequence>
* </extension>
* </complexContent>
*</complexType>
* </pre>
* </p>
*
*/
void serviceIdentification() {
start("ows:ServiceIdentification");
element("ows:Title", wfs.getTitle());
element("ows:Abstract", wfs.getAbstract());
keywords(wfs.getKeywords());
element("ows:ServiceType", "WFS");
element("ows:ServiceTypeVersion", "1.1.0");
element("ows:Fees", wfs.getFees());
element("ows:AccessConstraints", wfs.getAccessConstraints());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -