001: /*
002: * Created on Feb 16, 2004
003: *
004: * To change the template for this generated file go to
005: * Window - Preferences - Java - Code Generation - Code and Comments
006: */
007: package org.vfny.geoserver.form.data;
008:
009: import org.apache.struts.action.ActionErrors;
010: import org.apache.struts.action.ActionForm;
011: import org.apache.struts.action.ActionMapping;
012: import org.vfny.geoserver.config.ConfigRequests;
013: import org.vfny.geoserver.config.DataConfig;
014: import org.vfny.geoserver.global.UserContainer;
015: import org.vfny.geoserver.util.Requests;
016: import java.util.TreeSet;
017: import javax.servlet.http.HttpServletRequest;
018:
019: /**
020: * DataNamespacesSelectForm
021: * <p>
022: * @author rgould, Refractions Research, Inc.
023: * @author $Author: emperorkefka $ (last modification)
024: * @version $Id: DataNamespacesSelectForm.java 6177 2007-02-19 10:11:27Z aaime $
025: */
026: public class DataNamespacesSelectForm extends ActionForm {
027: /** namespace the user selected (value is a prefix) */
028: private String selectedNamespace;
029:
030: /** Action the user clicked on */
031: private String action;
032: private TreeSet namespaces;
033:
034: public void reset(ActionMapping arg0, HttpServletRequest request) {
035: super .reset(arg0, request);
036:
037: action = "";
038:
039: UserContainer user = Requests.getUserContainer(request);
040:
041: if (user == null) {
042: return; // User not logged in, probably the JSPCompiler
043: }
044:
045: selectedNamespace = user.getPrefix();
046:
047: // populate and sort available namespaces
048: //
049: DataConfig config = ConfigRequests.getDataConfig(request);
050: namespaces = new TreeSet(config.getNameSpaces().keySet());
051:
052: String def = config.getDefaultNameSpace().getPrefix();
053:
054: if (namespaces.contains(def)) {
055: namespaces.remove(def);
056: namespaces.add(def + "*");
057: }
058: }
059:
060: public ActionErrors validate(ActionMapping mapping,
061: HttpServletRequest request) {
062: ActionErrors errors = new ActionErrors();
063:
064: if ((getSelectedNamespace() == null)
065: || getSelectedNamespace().equalsIgnoreCase("")) {
066: return errors; // no data in the list, so return
067: }
068:
069: return errors;
070: }
071:
072: /**
073: * Access action property.
074: *
075: * @return Returns the action.
076: */
077: public String getAction() {
078: return action;
079: }
080:
081: /**
082: * Set action to action.
083: *
084: * @param action The action to set.
085: */
086: public void setAction(String action) {
087: this .action = action;
088: }
089:
090: /**
091: * Access selectedNamespace property.
092: *
093: * @return Returns the selectedNamespace.
094: */
095: public String getSelectedNamespace() {
096: return selectedNamespace;
097: }
098:
099: /**
100: * Set selectedNamespace to selectedNamespace.
101: *
102: * @param selectedNamespace The selectedNamespace to set.
103: */
104: public void setSelectedNamespace(String selectedNamespace) {
105: this .selectedNamespace = selectedNamespace;
106: }
107:
108: /**
109: * Access namespaces property.
110: *
111: * @return Returns the namespaces.
112: */
113: public TreeSet getNamespaces() {
114: return namespaces;
115: }
116: }
|