KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > verge > mvc > view > jsp > form > ATei


1 /*
2  * Copyright (c) 2003, Inversoft
3  *
4  * This software is distribuable under the GNU Lesser General Public License.
5  * For more information visit gnu.org.
6  */

7 package com.inversoft.verge.mvc.view.jsp.form;
8
9
10 import java.util.Collection JavaDoc;
11 import java.util.Iterator JavaDoc;
12
13 import javax.servlet.jsp.tagext.TagData JavaDoc;
14 import javax.servlet.jsp.tagext.TagExtraInfo JavaDoc;
15 import javax.servlet.jsp.tagext.VariableInfo JavaDoc;
16
17 import org.apache.log4j.Logger;
18
19 import com.inversoft.verge.mvc.MVCException;
20 import com.inversoft.verge.mvc.config.BaseFormConfig;
21 import com.inversoft.verge.mvc.controller.form.FormMVCMetaData;
22 import com.inversoft.verge.mvc.controller.form.config.ActionConfig;
23 import com.inversoft.verge.mvc.controller.form.config.FormConfig;
24 import com.inversoft.verge.mvc.controller.form.config.FormMVCConfigRegistry;
25 import com.inversoft.verge.util.WebBean;
26
27
28 /**
29  * Validates that the forms method attribute is either post
30  * or get (case-insensitive) and the form name
31  *
32  * @author Brian Pontarelli
33  */

34 public class ATei extends TagExtraInfo JavaDoc {
35
36     /**
37      * This classes logger
38      */

39     private static final Logger logger = Logger.getLogger(ATei.class);
40
41
42     /**
43      * Returns whether or not the form is valid.
44      *
45      * @return True if the form exists, false otherwise
46      */

47     public boolean isValid(TagData JavaDoc data) {
48         boolean valid = true;
49         String JavaDoc form = data.getAttributeString("form");
50         FormConfig config = null;
51         if (form != null) {
52             FormMVCMetaData metaData = new FormMVCMetaData(form, null);
53
54             try {
55                 config = (FormConfig) metaData.findFormConfig(null);
56             } catch (MVCException mvce) {
57                 logger.fatal(mvce);
58                 valid = false;
59             }
60         }
61
62
63         // Validate that the action is valid
64
String JavaDoc action = data.getAttributeString("action");
65         ActionConfig actionConfig =
66             FormMVCConfigRegistry.getInstance(null).
67                 lookupAction(action, config);
68         if (actionConfig == null) {
69             logger.fatal("[ATag] - Invalid action named: " + action);
70             valid = false;
71         }
72
73         return valid;
74     }
75
76     /**
77      * Returns the variable info for the form bean
78      *
79      * @return A single VariableInfo instance for the form bean
80      */

81     public VariableInfo JavaDoc [] getVariableInfo(TagData JavaDoc data) {
82         VariableInfo JavaDoc[] infos = null;
83         String JavaDoc form = data.getAttributeString("form");
84         if (form != null) {
85             FormMVCMetaData metaData = new FormMVCMetaData(form, null);
86
87             BaseFormConfig config = null;
88             try {
89                 config = metaData.findFormConfig(null);
90             } catch (MVCException mvce) {
91                 logger.fatal(mvce);
92                 throw new IllegalArgumentException JavaDoc("Invalid form name: " + form);
93             }
94
95             Collection JavaDoc formBeans = config.getFormBeans();
96             infos = new VariableInfo JavaDoc[formBeans.size()];
97             Iterator JavaDoc iter = formBeans.iterator();
98             WebBean webBean;
99             int count = 0;
100             while (iter.hasNext()) {
101                 webBean = (WebBean) iter.next();
102                 infos[count] = new VariableInfo JavaDoc(webBean.getID(), webBean.getClassName(),
103                     true, VariableInfo.NESTED);
104             }
105         }
106
107         return infos;
108     }
109 }
Popular Tags