📄 coverageseditorform.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.form.data;
import org.apache.struts.Globals;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.config.ControllerConfig;
import org.apache.struts.upload.CommonsMultipartRequestHandler;
import org.apache.struts.upload.MultipartRequestHandler;
import org.apache.struts.util.MessageResources;
import org.geotools.coverage.grid.io.AbstractGridFormat;
import org.geotools.geometry.GeneralEnvelope;
import org.geotools.referencing.CRS;
import org.opengis.coverage.grid.Format;
import org.opengis.parameter.ParameterValue;
import org.opengis.parameter.ParameterValueGroup;
import org.vfny.geoserver.action.HTMLEncoder;
import org.vfny.geoserver.config.ConfigRequests;
import org.vfny.geoserver.config.CoverageConfig;
import org.vfny.geoserver.config.CoverageStoreConfig;
import org.vfny.geoserver.config.DataConfig;
import org.vfny.geoserver.config.StyleConfig;
import org.vfny.geoserver.global.UserContainer;
import org.vfny.geoserver.util.CoverageStoreUtils;
import org.vfny.geoserver.util.CoverageUtils;
import org.vfny.geoserver.util.Requests;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.SortedSet;
import java.util.TreeSet;
import javax.servlet.http.HttpServletRequest;
/**
* DOCUMENT ME!
*
* @author $Author: Alessio Fabiani (alessio.fabiani@gmail.com) $ (last
* modification)
* @author $Author: Simone Giannecchini (simboss1@gmail.com) $ (last
* modification)
*/
public final class CoveragesEditorForm extends ActionForm {
/**
*
*/
private static final long serialVersionUID = 1831907046971087321L;
/**
*
*/
private String formatId;
/**
* Identify Style used to render this feature type
*/
private String styleId;
/** Sorted Set of available styles */
private SortedSet panelStyleIds;
private SortedSet typeStyles;
private String[] otherSelectedStyles;
/**
*
*/
private String name;
/**
*
*/
private String wmsPath;
/**
*
*/
private String label;
/**
*
*/
private String description;
/**
*
*/
private String metadataLink;
private String boundingBoxMinX;
private String boundingBoxMinY;
private String boundingBoxMaxX;
private String boundingBoxMaxY;
/**
*
*/
private String keywords;
/**
* Sorted Set of available styles
*/
private SortedSet styles;
/**
*
*/
private String srsName;
/**
*
*/
private String nativeCRS;
/**
*
*/
private String WKTString;
/**
*
*/
private String requestCRSs;
/**
*
*/
private String responseCRSs;
/**
*
*/
private String nativeFormat;
/**
*
*/
private String supportedFormats;
/**
*
*/
private String defaultInterpolationMethod;
/**
*
*/
private String interpolationMethods;
/**
* Action requested by user
*/
private String action;
/**
*
*/
private String newCoverage;
private List paramHelp;
private List paramKeys;
private List paramValues;
/**
* Set up CoverageEditor from from Web Container.
*
* <p>
* The key DataConfig.SELECTED_COVERAGE is used to look up the selected from
* the web container.
* </p>
*
* @param mapping
* @param request
*/
public void reset(ActionMapping mapping, HttpServletRequest request) {
super.reset(mapping, request);
// //
//
//
//
// //
action = "";
newCoverage = "";
final DataConfig config = ConfigRequests.getDataConfig(request);
final UserContainer user = Requests.getUserContainer(request);
final CoverageConfig type = user.getCoverageConfig();
if (type == null) {
// TODO Not sure what to do, user must have bookmarked?
return; // Action should redirect to Select screen?
}
this.formatId = type.getFormatId();
this.styleId = type.getDefaultStyle();
// //
//
//
//
// //
final CoverageConfig cvConfig = (CoverageConfig) request.getSession()
.getAttribute(DataConfig.SELECTED_COVERAGE);
final GeneralEnvelope bounds = cvConfig.getEnvelope();
if (bounds.isNull()) {
boundingBoxMinX = "";
} else {
boundingBoxMinX = Double.toString(bounds.getLowerCorner().getOrdinate(0));
boundingBoxMinY = Double.toString(bounds.getLowerCorner().getOrdinate(1));
boundingBoxMaxX = Double.toString(bounds.getUpperCorner().getOrdinate(0));
boundingBoxMaxY = Double.toString(bounds.getUpperCorner().getOrdinate(1));
}
// //
//
//
//
// //
srsName = cvConfig.getSrsName();
WKTString = cvConfig.getSrsWKT();
// //
//
//
//
// //
name = cvConfig.getName();
wmsPath = cvConfig.getWmsPath();
label = cvConfig.getLabel();
description = cvConfig.getDescription();
metadataLink = ((cvConfig.getMetadataLink() != null)
? cvConfig.getMetadataLink().getAbout() : null);
nativeFormat = cvConfig.getNativeFormat();
defaultInterpolationMethod = cvConfig.getDefaultInterpolationMethod();
// //
//
//
//
// //
StringBuffer buf = new StringBuffer();
// Keywords
if (cvConfig.getKeywords() != null) {
String keyword;
for (Iterator i = cvConfig.getKeywords().iterator(); i.hasNext();) {
keyword = (String) i.next();
buf.append(keyword);
if (i.hasNext()) {
buf.append(" ");
}
}
this.keywords = buf.toString();
}
// //
//
//
//
// //
if (cvConfig.getRequestCRSs() != null) {
buf = new StringBuffer();
// RequestCRSs
String CRS;
for (Iterator i = cvConfig.getRequestCRSs().iterator(); i.hasNext();) {
CRS = (String) i.next();
buf.append(CRS.toUpperCase());
if (i.hasNext()) {
buf.append(",");
}
}
this.requestCRSs = buf.toString();
}
// //
//
//
//
// //
if (cvConfig.getResponseCRSs() != null) {
buf = new StringBuffer();
// ResponseCRSs
String CRS;
for (Iterator i = cvConfig.getResponseCRSs().iterator(); i.hasNext();) {
CRS = (String) i.next();
buf.append(CRS.toUpperCase());
if (i.hasNext()) {
buf.append(",");
}
}
this.responseCRSs = buf.toString();
}
// //
//
//
//
// //
if (cvConfig.getSupportedFormats() != null) {
buf = new StringBuffer();
// SupportedFormats
String format;
for (Iterator i = cvConfig.getSupportedFormats().iterator(); i.hasNext();) {
format = (String) i.next();
buf.append(format.toUpperCase());
if (i.hasNext()) {
buf.append(",");
}
}
this.supportedFormats = buf.toString();
}
// //
//
//
//
// //
if (cvConfig.getInterpolationMethods() != null) {
buf = new StringBuffer();
// InterpolationMethods
String intMethod;
for (Iterator i = cvConfig.getInterpolationMethods().iterator(); i.hasNext();) {
intMethod = (String) i.next();
buf.append(intMethod.toLowerCase());
if (i.hasNext()) {
buf.append(",");
}
}
this.interpolationMethods = buf.toString();
}
// //
//
//
//
// //
styles = new TreeSet();
StyleConfig sc;
for (Iterator i = config.getStyles().values().iterator(); i.hasNext();) {
sc = (StyleConfig) i.next();
styles.add(sc.getId());
if (sc.isDefault()) {
if ((styleId == null) || "".equals(styleId)) {
styleId.equals(sc.getId());
}
}
}
typeStyles = new TreeSet();
for (Iterator i = type.getStyles().iterator(); i.hasNext();) {
String styleName = (String) i.next();
typeStyles.add(styleName);
}
if (styles instanceof org.vfny.geoserver.form.data.AttributeDisplay) {
// TODO why I am here?
}
/**
* Sync params
*/
Iterator it = type.getParameters().keySet().iterator();
String paramKey;
String paramValue;
List paramHelp = new ArrayList();
List paramKeys = new ArrayList();
List paramValues = new ArrayList();
while (it.hasNext()) {
paramKey = (String) it.next();
paramValue = (String) type.getParameters().get(paramKey);
paramHelp.add(paramKey);
paramKeys.add(paramKey);
paramValues.add(paramValue);
}
this.paramHelp = paramHelp;
this.paramKeys = paramKeys;
this.paramValues = paramValues;
}
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
Locale locale = (Locale) request.getLocale();
MessageResources messages = (MessageResources) request.getAttribute(Globals.MESSAGES_KEY);
final String ENVELOPE = HTMLEncoder.decode(messages.getMessage(locale,
"config.data.calculateBoundingBox.label"));
final String LOOKUP_SRS = HTMLEncoder.decode(messages.getMessage(locale,
"config.data.lookupSRS.label"));
// Pass Attribute Management Actions through without
// much validation.
if (action.startsWith("Up") || action.startsWith("Down") || action.startsWith("Remove")
|| ENVELOPE.equals(action)) {
return errors;
}
DataConfig data = ConfigRequests.getDataConfig(request);
// Check selected style exists
if (!(data.getStyles().containsKey(styleId) || "".equals(styleId))) {
errors.add("styleId", new ActionError("error.styleId.notFound", styleId));
}
// //
//
//
//
// //
if (!LOOKUP_SRS.equals(action)) {
if(!srsName.toUpperCase().startsWith("EPSG:")) {
srsName = "EPSG:" + srsName;
}
try {
CRS.decode(srsName);
} catch(Exception e) {
errors.add("envelope", new ActionError("config.data.coverage.srs", srsName));
}
}
// //
//
//
//
// //
if ("".equals(boundingBoxMinX) || "".equals(boundingBoxMinY) || "".equals(boundingBoxMaxX)
|| "".equals(boundingBoxMaxY)) {
errors.add("envelope", new ActionError("error.envelope.required"));
} else {
try {
Double.parseDouble(boundingBoxMinX);
Double.parseDouble(boundingBoxMinY);
Double.parseDouble(boundingBoxMaxX);
Double.parseDouble(boundingBoxMaxY);
} catch (NumberFormatException badNumber) {
errors.add("envelope", new ActionError("error.envelope.invalid", badNumber));
}
}
// //
//
//
//
// //
if ("".equals(name)) {
errors.add("name", new ActionError("error.coverage.name.required"));
} else if (name.indexOf(" ") > 0) {
errors.add("name", new ActionError("error.coverage.name.invalid"));
}
// //
//
//
//
// //
final DataConfig dataConfig = getDataConfig(request);
final CoverageStoreConfig cvConfig = dataConfig.getDataFormat(formatId);
if (cvConfig == null) {
// something is horribly wrong no FormatID selected!
// The JSP needs to not include us if there is no
// selected Format
//
throw new RuntimeException("selectedDataFormatId required in Session");
}
// Retrieve connection params
final Format factory = cvConfig.getFactory();
final ParameterValueGroup info = factory.getReadParameters();
final Map connectionParams = new HashMap();
// Convert Params into the kind of Map we actually need
//
if (paramKeys != null) {
Boolean maxSize;
String size = null;
ControllerConfig cc;
Object value;
String key;
ParameterValue param;
final int length = paramKeys.size();
final String readGeometryKey = AbstractGridFormat.READ_GRIDGEOMETRY2D.getName()
.toString();
for (int i = 0; i < length; i++) {
key = (String) getParamKey(i);
// //
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -