KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > security > CmsDefaultValidationHandler


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/security/CmsDefaultValidationHandler.java,v $
3  * Date : $Date: 2006/05/12 16:05:48 $
4  * Version: $Revision: 1.2 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.security;
33
34 import org.opencms.main.CmsIllegalArgumentException;
35 import org.opencms.util.CmsStringUtil;
36
37 /**
38  * Default implementation for the validation handler.<p>
39  *
40  * @author Michael Moossen
41  *
42  * @version $Revision: 1.2 $
43  *
44  * @since 6.3.0
45  */

46 public class CmsDefaultValidationHandler implements I_CmsValidationHandler {
47
48     /** The user name constraints. */
49     public static final String JavaDoc USERNAME_CONSTRAINTS = "-._~$@";
50
51     /** The email regular expression. */
52     public static final String JavaDoc EMAIL_REGEX = "^([a-zA-Z0-9_\\.\\-])+\\@(([a-zA-Z0-9\\-])+\\.)+([a-zA-Z0-9]{2,4})+$";
53
54     /** The zipcode regular expression. */
55     public static final String JavaDoc ZIPCODE_REGEX = "[\\w]*";
56
57     /**
58      * A user name can only be composed of digits,
59      * standard ASCII letters and the symbols defined in {@link #USERNAME_CONSTRAINTS}.<p>
60      *
61      * @see org.opencms.security.I_CmsValidationHandler#checkUserName(java.lang.String)
62      */

63     public void checkUserName(String JavaDoc userName) throws CmsIllegalArgumentException {
64
65         if (CmsStringUtil.isEmptyOrWhitespaceOnly(userName)) {
66             throw new CmsIllegalArgumentException(Messages.get().container(Messages.ERR_BAD_USERNAME_EMPTY_0, userName));
67         }
68
69         CmsStringUtil.checkName(userName, USERNAME_CONSTRAINTS, Messages.ERR_BAD_USERNAME_4, Messages.get());
70     }
71
72     /**
73      * @see org.opencms.security.I_CmsValidationHandler#checkGroupName(java.lang.String)
74      */

75     public void checkGroupName(String JavaDoc name) throws CmsIllegalArgumentException {
76
77         if (CmsStringUtil.isEmptyOrWhitespaceOnly(name)) {
78             throw new CmsIllegalArgumentException(Messages.get().container(Messages.ERR_BAD_GROUPNAME_EMPTY_0));
79         }
80     }
81
82     /**
83      * The email should only be composed by digits and standard english letters, points,
84      * underscores and exact one "At" symbol.<p>
85      *
86      * @see org.opencms.security.I_CmsValidationHandler#checkEmail(java.lang.String)
87      */

88     public void checkEmail(String JavaDoc email) throws CmsIllegalArgumentException {
89
90         if (!CmsStringUtil.validateRegex(
91             email,
92             EMAIL_REGEX,
93             false)) {
94             throw new CmsIllegalArgumentException(Messages.get().container(Messages.ERR_EMAIL_VALIDATION_1, email));
95         }
96     }
97
98     /**
99      * That means, the parameter should only be composed by digits and standard english letters.<p>
100      *
101      * @see org.opencms.security.I_CmsValidationHandler#checkZipCode(java.lang.String)
102      */

103     public void checkZipCode(String JavaDoc zipcode) throws CmsIllegalArgumentException {
104
105         if (!CmsStringUtil.validateRegex(zipcode, ZIPCODE_REGEX, true)) {
106             throw new CmsIllegalArgumentException(Messages.get().container(Messages.ERR_ZIPCODE_VALIDATION_1, zipcode));
107         }
108     }
109
110 }
Popular Tags