Source Code Cross Referenced for XNameValidator.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.util.Date;
004:        import net.xoetrope.xml.XmlElement;
005:        import net.xoetrope.xui.XProject;
006:
007:        import net.xoetrope.xui.validation.XBaseValidator;
008:
009:        /**
010:         * Validates names, by ensuring they are properly formed, of adequate length and
011:         * containing a valid set of characters
012:         * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
013:         * the GNU Public License (GPL), please see license.txt for more details. If
014:         * you make commercial use of this software you must purchase a commercial
015:         * license from Xoetrope.</p>
016:         * <p> $Revision: 1.8 $</p>
017:         */
018:        public class XNameValidator extends XBaseValidator {
019:            private boolean firstName;
020:
021:            /**
022:             * Validates a name
023:             * @param isFirstName true if this is a first name validator
024:             * @param msg The message to be displayed if validation fails
025:             */
026:            public XNameValidator(XProject project) {
027:                super (project);
028:            }
029:
030:            /**
031:             * Set the validation parameters
032:             * @param element the validator parameters
033:             */
034:            public void setup(XmlElement element) {
035:                super .setup(element);
036:
037:                boolean firstName = false;
038:                String fs = element.getAttribute("first");
039:                if (fs != null)
040:                    firstName = Boolean.valueOf(fs).booleanValue();
041:            }
042:
043:            /**
044:             * Validates that a name has been entered. For first names initials are accepted
045:             * for part of the name while for a second name words of at least two letters
046:             * are required.
047:             * @param comp The component triggering the validation
048:             * @throws Exception Contains the details of the message
049:             */
050:            public void validate(Object comp, boolean forceMandatory)
051:                    throws Exception {
052:                errorLevel = LEVEL_IGNORE;
053:                String text = getText(comp).trim();
054:                boolean failed = false;
055:
056:                if ((text.length() > 0) && (mandatory || forceMandatory)) {
057:                    Date value = null;
058:
059:                    int numSpaces = 0;
060:                    int len = text.length();
061:                    if (len < 2)
062:                        failed = true;
063:                    else {
064:                        for (int i = 0; i < len; i++) {
065:                            char c = text.charAt(i);
066:                            Character ch = new Character(c);
067:
068:                            // Treat an apostrophy as a space
069:                            if ((ch.isSpaceChar(c)) || (c == '\'')) {
070:                                if (numSpaces > 0) {
071:                                    failed = true;
072:                                    break;
073:                                }
074:                                numSpaces++;
075:                            } else if (ch.isDigit(c)) {
076:                                failed = true;
077:                                break;
078:                            } else if (!ch.isLetter(c)) {
079:                                failed = true;
080:                                break;
081:                            }
082:                        }
083:
084:                        // For a first name one of the words must have at least two letters e.g. John P
085:                        // and for a double barreled name each word must have at least two letters
086:                        // e.g. Da Vinci
087:                        if (len < (2 + (firstName ? 2 : 3) * numSpaces))
088:                            failed = true;
089:                    }
090:                } else if (mandatory || forceMandatory) { // Text length is zero
091:                    failed = true;
092:                    errorLevel = LEVEL_WARNING;
093:                }
094:
095:                if (failed) {
096:                    if (errorLevel != LEVEL_WARNING)
097:                        errorLevel = LEVEL_ERROR;
098:                    throwException();
099:                }
100:            }
101:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.