001: /* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
002: * This code is licensed under the GPL 2.0 license, availible at the root
003: * application directory.
004: */
005: package org.vfny.geoserver.form.data;
006:
007: import org.apache.struts.Globals;
008: import org.apache.struts.action.ActionError;
009: import org.apache.struts.action.ActionErrors;
010: import org.apache.struts.action.ActionForm;
011: import org.apache.struts.action.ActionMapping;
012: import org.apache.struts.util.MessageResources;
013: import org.vfny.geoserver.action.HTMLEncoder;
014: import org.vfny.geoserver.config.ConfigRequests;
015:
016: import java.util.Collections;
017: import java.util.List;
018: import java.util.Locale;
019: import javax.servlet.http.HttpServletRequest;
020:
021: /**
022: * Select current DataStore for edit or delete Action.
023: *
024: * @author rgould, Refractions Research, Inc.
025: * @author $Author: emperorkefka $ (last modification)
026: * @author bowens, TOPP
027: * @version $Id: DataDataStoresSelectForm.java 7234 2007-07-12 14:13:07Z aaime $
028: */
029: public class DataDataStoresSelectForm extends ActionForm {
030: /** Action that spawned us must be "edit" or "delete" */
031: private String buttonAction;
032:
033: /** Selection from list - will be a dataStoreId */
034: private String selectedDataStoreId;
035: private List dataStoreIds;
036:
037: /**
038: * Reset form
039: *
040: * @param mapping DOCUMENT ME!
041: * @param request DOCUMENT ME!
042: */
043: public void reset(ActionMapping mapping, HttpServletRequest request) {
044: super .reset(mapping, request);
045:
046: // Pass data from congif layer to screen
047: dataStoreIds = ConfigRequests.getDataConfig(request)
048: .listDataStoreIds();
049: Collections.sort(dataStoreIds);
050:
051: // Usual reset stuff
052: selectedDataStoreId = null; // nothing selected yet
053: buttonAction = null; // updated when user submits form
054: }
055:
056: /**
057: * Validate as required
058: *
059: * @param mapping DOCUMENT ME!
060: * @param request DOCUMENT ME!
061: *
062: * @return DOCUMENT ME!
063: */
064: public ActionErrors validate(ActionMapping mapping,
065: HttpServletRequest request) {
066: ActionErrors errors = new ActionErrors();
067:
068: Locale locale = (Locale) request.getLocale();
069:
070: //MessageResources messages = servlet.getResources();
071: //TODO: not sure about this, changed for struts 1.2.8 upgrade
072: MessageResources messages = (MessageResources) request
073: .getAttribute(Globals.MESSAGES_KEY);
074: String EDIT = HTMLEncoder.decode(messages.getMessage(locale,
075: "label.edit"));
076: String DELETE = HTMLEncoder.decode(messages.getMessage(locale,
077: "label.delete"));
078:
079: if (getSelectedDataStoreId() == null) {
080: return errors; // no data in the list, so return
081: }
082:
083: if (!getDataStoreIds().contains(getSelectedDataStoreId())) {
084: errors
085: .add("selectedDataStoreId", new ActionError(
086: "errors.factory.invalid",
087: getSelectedDataStoreId()));
088: }
089:
090: if (!DELETE.equals(getButtonAction())
091: && !EDIT.equals(getButtonAction())) {
092: errors.add("buttonAction", new ActionError(
093: "errors.buttonAction.invalid", getButtonAction()));
094: }
095:
096: return errors;
097: }
098:
099: /**
100: * List of current DataStoreIds
101: *
102: * @return DOCUMENT ME!
103: */
104: public List getDataStoreIds() {
105: return dataStoreIds;
106: }
107:
108: /**
109: * DataStoreID selected by User.
110: *
111: * <p>
112: * If the user has not selected anything (is this possible?) we will return
113: * <code>null</code>.
114: * </p>
115: *
116: * @return Selected DataStoreID or <code>null</code> if nothing is selected
117: */
118: public String getSelectedDataStoreId() {
119: return selectedDataStoreId;
120: }
121:
122: /**
123: * The button the user hit to submit this form.
124: *
125: * <p>
126: * We are doubling up and having the Same action process both Edit and
127: * Delete.
128: * </p>
129: *
130: * @return Either <code>edit</code> or <code>delete</code>
131: */
132: public String getButtonAction() {
133: return buttonAction;
134: }
135:
136: public void setButtonAction(String string) {
137: buttonAction = string;
138: }
139:
140: public void setSelectedDataStoreId(String string) {
141: selectedDataStoreId = string;
142: }
143: }
|