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: import java.util.List;
016: import java.util.Locale;
017: import javax.servlet.http.HttpServletRequest;
018:
019: /**
020: * Select current DataFormat for edit or delete Action.
021: *
022: *
023: * @author $Author: Alessio Fabiani (alessio.fabiani@gmail.com) $ (last
024: * modification)
025: * @author $Author: Simone Giannecchini (simboss1@gmail.com) $ (last
026: * modification)
027: */
028: public final class CoverageStoresSelectForm extends ActionForm {
029: /**
030: *
031: */
032: private static final long serialVersionUID = 950236665044594046L;
033:
034: /**
035: * Action that spawned us must be "edit" or "delete"
036: */
037: private String buttonAction;
038:
039: /**
040: * Selection from list - will be a dataFormatId
041: */
042: private String selectedDataFormatId;
043:
044: /**
045: *
046: */
047: private List dataFormatIds;
048:
049: /**
050: * Reset form
051: *
052: * @param mapping
053: * DOCUMENT ME!
054: * @param request
055: * DOCUMENT ME!
056: */
057: public void reset(ActionMapping mapping, HttpServletRequest request) {
058: super .reset(mapping, request);
059:
060: // Pass data from congif layer to screen
061: // REVIST: Bad Design JSP should lookup data itself!
062: dataFormatIds = ConfigRequests.getDataConfig(request)
063: .listDataFormatIds();
064:
065: // Usual reset stuff
066: selectedDataFormatId = null; // nothing selected yet
067: buttonAction = null; // updated when user submits form
068: }
069:
070: /**
071: * Validate as required
072: *
073: * @param mapping
074: * DOCUMENT ME!
075: * @param request
076: * DOCUMENT ME!
077: *
078: * @return DOCUMENT ME!
079: */
080: public ActionErrors validate(ActionMapping mapping,
081: HttpServletRequest request) {
082: ActionErrors errors = new ActionErrors();
083:
084: Locale locale = (Locale) request.getLocale();
085: MessageResources messages = (MessageResources) request
086: .getAttribute(Globals.MESSAGES_KEY);
087: String EDIT = HTMLEncoder.decode(messages.getMessage(locale,
088: "label.edit"));
089: String DELETE = HTMLEncoder.decode(messages.getMessage(locale,
090: "label.delete"));
091:
092: if (!getDataFormatIds().contains(getSelectedDataFormatId())) {
093: errors.add("selectedDataFormatId",
094: new ActionError("errors.factory.invalid",
095: getSelectedDataFormatId()));
096: }
097:
098: if (!DELETE.equals(getButtonAction())
099: && !EDIT.equals(getButtonAction())) {
100: errors.add("buttonAction", new ActionError(
101: "errors.buttonAction.invalid", getButtonAction()));
102: }
103:
104: return errors;
105: }
106:
107: /**
108: * List of current DataFormatIds
109: *
110: * @return DOCUMENT ME!
111: */
112: public List getDataFormatIds() {
113: return dataFormatIds;
114: }
115:
116: /**
117: * DataFormatID selected by User.
118: *
119: * <p>
120: * If the user has not selected anything (is this possible?) we will return
121: * <code>null</code>.
122: * </p>
123: *
124: * @return Selected DataFormatID or <code>null</code> if nothing is
125: * selected
126: */
127: public String getSelectedDataFormatId() {
128: return selectedDataFormatId;
129: }
130:
131: /**
132: * The button the user hit to submit this form.
133: *
134: * <p>
135: * We are doubling up and having the Same action process both Edit and
136: * Delete.
137: * </p>
138: *
139: * @return Either <code>edit</code> or <code>delete</code>
140: */
141: public String getButtonAction() {
142: return buttonAction;
143: }
144:
145: /**
146: *
147: */
148: public void setButtonAction(String string) {
149: buttonAction = string;
150: }
151:
152: /**
153: *
154: */
155: public void setSelectedDataFormatId(String string) {
156: selectedDataFormatId = string;
157: }
158: }
|