📄 wcscapstransformer.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.vfny.geoserver.wcs.responses;
import org.geoserver.ows.util.RequestUtils;
import org.geotools.geometry.GeneralEnvelope;
import org.geotools.xml.transform.TransformerBase;
import org.geotools.xml.transform.Translator;
import org.vfny.geoserver.global.CoverageInfo;
import org.vfny.geoserver.global.CoverageInfoLabelComparator;
import org.vfny.geoserver.global.MetaDataLink;
import org.vfny.geoserver.global.Service;
import org.vfny.geoserver.global.WCS;
import org.vfny.geoserver.util.requests.CapabilitiesRequest;
import org.vfny.geoserver.wcs.requests.WCSRequest;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.logging.Logger;
/**
* DOCUMENT ME!
*
* @author $Author: Alessio Fabiani (alessio.fabiani@gmail.com) $ (last
* modification)
* @author $Author: Simone Giannecchini (simboss1@gmail.com) $ (last
* modification)
*/
public class WCSCapsTransformer extends TransformerBase {
/** DOCUMENT ME! */
private static final Logger LOGGER = org.geotools.util.logging.Logging.getLogger(WCSCapsTransformer.class.getPackage()
.getName());
protected static final String WCS_URI = "http://www.opengis.net/wcs";
/** DOCUMENT ME! */
protected static final String WFS_URI = "http://www.opengis.net/wcs";
/** DOCUMENT ME! */
protected static final String CUR_VERSION = "1.0.0";
/** DOCUMENT ME! */
protected static final String XSI_PREFIX = "xsi";
/** DOCUMENT ME! */
protected static final String XSI_URI = "http://www.w3.org/2001/XMLSchema-instance";
/**
* DOCUMENT ME!
*
* @uml.property name="request"
* @uml.associationEnd multiplicity="(0 1)"
*/
protected WCSRequest request;
/**
* Creates a new WFSCapsTransformer object.
*/
public WCSCapsTransformer() {
super();
setNamespaceDeclarationEnabled(false);
}
/**
* DOCUMENT ME!
*
* @param handler
* DOCUMENT ME!
*
* @return DOCUMENT ME!
*/
public Translator createTranslator(ContentHandler handler) {
return new WCSCapsTranslator(handler);
}
/**
* DOCUMENT ME!
*
* @author Gabriel Roldan, Axios Engineering
* @version $Id
*/
private static class WCSCapsTranslator extends TranslatorSupport {
/**
* DOCUMENT ME!
*
* @uml.property name="request"
* @uml.associationEnd multiplicity="(0 1)"
*/
private CapabilitiesRequest request;
/**
* Creates a new WFSCapsTranslator object.
*
* @param handler
* DOCUMENT ME!
*/
public WCSCapsTranslator(ContentHandler handler) {
super(handler, null, null);
}
/**
* Encode the object.
*
* @param o
* The Object to encode.
*
* @throws IllegalArgumentException
* if the Object is not encodeable.
*/
public void encode(Object o) throws IllegalArgumentException {
if (!(o instanceof CapabilitiesRequest)) {
throw new IllegalArgumentException(new StringBuffer("Not a CapabilitiesRequest: ").append(
o).toString());
}
this.request = (CapabilitiesRequest) o;
final AttributesImpl attributes = new AttributesImpl();
attributes.addAttribute("", "version", "version", "", CUR_VERSION);
attributes.addAttribute("", "xmlns", "xmlns", "", WCS_URI);
attributes.addAttribute("", "xmlns:xlink", "xmlns:xlink", "",
"http://www.w3.org/1999/xlink");
attributes.addAttribute("", "xmlns:ogc", "xmlns:ogc", "", "http://www.opengis.net/ogc");
attributes.addAttribute("", "xmlns:gml", "xmlns:gml", "", "http://www.opengis.net/gml");
final String prefixDef = new StringBuffer("xmlns:").append(XSI_PREFIX).toString();
attributes.addAttribute("", prefixDef, prefixDef, "", XSI_URI);
final String locationAtt = new StringBuffer(XSI_PREFIX).append(":schemaLocation")
.toString();
final String locationDef = WCS_URI + " "
+ RequestUtils.schemaBaseURL(request.getHttpServletRequest())
+ "wcs/1.0.0/wcsCapabilities.xsd";
attributes.addAttribute("", locationAtt, locationAtt, "", locationDef);
start("WCS_Capabilities", attributes);
handleService();
handleCapabilities();
end("WCS_Capabilities");
}
/**
* Handles the service section of the capabilities document.
*
* @param config
* The OGC service to transform.
*
* @throws SAXException
* For any errors.
*/
private void handleService() {
final WCS wcs = (WCS) request.getServiceRef().getServiceRef();
AttributesImpl attributes = new AttributesImpl();
attributes.addAttribute("", "version", "version", "", CUR_VERSION);
start("Service", attributes);
handleMetadataLink(wcs.getMetadataLink());
element("description", wcs.getAbstract());
element("name", wcs.getName());
element("label", wcs.getTitle());
handleKeywords(wcs.getKeywords());
handleContact(wcs);
String fees = wcs.getFees();
if ((fees == null) || "".equals(fees)) {
fees = "NONE";
}
element("fees", fees);
String accessConstraints = wcs.getAccessConstraints();
if ((accessConstraints == null) || "".equals(accessConstraints)) {
accessConstraints = "NONE";
}
element("accessConstraints", accessConstraints);
end("Service");
}
/**
* DOCUMENT ME!
*
* @param serviceConfig
* DOCUMENT ME!
*
* @throws SAXException
* DOCUMENT ME!
*/
private void handleCapabilities() {
final WCS wcs = (WCS) request.getServiceRef().getServiceRef();
start("Capability");
handleRequest(wcs);
handleExceptions(wcs);
handleVendorSpecifics(wcs);
end("Capability");
handleContentMetadata(wcs);
}
/**
* Handles the request portion of the document, printing out the
* capabilities and where to bind to them.
*
* @param config
* The global wms.
*
* @throws SAXException
* For any problems.
*/
private void handleRequest(WCS config) {
start("Request");
handleCapability(config, "GetCapabilities");
handleCapability(config, "DescribeCoverage");
handleCapability(config, "GetCoverage");
end("Request");
}
private void handleCapability(WCS config, String capabilityName) {
AttributesImpl attributes = new AttributesImpl();
start(capabilityName);
start("DCPType");
start("HTTP");
String url = "";
String baseUrl = request.getBaseUrl() + "wcs";
if (request.isDispatchedRequest()) {
url = new StringBuffer(baseUrl).append("?").toString();
} else {
url = new StringBuffer(baseUrl).append("/").append(capabilityName).append("?")
.toString();
}
attributes.addAttribute("", "xlink:href", "xlink:href", "", url);
start("Get");
start("OnlineResource", attributes);
end("OnlineResource");
end("Get");
end("HTTP");
end("DCPType");
attributes = new AttributesImpl();
if (request.isDispatchedRequest()) {
url = baseUrl;
} else {
url = new StringBuffer(baseUrl).append("/").append(capabilityName).toString();
}
attributes.addAttribute("", "xlink:href", "xlink:href", "", url);
start("DCPType");
start("HTTP");
start("Post");
start("OnlineResource", attributes);
end("OnlineResource");
end("Post");
end("HTTP");
end("DCPType");
end(capabilityName);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -