Source Code Cross Referenced for DynaValidatorForm.java in  » Web-Framework » struts-1.3.8 » org » apache » struts » validator » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Framework » struts 1.3.8 » org.apache.struts.validator 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: DynaValidatorForm.java 471754 2006-11-06 14:55:09Z husted $
003:         *
004:         * Licensed to the Apache Software Foundation (ASF) under one
005:         * or more contributor license agreements.  See the NOTICE file
006:         * distributed with this work for additional information
007:         * regarding copyright ownership.  The ASF licenses this file
008:         * to you under the Apache License, Version 2.0 (the
009:         * "License"); you may not use this file except in compliance
010:         * with the License.  You may obtain a copy of the License at
011:         *
012:         *  http://www.apache.org/licenses/LICENSE-2.0
013:         *
014:         * Unless required by applicable law or agreed to in writing,
015:         * software distributed under the License is distributed on an
016:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017:         * KIND, either express or implied.  See the License for the
018:         * specific language governing permissions and limitations
019:         * under the License.
020:         */
021:        package org.apache.struts.validator;
022:
023:        import org.apache.commons.beanutils.DynaBean;
024:        import org.apache.commons.logging.Log;
025:        import org.apache.commons.logging.LogFactory;
026:        import org.apache.commons.validator.Validator;
027:        import org.apache.commons.validator.ValidatorException;
028:        import org.apache.commons.validator.ValidatorResults;
029:        import org.apache.struts.action.ActionErrors;
030:        import org.apache.struts.action.ActionMapping;
031:        import org.apache.struts.action.DynaActionForm;
032:
033:        import javax.servlet.ServletContext;
034:        import javax.servlet.http.HttpServletRequest;
035:
036:        import java.io.Serializable;
037:
038:        import java.util.Map;
039:
040:        /**
041:         * <p>This class extends <strong>DynaActionForm</strong> and provides basic
042:         * field validation based on an XML file.  The key passed into the validator
043:         * is the action element's 'name' attribute from the struts-config.xml which
044:         * should match the form element's name attribute in the validation.xml.</p>
045:         *
046:         * <ul>
047:         *
048:         * <li>See <code>ValidatorPlugin</code> definition in struts-config.xml for
049:         * validation rules.</li>
050:         *
051:         * </ul>
052:         *
053:         * @version $Rev: 471754 $ $Date: 2005-05-07 12:11:38 -0400 (Sat, 07 May 2005)
054:         *          $
055:         * @see org.apache.struts.action.ActionForm
056:         * @since Struts 1.1
057:         */
058:        public class DynaValidatorForm extends DynaActionForm implements 
059:                DynaBean, Serializable {
060:            /**
061:             * Commons Logging instance.
062:             */
063:            private static Log log = LogFactory.getLog(DynaValidatorForm.class);
064:
065:            /**
066:             * The results returned from the validation performed by the
067:             * <code>Validator</code>.
068:             */
069:            protected ValidatorResults validatorResults = null;
070:
071:            /**
072:             * Used to indicate the current page of a multi-page form.
073:             */
074:            protected int page = 0;
075:
076:            /**
077:             * Gets page.
078:             *
079:             * @return page number.
080:             */
081:            public int getPage() {
082:                return page;
083:            }
084:
085:            /**
086:             * Sets page.
087:             *
088:             * @param page page number
089:             */
090:            public void setPage(int page) {
091:                this .page = page;
092:            }
093:
094:            /**
095:             * Validate the properties that have been set from this HTTP request, and
096:             * return an <code>ActionErrors</code> object that encapsulates any
097:             * validation errors that have been found.  If no errors are found, return
098:             * <code>null</code> or an <code>ActionErrors</code> object with no
099:             * recorded error messages.
100:             *
101:             * @param mapping The mapping used to select this instance.
102:             * @param request The servlet request we are processing.
103:             * @return <code>ActionErrors</code> object that encapsulates any
104:             *         validation errors.
105:             */
106:            public ActionErrors validate(ActionMapping mapping,
107:                    HttpServletRequest request) {
108:                this .setPageFromDynaProperty();
109:
110:                ServletContext application = getServlet().getServletContext();
111:                ActionErrors errors = new ActionErrors();
112:
113:                String validationKey = getValidationKey(mapping, request);
114:
115:                Validator validator = Resources.initValidator(validationKey,
116:                        this , application, request, errors, page);
117:
118:                try {
119:                    validatorResults = validator.validate();
120:                } catch (ValidatorException e) {
121:                    log.error(e.getMessage(), e);
122:                }
123:
124:                return errors;
125:            }
126:
127:            /**
128:             * Returns the Validation key.
129:             *
130:             * @param mapping The mapping used to select this instance
131:             * @param request The servlet request we are processing
132:             * @return validation key - the form element's name in this case
133:             */
134:            public String getValidationKey(ActionMapping mapping,
135:                    HttpServletRequest request) {
136:                return mapping.getAttribute();
137:            }
138:
139:            /**
140:             * Sets this.page to the value of the Dyna property "page" if it's
141:             * defined.  This is used to setup the page variable before validation
142:             * starts.
143:             *
144:             * @since Struts 1.2
145:             */
146:            protected void setPageFromDynaProperty() {
147:                Map props = this .getMap();
148:
149:                if (props.containsKey("page")) {
150:                    Integer p = null;
151:
152:                    try {
153:                        p = (Integer) props.get("page");
154:                    } catch (ClassCastException e) {
155:                        log
156:                                .error(
157:                                        "Dyna 'page' property must be of type java.lang.Integer.",
158:                                        e);
159:                        throw e;
160:                    }
161:
162:                    if (p == null) {
163:                        throw new NullPointerException(
164:                                "Dyna 'page' property must not be null. "
165:                                        + " Either provide an initial value or set 'convertNull' to false. ");
166:                    }
167:
168:                    this .page = p.intValue();
169:                }
170:            }
171:
172:            /**
173:             * Reset all properties to their default values.
174:             *
175:             * @param mapping The mapping used to select this instance
176:             * @param request The servlet request we are processing
177:             */
178:            public void reset(ActionMapping mapping, HttpServletRequest request) {
179:                super .reset(mapping, request);
180:                page = 0;
181:                validatorResults = null;
182:            }
183:
184:            /**
185:             * Get results of the validation performed by the <code>Validator</code>.
186:             *
187:             * @return validator results as ValidatorResults object
188:             */
189:            public ValidatorResults getValidatorResults() {
190:                return validatorResults;
191:            }
192:
193:            /**
194:             * Set results of the validation performed by the <code>Validator</code>.
195:             *
196:             * @param validatorResults Set results of the validation performed
197:             */
198:            public void setValidatorResults(ValidatorResults validatorResults) {
199:                this .validatorResults = validatorResults;
200:            }
201:
202:            /**
203:             * Returns a <code>Map</code> of values returned from any validation that
204:             * returns a value other than <code>null</code> or <code>Boolean</code>
205:             * with the key the full property path of the field.
206:             *
207:             * @return Returns a <code>Map</code> of values, otherwise returns null if
208:             *         no results.
209:             */
210:            public Map getResultValueMap() {
211:                return ((validatorResults != null) ? validatorResults
212:                        .getResultValueMap() : null);
213:            }
214:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.