Source Code Cross Referenced for EscapedErrors.java in  » J2EE » spring-framework-2.0.6 » org » springframework » web » bind » 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 » spring framework 2.0.6 » org.springframework.web.bind 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2002-2006 the original author or authors.
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:
017:        package org.springframework.web.bind;
018:
019:        import java.util.ArrayList;
020:        import java.util.Iterator;
021:        import java.util.List;
022:
023:        import org.springframework.validation.Errors;
024:        import org.springframework.validation.FieldError;
025:        import org.springframework.validation.ObjectError;
026:        import org.springframework.web.util.HtmlUtils;
027:
028:        /**
029:         * Errors wrapper that adds automatic HTML escaping to the wrapped instance,
030:         * for convenient usage in HTML views. Can be retrieved easily via
031:         * RequestContext's <code>getErrors</code> method.
032:         *
033:         * <p>Note that BindTag does <i>not</i> use this class to avoid unnecessary
034:         * creation of ObjectError instances. It just escapes the messages and values
035:         * that get copied into the respective BindStatus instance.
036:         *
037:         * @author Juergen Hoeller
038:         * @since 01.03.2003
039:         * @see org.springframework.web.servlet.support.RequestContext#getErrors
040:         * @see org.springframework.web.servlet.tags.BindTag
041:         */
042:        public class EscapedErrors implements  Errors {
043:
044:            private final Errors source;
045:
046:            /**
047:             * Create a new EscapedErrors instance for the given source instance.
048:             */
049:            public EscapedErrors(Errors source) {
050:                if (source == null) {
051:                    throw new IllegalArgumentException(
052:                            "Cannot wrap a null instance");
053:                }
054:                this .source = source;
055:            }
056:
057:            public Errors getSource() {
058:                return this .source;
059:            }
060:
061:            public String getObjectName() {
062:                return this .source.getObjectName();
063:            }
064:
065:            public void setNestedPath(String nestedPath) {
066:                this .source.setNestedPath(nestedPath);
067:            }
068:
069:            public String getNestedPath() {
070:                return this .source.getNestedPath();
071:            }
072:
073:            public void pushNestedPath(String subPath) {
074:                this .source.pushNestedPath(subPath);
075:            }
076:
077:            public void popNestedPath() throws IllegalStateException {
078:                this .source.popNestedPath();
079:            }
080:
081:            public void reject(String errorCode) {
082:                this .source.reject(errorCode);
083:            }
084:
085:            public void reject(String errorCode, String defaultMessage) {
086:                this .source.reject(errorCode, defaultMessage);
087:            }
088:
089:            public void reject(String errorCode, Object[] errorArgs,
090:                    String defaultMessage) {
091:                this .source.reject(errorCode, errorArgs, defaultMessage);
092:            }
093:
094:            public void rejectValue(String field, String errorCode) {
095:                this .source.rejectValue(field, errorCode);
096:            }
097:
098:            public void rejectValue(String field, String errorCode,
099:                    String defaultMessage) {
100:                this .source.rejectValue(field, errorCode, defaultMessage);
101:            }
102:
103:            public void rejectValue(String field, String errorCode,
104:                    Object[] errorArgs, String defaultMessage) {
105:                this .source.rejectValue(field, errorCode, errorArgs,
106:                        defaultMessage);
107:            }
108:
109:            public void addAllErrors(Errors errors) {
110:                this .source.addAllErrors(errors);
111:            }
112:
113:            public boolean hasErrors() {
114:                return this .source.hasErrors();
115:            }
116:
117:            public int getErrorCount() {
118:                return this .source.getErrorCount();
119:            }
120:
121:            public List getAllErrors() {
122:                return escapeObjectErrors(this .source.getAllErrors());
123:            }
124:
125:            public boolean hasGlobalErrors() {
126:                return this .source.hasGlobalErrors();
127:            }
128:
129:            public int getGlobalErrorCount() {
130:                return this .source.getGlobalErrorCount();
131:            }
132:
133:            public List getGlobalErrors() {
134:                return escapeObjectErrors(this .source.getGlobalErrors());
135:            }
136:
137:            public ObjectError getGlobalError() {
138:                return escapeObjectError(this .source.getGlobalError());
139:            }
140:
141:            public boolean hasFieldErrors() {
142:                return this .source.hasFieldErrors();
143:            }
144:
145:            public int getFieldErrorCount() {
146:                return this .source.getFieldErrorCount();
147:            }
148:
149:            public List getFieldErrors() {
150:                return this .source.getFieldErrors();
151:            }
152:
153:            public FieldError getFieldError() {
154:                return this .source.getFieldError();
155:            }
156:
157:            public boolean hasFieldErrors(String field) {
158:                return this .source.hasFieldErrors(field);
159:            }
160:
161:            public int getFieldErrorCount(String field) {
162:                return this .source.getFieldErrorCount(field);
163:            }
164:
165:            public List getFieldErrors(String field) {
166:                return escapeObjectErrors(this .source.getFieldErrors(field));
167:            }
168:
169:            public FieldError getFieldError(String field) {
170:                return (FieldError) escapeObjectError(this .source
171:                        .getFieldError(field));
172:            }
173:
174:            public Object getFieldValue(String field) {
175:                Object value = this .source.getFieldValue(field);
176:                return (value instanceof  String ? HtmlUtils
177:                        .htmlEscape((String) value) : value);
178:            }
179:
180:            public Class getFieldType(String field) {
181:                return this .source.getFieldType(field);
182:            }
183:
184:            private ObjectError escapeObjectError(ObjectError source) {
185:                if (source == null) {
186:                    return null;
187:                }
188:                if (source instanceof  FieldError) {
189:                    FieldError fieldError = (FieldError) source;
190:                    Object value = fieldError.getRejectedValue();
191:                    if (value instanceof  String) {
192:                        value = HtmlUtils.htmlEscape((String) value);
193:                    }
194:                    return new FieldError(fieldError.getObjectName(),
195:                            fieldError.getField(), value, fieldError
196:                                    .isBindingFailure(), fieldError.getCodes(),
197:                            fieldError.getArguments(), HtmlUtils
198:                                    .htmlEscape(fieldError.getDefaultMessage()));
199:                }
200:                return new ObjectError(source.getObjectName(), source
201:                        .getCodes(), source.getArguments(), HtmlUtils
202:                        .htmlEscape(source.getDefaultMessage()));
203:            }
204:
205:            private List escapeObjectErrors(List source) {
206:                List escaped = new ArrayList(source.size());
207:                for (Iterator it = source.iterator(); it.hasNext();) {
208:                    ObjectError objectError = (ObjectError) it.next();
209:                    escaped.add(escapeObjectError(objectError));
210:                }
211:                return escaped;
212:            }
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.