Source Code Cross Referenced for FormsDelegate.java in  » Web-Framework » calyxo » de » odysseus » calyxo » struts » forms » 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 » calyxo » de.odysseus.calyxo.struts.forms 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2004, 2005, 2006 Odysseus Software GmbH
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:        package de.odysseus.calyxo.struts.forms;
017:
018:        import java.io.Serializable;
019:        import java.util.ArrayList;
020:        import java.util.Iterator;
021:        import java.util.Locale;
022:
023:        import javax.servlet.http.HttpServletRequest;
024:
025:        import org.apache.struts.action.ActionErrors;
026:        import org.apache.struts.action.ActionMapping;
027:        import org.apache.struts.action.ActionMessage;
028:        import org.apache.struts.action.ActionMessages;
029:
030:        import de.odysseus.calyxo.base.I18nSupport;
031:        import de.odysseus.calyxo.base.Message;
032:        import de.odysseus.calyxo.base.Messages;
033:        import de.odysseus.calyxo.base.conf.ConfigException;
034:        import de.odysseus.calyxo.forms.Form;
035:        import de.odysseus.calyxo.forms.FormInputValues;
036:        import de.odysseus.calyxo.forms.FormResult;
037:        import de.odysseus.calyxo.forms.FormsSupport;
038:
039:        /**
040:         * This class performs the form validation.
041:         * 
042:         * @author Christoph Beck
043:         */
044:        public class FormsDelegate implements  Serializable {
045:            private static final String FORMATTED_MESSAGE_KEY = "";
046:
047:            /**
048:             * Transform a calyxo message into a struts action message.
049:             * Calyxo messages and struts action messages differ in that
050:             * calyxo messages may specify a bundle name.
051:             * If the calyxo message specifies a bundle, this method will
052:             * format the message and produce a struts action message
053:             * with key <code>""</code> and the formatted message string
054:             * as argument.
055:             * 
056:             * @param request the request we're in
057:             * @param locale the desired locale
058:             * @param i18n 18n support instance
059:             * @param message the message to be transformed
060:             * @return a struts action message
061:             */
062:            protected ActionMessage createActionMessage(
063:                    HttpServletRequest request, Locale locale,
064:                    I18nSupport i18n, Message message) {
065:
066:                ArrayList values = new ArrayList();
067:                Iterator args = message.getArgs();
068:                while (args.hasNext()) {
069:                    Message.Arg arg = (Message.Arg) args.next();
070:                    values.add(arg.getValue(locale, i18n));
071:                }
072:                if (message.getBundle() != null) {
073:                    String string = i18n.getMessage(locale,
074:                            message.getBundle(), message.getKey(), values
075:                                    .toArray());
076:                    return new ActionMessage(FORMATTED_MESSAGE_KEY, string);
077:                }
078:                return new ActionMessage(message.getKey(), values.toArray());
079:            }
080:
081:            protected ActionErrors doValidate(ActionMapping mapping,
082:                    HttpServletRequest request, FormInputValues inputs)
083:                    throws Exception {
084:
085:                I18nSupport i18n = I18nSupport.getInstance(request);
086:                Locale locale = i18n.getLocale(request);
087:                FormsSupport support = FormsSupport.getInstance(request);
088:                Form form = support.getForm(request, locale, mapping.getPath());
089:                if (form == null) {
090:                    throw new ConfigException("No form for action '"
091:                            + mapping.getPath() + "'");
092:                }
093:                ActionErrors errors = null;
094:                // execute validation
095:                FormResult result = form.validate(request, inputs);
096:                if (!result.isValid()) { // collect error messages
097:                    errors = new ActionErrors();
098:                    Messages messages = result.getMessages();
099:                    Iterator names = messages.getKeys();
100:                    while (names.hasNext()) {
101:                        String name = (String) names.next();
102:                        if (name != Messages.GLOBAL_KEY) {
103:                            Message message = messages.getFirstMessage(name);
104:                            ActionMessage error = createActionMessage(request,
105:                                    locale, i18n, message);
106:                            errors.add(name, error);
107:                        } else {
108:                            Iterator iter = messages.getGlobalMessages();
109:                            while (iter.hasNext()) {
110:                                Message message = (Message) iter.next();
111:                                ActionMessage error = createActionMessage(
112:                                        request, locale, i18n, message);
113:                                errors
114:                                        .add(ActionMessages.GLOBAL_MESSAGE,
115:                                                error);
116:                            }
117:                        }
118:                    }
119:                }
120:                request.setAttribute(FormsSupport.FORM_RESULT_KEY, result);
121:                return errors;
122:            }
123:
124:            public ActionErrors handleException(Exception e) {
125:                ActionErrors errors = new ActionErrors();
126:                ActionMessage error = new ActionMessage(FORMATTED_MESSAGE_KEY,
127:                        e.getMessage());
128:                errors.add(ActionMessages.GLOBAL_MESSAGE, error);
129:                return errors;
130:            }
131:
132:            /**
133:             * Validate the properties that have been set for this HTTP request,
134:             * and return an <code>ActionErrors</code> object that encapsulates any
135:             * validation errors that have been found.  If no errors are found,
136:             * return <code>null</code> or an <code>ActionErrors</code> object with
137:             * no recorded error messages.
138:             * <p>
139:             *
140:             * @param mapping The mapping used to select this instance
141:             * @param request The servlet request we are processing
142:             */
143:            public ActionErrors validate(ActionMapping mapping,
144:                    HttpServletRequest request, FormInputValues inputs) {
145:                try {
146:                    return doValidate(mapping, request, inputs);
147:                } catch (Exception e) {
148:                    return handleException(e);
149:                }
150:            }
151:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.