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.action.ActionError;
008: import org.apache.struts.action.ActionErrors;
009: import org.apache.struts.action.ActionForm;
010: import org.apache.struts.action.ActionMapping;
011: import org.vfny.geoserver.util.CoverageStoreUtils;
012: import java.util.List;
013: import java.util.SortedSet;
014: import java.util.TreeSet;
015: import java.util.regex.Pattern;
016: import javax.servlet.http.HttpServletRequest;
017:
018: /**
019: * Used to accept information from user for a New DataFormat Action.
020: *
021: * @author User, Refractions Research, Inc.
022: * @author jive
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 CoverageStoresNewForm extends ActionForm {
029: /**
030: *
031: */
032: private static final long serialVersionUID = -7723738069176272163L;
033:
034: /**
035: * Description provided by selected Dataformat GDSFactory
036: */
037: private String selectedDescription;
038:
039: /**
040: * User provided dataFormatID
041: */
042: private String dataFormatID;
043: private List formatDescriptions;
044:
045: /**
046: * Default state of New form
047: *
048: * @param mapping
049: * DOCUMENT ME!
050: * @param request
051: * DOCUMENT ME!
052: */
053: public void reset(ActionMapping mapping, HttpServletRequest request) {
054: super .reset(mapping, request);
055: selectedDescription = "";
056: dataFormatID = "";
057: formatDescriptions = CoverageStoreUtils
058: .listDataFormatsDescriptions();
059: }
060:
061: /**
062: * Check NewForm for correct use
063: *
064: * @param mapping
065: * DOCUMENT ME!
066: * @param request
067: * DOCUMENT ME!
068: *
069: * @return DOCUMENT ME!
070: */
071: public ActionErrors validate(ActionMapping mapping,
072: HttpServletRequest request) {
073: ActionErrors errors = new ActionErrors();
074:
075: if (!getDataFormatDescriptions().contains(
076: getSelectedDescription())) {
077: errors.add("selectedDescription", new ActionError(
078: "error.dataFormatFactory.invalid",
079: getSelectedDescription()));
080: }
081:
082: if ((getDataFormatID() == null) || getDataFormatID().equals("")) {
083: errors.add("dataFormatID", new ActionError(
084: "error.dataFormatId.required", getDataFormatID()));
085: } else if (!Pattern.matches("^\\w(\\w|\\.)*$",
086: getDataFormatID())) {
087: errors.add("dataFormatID", new ActionError(
088: "error.dataFormatId.invalid", getDataFormatID()));
089: }
090:
091: return errors;
092: }
093:
094: /**
095: *
096: */
097: public String getDataFormatID() {
098: return dataFormatID;
099: }
100:
101: /**
102: *
103: */
104: public String getSelectedDescription() {
105: return selectedDescription;
106: }
107:
108: /**
109: *
110: */
111: public void setDataFormatID(String string) {
112: dataFormatID = string;
113: }
114:
115: /**
116: *
117: */
118: public void setSelectedDescription(String string) {
119: selectedDescription = string;
120: }
121:
122: /*
123: * Allows the JSP page to easily access the list of dataFormat Descriptions
124: */
125: public SortedSet getDataFormatDescriptions() {
126: return new TreeSet(formatDescriptions);
127: }
128: }
|