Source Code Cross Referenced for ValidatorSupport.java in  » J2EE » webwork-2.2.6 » com » opensymphony » xwork » validator » validators » 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 » J2EE » webwork 2.2.6 » com.opensymphony.xwork.validator.validators 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 2002-2006 by OpenSymphony
003:         * All rights reserved.
004:         */
005:        package com.opensymphony.xwork.validator.validators;
006:
007:        import com.opensymphony.xwork.ActionContext;
008:        import com.opensymphony.xwork.util.OgnlValueStack;
009:        import com.opensymphony.xwork.util.TextParseUtil;
010:        import com.opensymphony.xwork.validator.*;
011:        import org.apache.commons.logging.Log;
012:        import org.apache.commons.logging.LogFactory;
013:
014:        /**
015:         * Abstract implementation of the Validator interface suitable for subclassing.
016:         *
017:         * @author Jason Carreira
018:         * @author tmjee
019:         */
020:        public abstract class ValidatorSupport implements  Validator,
021:                ShortCircuitableValidator {
022:
023:            protected final Log log = LogFactory.getLog(this .getClass());
024:            protected String defaultMessage = "";
025:            protected String messageKey = null;
026:            private ValidatorContext validatorContext;
027:            private boolean shortCircuit;
028:            private boolean parse = false;
029:            private String type;
030:
031:            public void setParse(boolean parse) {
032:                this .parse = parse;
033:            }
034:
035:            public boolean getParse() {
036:                return parse;
037:            }
038:
039:            public void setDefaultMessage(String message) {
040:                this .defaultMessage = message;
041:            }
042:
043:            public String getDefaultMessage() {
044:                return defaultMessage;
045:            }
046:
047:            public String getMessage(Object object) {
048:                String message;
049:                OgnlValueStack stack = ActionContext.getContext()
050:                        .getValueStack();
051:                boolean pop = false;
052:
053:                if (!stack.getRoot().contains(object)) {
054:                    stack.push(object);
055:                    pop = true;
056:                }
057:
058:                stack.push(this );
059:
060:                if (messageKey != null) {
061:                    if ((defaultMessage == null)
062:                            || (defaultMessage.trim().equals(""))) {
063:                        defaultMessage = messageKey;
064:                    }
065:                    if (validatorContext == null) {
066:                        validatorContext = new DelegatingValidatorContext(
067:                                object);
068:                    }
069:                    message = validatorContext.getText(messageKey,
070:                            defaultMessage);
071:                } else {
072:                    message = defaultMessage;
073:                }
074:
075:                message = TextParseUtil.translateVariables(message, stack);
076:
077:                stack.pop();
078:
079:                if (pop) {
080:                    stack.pop();
081:                }
082:
083:                return message;
084:            }
085:
086:            public void setMessageKey(String key) {
087:                messageKey = key;
088:            }
089:
090:            public String getMessageKey() {
091:                return messageKey;
092:            }
093:
094:            public void setShortCircuit(boolean shortcircuit) {
095:                shortCircuit = shortcircuit;
096:            }
097:
098:            public boolean isShortCircuit() {
099:                return shortCircuit;
100:            }
101:
102:            public void setValidatorContext(ValidatorContext validatorContext) {
103:                this .validatorContext = validatorContext;
104:            }
105:
106:            public ValidatorContext getValidatorContext() {
107:                return validatorContext;
108:            }
109:
110:            public void setValidatorType(String type) {
111:                this .type = type;
112:            }
113:
114:            public String getValidatorType() {
115:                return type;
116:            }
117:
118:            /**
119:             * Parse <code>expression</code> passed in against value stack. Only parse
120:             * when 'parse' param is set to true, else just returns the expression unparsed.
121:             * 
122:             * @param expression
123:             * @return
124:             */
125:            protected Object conditionalParse(String expression) {
126:                if (parse) {
127:                    OgnlValueStack stack = ActionContext.getContext()
128:                            .getValueStack();
129:                    return TextParseUtil.translateVariables('$', expression,
130:                            stack);
131:                }
132:                return expression;
133:            }
134:
135:            /**
136:             * Return the field value named <code>name</code> from <code>object</code>, 
137:             * <code>object</code> should have the appropriate getter/setter.
138:             * 
139:             * @param name
140:             * @param object
141:             * @return
142:             * @throws ValidationException
143:             */
144:            protected Object getFieldValue(String name, Object object)
145:                    throws ValidationException {
146:                OgnlValueStack stack = ActionContext.getContext()
147:                        .getValueStack();
148:
149:                boolean pop = false;
150:
151:                if (!stack.getRoot().contains(object)) {
152:                    stack.push(object);
153:                    pop = true;
154:                }
155:
156:                Object retVal = stack.findValue(name);
157:
158:                if (pop) {
159:                    stack.pop();
160:                }
161:
162:                return retVal;
163:            }
164:
165:            protected void addActionError(Object object) {
166:                validatorContext.addActionError(getMessage(object));
167:            }
168:
169:            protected void addFieldError(String propertyName, Object object) {
170:                validatorContext
171:                        .addFieldError(propertyName, getMessage(object));
172:            }
173:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.