KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > roller > ui > core > struts > actions > UserBaseAction


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. The ASF licenses this file to You
4  * under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License. For additional information regarding
15  * copyright in this work, please see the NOTICE file in the top level
16  * directory of this distribution.
17  */

18
19 package org.apache.roller.ui.core.struts.actions;
20
21 import org.apache.commons.lang.CharSetUtils;
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24 import org.apache.struts.action.ActionError;
25 import org.apache.struts.action.ActionErrors;
26 import org.apache.struts.action.ActionMessages;
27 import org.apache.struts.actions.DispatchAction;
28 import org.apache.roller.config.RollerConfig;
29 import org.apache.roller.ui.authoring.struts.formbeans.UserFormEx;
30
31
32 /**
33  * Base class for user actions.
34  */

35 public class UserBaseAction extends DispatchAction {
36     
37     private static Log mLogger = LogFactory.getLog(UserBaseAction.class);
38     
39     protected static String JavaDoc DEFAULT_ALLOWED_CHARS = "A-Za-z0-9";
40     
41     
42     /** Validate user form. TODO: replace with Struts validation. */
43     protected ActionMessages validate( UserFormEx form, ActionMessages errors ) {
44         
45         String JavaDoc allowed = RollerConfig.getProperty("username.allowedChars");
46         if(allowed == null || allowed.trim().length() == 0) {
47             allowed = DEFAULT_ALLOWED_CHARS;
48         }
49         String JavaDoc safe = CharSetUtils.keep(form.getUserName(), allowed);
50         
51         if ( "".equals(form.getUserName().trim())) {
52             errors.add( ActionErrors.GLOBAL_ERROR,
53                     new ActionError("error.add.user.missingUserName"));
54         } else if ( !safe.equals(form.getUserName()) ) {
55             errors.add( ActionErrors.GLOBAL_ERROR,
56                     new ActionError("error.add.user.badUserName"));
57         }
58         
59         if ( "".equals(form.getEmailAddress().trim())) {
60             errors.add( ActionErrors.GLOBAL_ERROR,
61                     new ActionError("error.add.user.missingEmailAddress"));
62         }
63         return errors;
64     }
65     
66 }
67
68
69
70
71
72
73
Popular Tags