📄 typeseditoraction.java
字号:
e.getAuthorityCode()));
saveErrors(request, errors);
return mapping.findForward("config.data.type.editor");
} catch (FactoryException fe) {
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine(fe.getLocalizedMessage());
LOGGER.fine(fe.getStackTrace().toString());
}
ActionErrors errors = new ActionErrors();
errors.add(ActionErrors.GLOBAL_ERROR,
new ActionError("error.data.factoryException", fe.getLocalizedMessage()));
saveErrors(request, errors);
return mapping.findForward("config.data.type.editor");
} catch (TransformException te) {
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine(te.getLocalizedMessage());
LOGGER.fine(te.getStackTrace().toString());
}
ActionErrors errors = new ActionErrors();
errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.data.transformException"));
saveErrors(request, errors);
return mapping.findForward("config.data.type.editor");
} finally {
if(dataStore != null) dataStore.dispose();
}
return mapping.findForward("config.data.type.editor");
}
/**
* Sync generated attributes with schemaBase.
*
* @param form
* @param config
*/
private void sync(TypesEditorForm form, FeatureTypeConfig config, HttpServletRequest request) {
config.setName(form.getTypeName());
config.setAbstract(form.getAbstract());
config.setDefaultStyle(form.getStyleId());
if (form.getOtherSelectedStyles() != null) {
config.getStyles().clear();
for (int i = 0; i < form.getOtherSelectedStyles().length; i++) {
config.addStyle(form.getOtherSelectedStyles()[i]);
}
}
config.setSRS(Integer.parseInt(form.getSRS()));
config.setTitle(form.getTitle());
Envelope latLonBbox = getBoundingBox(form);
Envelope nativeBbox = getNativeBBox(form);
// if the lat/lon bbox did not change, don't try to update stuff, since we don't have
// the native bbox calculated
if(!config.getLatLongBBox().equals(latLonBbox)) {
config.setLatLongBBox(latLonBbox);
}
// may the native bbox have been changed due to a change
// in the CRS code by the user
if(!config.getNativeBBox().equals(nativeBbox)){
config.setNativeBBox(nativeBbox);
}
config.setKeywords(keyWords(form));
config.setMetadataLinks(metadataLinks(form));
config.setWmsPath(form.getWmsPath());
config.setCacheMaxAge(form.getCacheMaxAge());
config.setCachingEnabled(form.isCachingEnabled());
config.setSRSHandling(form.getSrsHandlingCode());
if (!form.isCachingEnabledChecked()) {
config.setCachingEnabled(false);
}
String schemaBase = form.getSchemaBase();
if ((schemaBase == null) || schemaBase.equals("") || schemaBase.equals("--")) {
config.setSchemaBase(null);
config.setSchemaName(null);
config.setSchemaAttributes(null);
} else {
config.setSchemaBase(schemaBase);
String schemaName = config.getSchemaName();
List schemaAttributes = config.getSchemaAttributes();
System.out.println("in non null sb, sname: " + schemaName + ", satts: "
+ schemaAttributes);
if ((schemaName == null) || (schemaName.trim().length() == 0)) {
schemaName = form.getTypeName() + "_Type";
//HACK: For some reason only when editing an already exisitng
//featureType, on the first time of switching to the editor
//it gets a full schemaAttribute list, and I can't find where
//so for now we are just relying on schemaName being null or
schemaAttributes = null;
//System.out.println("testing on schemaAtts: " + schemaAttributes);
config.setSchemaName(schemaName);
} else {
config.setSchemaName(form.getSchemaName());
}
if ((schemaAttributes == null) || schemaAttributes.isEmpty()) {
schemaAttributes = new ArrayList();
List createList = form.getCreateableAttributes();
System.out.println("schemaAtts null, createList: " + createList);
FeatureType fType = getFeatureType(form, request);
for (int i = 0; i < fType.getAttributeCount(); i++) {
AttributeType attType = fType.getAttributeType(i);
AttributeTypeInfoConfig attributeConfig = new AttributeTypeInfoConfig(attType);
schemaAttributes.add(attributeConfig);
//new ArrayList();
//DataStoreConfig dsConfig = config.
//FeatureType featureType = config.get
}
config.setSchemaAttributes(schemaAttributes);
} else {
config.setSchemaAttributes(form.toSchemaAttributes());
}
}
// config.setSchemaAttributes(form.toSchemaAttributes());
LOGGER.fine("config schema atts is " + config.getSchemaAttributes());
//config.setSchemaAttributes(form.toSchemaAttributes());
}
private void executeAdd(ActionMapping mapping, TypesEditorForm form, UserContainer user,
HttpServletRequest request) {
String attributeName = form.getNewAttribute();
FeatureType fType = getFeatureType(form, request);
AttributeForm newAttribute = newAttributeForm(attributeName, fType);
form.getAttributes().add(newAttribute);
}
private AttributeForm newAttributeForm(String attributeName, FeatureType featureType) {
AttributeType attributeType = featureType.getAttributeType(attributeName);
AttributeTypeInfoConfig attributeConfig = new AttributeTypeInfoConfig(attributeType);
AttributeForm newAttribute = new AttributeForm(attributeConfig, attributeType);
return newAttribute;
}
private FeatureType getFeatureType(TypesEditorForm form, HttpServletRequest request) {
FeatureType featureType = null;
DataStore dataStore = null;
try {
DataConfig config = ConfigRequests.getDataConfig(request);
DataStoreConfig dataStoreConfig = config.getDataStore(form.getDataStoreId());
dataStore = dataStoreConfig.findDataStore(getServlet().getServletContext());
featureType = dataStore.getSchema(form.getTypeName());
} catch (IOException e) {
// DataStore unavailable!
} finally {
if(dataStore != null) dataStore.dispose();
}
return featureType;
}
/**
* Execute Submit Action.
*
* @param mapping
* @param form
* @param user
* @param request
*
* @return
*/
private ActionForward executeSubmit(ActionMapping mapping, TypesEditorForm form,
UserContainer user, HttpServletRequest request) {
FeatureTypeConfig config = user.getFeatureTypeConfig();
sync(form, config, request);
DataConfig dataConfig = (DataConfig) getDataConfig();
dataConfig.addFeatureType(config.getDataStoreId() + ":" + config.getName(), config);
// Don't think reset is needed (as me have moved on to new page)
// form.reset(mapping, request);
getApplicationState().notifyConfigChanged();
// Feature no longer selected
user.setFeatureTypeConfig(null);
return mapping.findForward("config.data.type");
}
/**
* DOCUMENT ME!
*
* @param typeForm
*
* @return Bounding box in lat long
*/
private Envelope getBoundingBox(TypesEditorForm typeForm) {
return new Envelope(Double.parseDouble(typeForm.getMinX()),
Double.parseDouble(typeForm.getMaxX()), Double.parseDouble(typeForm.getMinY()),
Double.parseDouble(typeForm.getMaxY()));
}
/**
* DOCUMENT ME!
*
* @param typeForm
*
* @return Bounding box in lat long
*/
private Envelope getNativeBBox(TypesEditorForm typeForm) {
// here, we try to use the native bbox computed during "generate", but if the
// user specified the bbox by hand, we have to resort to back-project the lat/lon one
try {
return new Envelope(Double.parseDouble(typeForm.getDataMinX()),
Double.parseDouble(typeForm.getDataMaxX()), Double.parseDouble(typeForm.getDataMinY()),
Double.parseDouble(typeForm.getDataMaxY()));
} catch(NumberFormatException e) {
return null;
}
}
/**
* DOCUMENT ME!
*
* @param typeForm
*
* @return Set of keywords
*/
private Set keyWords(TypesEditorForm typeForm) {
HashSet keywords = new HashSet();
String[] array = (typeForm.getKeywords() != null)
? typeForm.getKeywords().split(System.getProperty("line.separator")) : new String[0];
for (int i = 0; i < array.length; i++) {
keywords.add(array[i]);
}
return keywords;
}
private Set metadataLinks(TypesEditorForm typeForm) {
HashSet links = new HashSet();
MetaDataLink link = getLink(typeForm, 0);
if (link != null) {
links.add(link);
}
link = getLink(typeForm, 1);
if (link != null) {
links.add(link);
}
return links;
}
private MetaDataLink getLink(TypesEditorForm typeForm, int index) {
MetaDataLink link = typeForm.getMetadataLink(index);
if ((link.getContent() == null) || link.getContent().trim().equals("")) {
return null;
}
return link;
}
DataStore aquireDataStore(String dataStoreID) throws IOException {
DataConfig dataConfig = getDataConfig();
DataStoreConfig dataStoreConfig = dataConfig.getDataStore(dataStoreID);
Map params = dataStoreConfig.getConnectionParams();
return DataStoreUtils.getDataStore(params);
}
FeatureType getSchema(String dataStoreID, String typeName)
throws IOException {
DataStore dataStore = null;
try {
dataStore = aquireDataStore(dataStoreID);
return dataStore.getSchema(typeName);
} finally {
if(dataStore != null) dataStore.dispose();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -