Source Code Cross Referenced for XDateValidator.java in  » XML-UI » xui32 » com » xoetrope » validation » 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 » XML UI » xui32 » com.xoetrope.validation 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.xoetrope.validation;
002:
003:        import java.text.DateFormat;
004:        import java.text.ParseException;
005:        import java.util.Date;
006:        import net.xoetrope.xui.build.BuildProperties;
007:        import net.xoetrope.debug.DebugLogger;
008:        import net.xoetrope.xui.XPage;
009:        import net.xoetrope.xui.validation.XBaseValidator;
010:        import java.text.SimpleDateFormat;
011:        import java.text.ParsePosition;
012:        import net.xoetrope.xml.XmlElement;
013:        import net.xoetrope.xui.XProject;
014:
015:        /**
016:         * A date validator
017:         * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
018:         * the GNU Public License (GPL), please see license.txt for more details. If
019:         * you make commercial use of this software you must purchase a commercial
020:         * license from Xoetrope.</p>
021:         * <p> $Revision: 1.8 $</p>
022:         */
023:        public class XDateValidator extends XBaseValidator {
024:            private Date min, max;
025:            private XPage page;
026:            private String dateFormat = "dd/MM/yyyy";
027:
028:            /**
029:             * Constructors the XMinMaxValidator
030:             * @param project the owner project
031:             */
032:            /** @todo change the API for this validator */
033:            public XDateValidator(XProject project) {
034:                super (project);
035:            }
036:
037:            /**
038:             * Set the validation parameters
039:             * @param element the validator parameters
040:             */
041:            public void setup(XmlElement element) {
042:                super .setup(element);
043:                String startDate = element.getAttribute("min");
044:                String endDate = element.getAttribute("max");
045:                String format = element.getAttribute("format");
046:
047:                if ((format != null) && (format.length() > 0))
048:                    dateFormat = format;
049:
050:                // Setup the min and max bounds if needed
051:                if (startDate != null) {
052:                    try {
053:                        min = DateFormat.getInstance().parse(startDate);
054:                    } catch (Exception ex) {
055:                        if (BuildProperties.DEBUG)
056:                            DebugLogger.logWarning("Invalid start date: "
057:                                    + startDate);
058:                    }
059:                }
060:
061:                if (endDate != null) {
062:                    try {
063:                        max = DateFormat.getInstance().parse(endDate);
064:                    } catch (Exception ex) {
065:                        if (BuildProperties.DEBUG)
066:                            DebugLogger.logWarning("Invalid end date: "
067:                                    + endDate);
068:                    }
069:                }
070:            }
071:
072:            /**
073:             * Carries out the min-max validation on the value entered. If the Method
074:             * validationMethod is not null we have to invoke it in order to get it's
075:             * return value. If the Method invocation returns a null we do not validate.
076:             * If a problem is found we format the message using the messageHelper.
077:             * @param c The component triggering the validation
078:             * @throws Exception Contains the details of the message
079:             */
080:            public void validate(Object c, boolean forceMandatory)
081:                    throws Exception {
082:                errorLevel = LEVEL_IGNORE;
083:                formattedMessage = message;
084:                String text = getText(c);
085:                Object ret = null;
086:                Object funcResult = null;
087:                boolean failed = false;
088:                if (mandatory || forceMandatory) {
089:                    try {
090:                        Date dateValue = null;
091:
092:                        if (text.length() == 0) {
093:                            failed = true;
094:                            //          errorLevel = LEVEL_WARNING;
095:                        } else if (validationMethod == null) {
096:                            if (text.length() > 0) {
097:                                ParsePosition pp = new ParsePosition(0);
098:                                SimpleDateFormat formatter = new SimpleDateFormat(
099:                                        dateFormat);
100:                                formatter.setLenient(false);
101:                                dateValue = formatter.parse(text, pp);
102:                                if (dateValue == null) {
103:                                    failed = true;
104:                                    errorLevel = LEVEL_ERROR;
105:                                }
106:                            }
107:                        } else {
108:                            /* We need to get the value being compared from the function call */
109:                            funcResult = invokeMethod();
110:                            if (funcResult != null) {
111:                                try {
112:                                    dateValue = DateFormat.getInstance().parse(
113:                                            funcResult.toString());
114:                                } catch (ParseException e) {
115:                                    dateValue = null;
116:                                }
117:                            }
118:                        }
119:                        /* We are either validating a basic value or the results of the Method
120:                         invocation if it is not null.
121:                         */
122:                        if ((validationMethod == null) || (funcResult != null)) {
123:                            value = String.valueOf(dateValue);
124:                            if ((text.length() == 0)
125:                                    && (mandatory || forceMandatory))
126:                                failed = true;
127:                            else if ((min != null) && (dateValue.before(min)))
128:                                failed = true;
129:                            else if ((max != null) && (dateValue.after(max)))
130:                                failed = true;
131:
132:                            if (failed) {
133:                                if (min != null)
134:                                    replaceToken("{min}", min.toString());
135:                                if (max != null)
136:                                    replaceToken("{max}", max.toString());
137:
138:                                if (funcResult != null)
139:                                    replaceToken("{value}", funcResult
140:                                            .toString());
141:                                else
142:                                    replaceToken("{value}", text);
143:                            }
144:                        }
145:
146:                    } catch (Exception ex) {
147:                        failed = true;
148:                    }
149:
150:                    if (failed) {
151:                        if (mandatory && forceMandatory)
152:                            errorLevel = LEVEL_ERROR;
153:                        else
154:                            errorLevel = Math.max(LEVEL_WARNING, errorLevel);
155:                        throwException();
156:                    }
157:                }
158:            }
159:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.