KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > core > forms > AbstractResourceDetailsWizardForm


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.core.forms;
21
22 import javax.servlet.http.HttpServletRequest JavaDoc;
23
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26 import org.apache.struts.Globals;
27 import org.apache.struts.action.ActionErrors;
28 import org.apache.struts.action.ActionMapping;
29
30 import com.sslexplorer.core.BundleActionMessage;
31 import com.sslexplorer.policyframework.ResourceType;
32 import com.sslexplorer.wizard.AbstractWizardSequence;
33 import com.sslexplorer.wizard.forms.DefaultWizardForm;
34
35 /**
36  * Abstract implementation of a {@link DefaultWizardForm}. Provides setters and getters
37  * for attributes common to all resource types in the wizards.
38  *
39  * @author James D Robinson <a HREF="mailto:james@3sp.com">&lt;james@3sp.com&gt;</a>
40  *
41  */

42 public abstract class AbstractResourceDetailsWizardForm extends DefaultWizardForm {
43     private String JavaDoc resourceName;
44     private String JavaDoc resourceDescription;
45     private ResourceType resourceTypeForAccessRights;
46
47     final static Log log = LogFactory.getLog(AbstractResourceDetailsWizardForm.class);
48
49     /**
50      * Resource name constant
51      */

52     public final static String JavaDoc ATTR_RESOURCE_NAME = "resourceName";
53     
54     /**
55      * Resource description constant
56      */

57     public final static String JavaDoc ATTR_RESOURCE_DESCRIPTION = "resourceDescription";
58     
59     /**
60      * Resource permission class constant.
61      */

62     public static final String JavaDoc ATTR_RESOURCE_PERMISSION_CLASS = "class";
63
64     /**
65      * @param nextAvailable
66      * @param previousAvailable
67      * @param page
68      * @param focussedField
69      * @param autoComplete
70      * @param finishAvailable
71      * @param pageName must be name of action
72      * @param resourceBundle
73      * @param resourcePrefix
74      * @param stepIndex
75      * @param resourceTypeForAccessRights
76      */

77     public AbstractResourceDetailsWizardForm(boolean nextAvailable, boolean previousAvailable, String JavaDoc page, String JavaDoc focussedField,
78                     boolean autoComplete, boolean finishAvailable, String JavaDoc pageName, String JavaDoc resourceBundle, String JavaDoc resourcePrefix,
79                     int stepIndex, ResourceType resourceTypeForAccessRights) {
80         super(nextAvailable, previousAvailable, page, focussedField, autoComplete, finishAvailable, pageName, resourceBundle,
81             resourcePrefix, stepIndex);
82         this.resourceTypeForAccessRights = resourceTypeForAccessRights;
83     }
84
85     /**
86      * @return Returns the resourceDescription.
87      */

88     public String JavaDoc getResourceDescription() {
89         return resourceDescription;
90     }
91
92     /**
93      * @param resourceDescription The resourceDescription to set.
94      */

95     public void setResourceDescription(String JavaDoc resourceDescription) {
96         this.resourceDescription = resourceDescription.trim();
97     }
98
99     /**
100      * @return Returns the resourceName.
101      */

102     public String JavaDoc getResourceName() {
103         return resourceName;
104     }
105
106     /*
107      * (non-Javadoc)
108      *
109      * @see com.sslexplorer.wizard.forms.DefaultWizardForm#apply(com.sslexplorer.wizard.AbstractWizardSequence)
110      */

111     public void apply(AbstractWizardSequence sequence) throws Exception JavaDoc {
112         super.apply(sequence);
113         sequence.putAttribute(ATTR_RESOURCE_NAME, resourceName);
114         sequence.putAttribute(ATTR_RESOURCE_DESCRIPTION, resourceDescription);
115     }
116
117     /**
118      * @param resourceName The resourceName to set.
119      */

120     public void setResourceName(String JavaDoc resourceName) {
121         this.resourceName = resourceName.trim();
122     }
123
124     /*
125      * (non-Javadoc)
126      *
127      * @see com.sslexplorer.wizard.forms.DefaultWizardForm#init(com.sslexplorer.wizard.AbstractWizardSequence,
128      * javax.servlet.http.HttpServletRequest)
129      */

130     public void init(AbstractWizardSequence sequence, HttpServletRequest JavaDoc request) throws Exception JavaDoc {
131         super.init(sequence, request);
132         resourceName = (String JavaDoc) sequence.getAttribute(ATTR_RESOURCE_NAME, "");
133         resourceDescription = (String JavaDoc) sequence.getAttribute(ATTR_RESOURCE_DESCRIPTION, "");
134     }
135
136     /*
137      * (non-Javadoc)
138      *
139      * @see com.sslexplorer.wizard.forms.AbstractWizardForm#reset(org.apache.struts.action.ActionMapping,
140      * javax.servlet.http.HttpServletRequest)
141      */

142     public void reset(ActionMapping mapping, HttpServletRequest JavaDoc request) {
143         super.reset(mapping, request);
144     }
145
146     /*
147      * (non-Javadoc)
148      *
149      * @see com.sslexplorer.wizard.forms.DefaultWizardForm#validate(org.apache.struts.action.ActionMapping,
150      * javax.servlet.http.HttpServletRequest)
151      */

152     public ActionErrors validate(ActionMapping mapping, HttpServletRequest JavaDoc request) {
153         if (resourceName != null && isCommiting()) {
154             ActionErrors errs = new ActionErrors();
155             AbstractWizardSequence seq = getWizardSequence(request);
156             if (resourceName.equals("")) {
157                 errs.add(Globals.ERROR_KEY, new BundleActionMessage(seq.getCurrentPageForm().getResourceBundle(), seq
158                     .getCurrentPageForm().getResourcePrefix()
159                                 + ".error.noResourceName"));
160             }
161             if (resourceDescription.equals("")) {
162                 errs.add(Globals.ERROR_KEY, new BundleActionMessage(seq.getCurrentPageForm().getResourceBundle(), seq
163                     .getCurrentPageForm().getResourcePrefix()
164                                 + ".error.noResourceDescription"));
165             }
166             try {
167                 if (this.getResourceTypeForAccessRights().getResourceByName(getResourceName(), seq.getSession()) != null) {
168                     errs.add(Globals.ERROR_KEY, new BundleActionMessage(seq.getCurrentPageForm().getResourceBundle(), seq
169                         .getCurrentPageForm().getResourcePrefix()
170                                     + ".error.duplicateName", getResourceName()));
171                 }
172             } catch (Exception JavaDoc e) {
173                 log.error("Failed to check if named resource already exists.", e);
174                 errs.add(Globals.ERROR_KEY, new BundleActionMessage(seq.getCurrentPageForm().getResourceBundle(), seq
175                     .getCurrentPageForm().getResourcePrefix()
176                                 + ".error.failedToCheckForName", e.getMessage()));
177             }
178             return errs;
179         }
180         return null;
181     }
182     
183     /**
184      * @return Resource type
185      */

186     public ResourceType getResourceTypeForAccessRights() {
187         return resourceTypeForAccessRights;
188     }
189 }
190
Popular Tags