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


001:        /*
002:         * Copyright (c) 2002-2007 by OpenSymphony
003:         * All rights reserved.
004:         */
005:        package com.opensymphony.xwork.validator;
006:
007:        import com.opensymphony.xwork.TextProvider;
008:        import com.opensymphony.xwork.util.OgnlValueStack;
009:
010:        import java.util.*;
011:
012:        import org.apache.commons.logging.LogFactory;
013:        import org.apache.commons.logging.Log;
014:
015:        /**
016:         * This is a composite {@link TextProvider} that takes in an array or {@link List} of {@link TextProvider}s, it will
017:         * consult each of them in order to get a composite result. To know how each method behaves, please refer to the
018:         * javadoc for each methods.
019:         *
020:         * @author tmjee
021:         * @version $Date$ $Id$
022:         */
023:        public class CompositeTextProvider implements  TextProvider {
024:
025:            private static final Log LOG = LogFactory
026:                    .getLog(CompositeTextProvider.class);
027:
028:            private List textProviders = new ArrayList();
029:
030:            /**
031:             * Instantiates a {@link CompositeTextProvider} with some predefined <code>textProviders</code>.
032:             * @param textProviders
033:             */
034:            public CompositeTextProvider(List textProviders) {
035:                for (Iterator i = textProviders.iterator(); i.hasNext();) {
036:                    Object obj = i.next();
037:                    if (obj instanceof  TextProvider) {
038:                        this .textProviders.add(obj);
039:                    } else {
040:                        LOG
041:                                .warn("object ["
042:                                        + obj
043:                                        + "] provided in list ["
044:                                        + textProviders
045:                                        + "] is not a TextProvider instance, ignoring it");
046:                    }
047:                }
048:            }
049:
050:            /**
051:             * Instantiates a {@link CompositeTextProvider} with some predefined <code>textProviders</code>.
052:             * @param textProviders
053:             */
054:            public CompositeTextProvider(TextProvider[] textProviders) {
055:                this (Arrays.asList(textProviders));
056:            }
057:
058:            /**
059:             * @see {@link com.opensymphony.xwork.TextProvider#hasKey(String)}
060:             * It will consult each individual {@link TextProvider}s and return true if either one of the
061:             * {@link TextProvider} has such a <code>key></code> else false.
062:             *
063:             * @param key
064:             * @return
065:             */
066:            public boolean hasKey(String key) {
067:                // if there's a key in either text providers we are ok, else try the next text provider
068:                for (Iterator i = textProviders.iterator(); i.hasNext();) {
069:                    TextProvider _textProvider = (TextProvider) i.next();
070:                    if (_textProvider.hasKey(key)) {
071:                        return true;
072:                    }
073:                }
074:                return false;
075:            }
076:
077:            /**
078:             * It will consult each {@link TextProvider}s and return the first valid message for this
079:             * <code>key</code>
080:             * @see {@link com.opensymphony.xwork.TextProvider#getText(String)}
081:             * @param key
082:             * @return
083:             */
084:            public String getText(String key) {
085:                return getText(key, key, Collections.EMPTY_LIST);
086:            }
087:
088:            /**
089:             * It will consult each {@link TextProvider}s and return the first valid message for this
090:             * <code>key</code> before returning <code>defaultValue</code> if every else fails.
091:             * @see {@link com.opensymphony.xwork.TextProvider#getText(String, String)} 
092:             * @param key
093:             * @param defaultValue
094:             * @return
095:             */
096:            public String getText(String key, String defaultValue) {
097:                return getText(key, defaultValue, Collections.EMPTY_LIST);
098:            }
099:
100:            /**
101:             * It will consult each {@link TextProvider}s and return the first valid message for this
102:             * <code>key</code>, before returining <code>defaultValue</code>
103:             * if every else fails.
104:             * @see {@link com.opensymphony.xwork.TextProvider#getText(String, String, String)}
105:             * @param key
106:             * @param defaultValue
107:             * @param obj
108:             * @return
109:             */
110:            public String getText(String key, String defaultValue,
111:                    final String obj) {
112:                return getText(key, defaultValue, new ArrayList() {
113:                    {
114:                        add(obj);
115:                    }
116:                });
117:            }
118:
119:            /**
120:             * It will consult each {@link TextProvider}s and return the first valid message for this
121:             * <code>key</code>.
122:             * @see {@link com.opensymphony.xwork.TextProvider#getText(String, java.util.List)}
123:             * @param key
124:             * @param args
125:             * @return
126:             */
127:            public String getText(String key, List args) {
128:                return getText(key, key, args);
129:            }
130:
131:            /**
132:             * It will consult each {@link TextProvider}s and return the first valid message for this
133:             * <code>key</code>.
134:             * @see {@link com.opensymphony.xwork.TextProvider#getText(String, String[])}
135:             * @param key
136:             * @param args
137:             * @return
138:             */
139:            public String getText(String key, String[] args) {
140:                return getText(key, key, args);
141:            }
142:
143:            /**
144:             * It will consult each {@link TextProvider}s and return the first valid message for this
145:             * <code>key</code>, before returining <code>defaultValue</code>
146:             * @see {@link com.opensymphony.xwork.TextProvider#getText#getText(String, String, java.util.List)}
147:             * @param key
148:             * @param defaultValue
149:             * @param args
150:             * @return
151:             */
152:            public String getText(String key, String defaultValue, List args) {
153:                // if there's one text provider that gives us a msg not the same as defaultValue
154:                // for this key, we are ok, else try the next
155:                // text provider
156:                for (Iterator i = textProviders.iterator(); i.hasNext();) {
157:                    TextProvider _textProvider = (TextProvider) i.next();
158:                    String msg = _textProvider.getText(key, defaultValue, args);
159:                    if (msg != null && (!msg.equals(defaultValue))) {
160:                        return msg;
161:                    }
162:                }
163:                return defaultValue;
164:            }
165:
166:            /**
167:             * It will consult each {@link TextProvider}s and return the first valid message for this
168:             * <code>key</code>, before returining <code>defaultValue</code>.
169:             * @see {@link com.opensymphony.xwork.TextProvider#getText(String, String, String[])}
170:             * @param key
171:             * @param defaultValue
172:             * @param args
173:             * @return
174:             */
175:            public String getText(String key, String defaultValue, String[] args) {
176:                // if there's one text provider that gives us a msg not the same as defaultValue
177:                // for this key, we are ok, else try the next
178:                // text provider
179:                for (Iterator i = textProviders.iterator(); i.hasNext();) {
180:                    TextProvider _textProvider = (TextProvider) i.next();
181:                    String msg = _textProvider.getText(key, defaultValue, args);
182:                    if (msg != null && (!msg.equals(defaultValue))) {
183:                        return msg;
184:                    }
185:                }
186:                return defaultValue;
187:            }
188:
189:            /**
190:             * It will consult each {@link TextProvider}s and return the first valid message for this
191:             * <code>key</code>, before returining <code>defaultValue</code>
192:             *
193:             * @see {@link com.opensymphony.xwork.TextProvider#getText(String, String, java.util.List, com.opensymphony.xwork.util.OgnlValueStack)}
194:             * @param key
195:             * @param defaultValue
196:             * @param args
197:             * @param stack
198:             * @return
199:             */
200:            public String getText(String key, String defaultValue, List args,
201:                    OgnlValueStack stack) {
202:                // if there's one text provider that gives us a msg not the same as defaultValue
203:                // for this key, we are ok, else try the next
204:                // text provider
205:                for (Iterator i = textProviders.iterator(); i.hasNext();) {
206:                    TextProvider _textProvider = (TextProvider) i.next();
207:                    String msg = _textProvider.getText(key, defaultValue, args,
208:                            stack);
209:                    if (msg != null && (!msg.equals(defaultValue))) {
210:                        return msg;
211:                    }
212:                }
213:                return defaultValue;
214:            }
215:
216:            /**
217:             * It will consult each {@link TextProvider}s and return the first valid message for this
218:             * <code>key</code>, before returining <code>defaultValue</code>
219:             * @see {@link com.opensymphony.xwork.TextProvider#getText(String, String, String[], com.opensymphony.xwork.util.OgnlValueStack)}
220:             * @param key
221:             * @param defaultValue
222:             * @param args
223:             * @param stack
224:             * @return
225:             */
226:            public String getText(String key, String defaultValue,
227:                    String[] args, OgnlValueStack stack) {
228:                // if there's one text provider that gives us a msg not the same as defaultValue
229:                // for this key, we are ok, else try the next
230:                // text provider
231:                for (Iterator i = textProviders.iterator(); i.hasNext();) {
232:                    TextProvider _textProvider = (TextProvider) i.next();
233:                    String msg = _textProvider.getText(key, defaultValue, args,
234:                            stack);
235:                    if (msg != null && (!msg.equals(defaultValue))) {
236:                        return msg;
237:                    }
238:                }
239:                return defaultValue;
240:            }
241:
242:            /**
243:             * It will consult each {@link TextProvider}s and return the first non-null {@link ResourceBundle}.
244:             * @see {@link TextProvider#getTexts(String)} 
245:             * @param bundleName
246:             * @return
247:             */
248:            public ResourceBundle getTexts(String bundleName) {
249:                // if there's one text provider that gives us a non-null resource bunlde for this bundleName, we are ok, else try the next
250:                // text provider
251:                for (Iterator i = textProviders.iterator(); i.hasNext();) {
252:                    TextProvider _textProvider = (TextProvider) i.next();
253:                    ResourceBundle bundle = _textProvider.getTexts(bundleName);
254:                    if (bundle != null) {
255:                        return bundle;
256:                    }
257:                }
258:                return null;
259:            }
260:
261:            /**
262:             * It will consult each {@link com.opensymphony.xwork.TextProvider}s and return the first non-null {@link ResourceBundle}.
263:             * @see {@link TextProvider#getTexts()} 
264:             * @return
265:             */
266:            public ResourceBundle getTexts() {
267:                // if there's one text provider that gives us a non-null resource bundle, we are ok, else try the next
268:                // text provider
269:                for (Iterator i = textProviders.iterator(); i.hasNext();) {
270:                    TextProvider _textProvider = (TextProvider) i.next();
271:                    ResourceBundle bundle = _textProvider.getTexts();
272:                    if (bundle != null) {
273:                        return bundle;
274:                    }
275:                }
276:                return null;
277:            }
278:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.