1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.security.auth;
16  
17  import com.liferay.portal.kernel.util.GetterUtil;
18  import com.liferay.portal.kernel.util.StringPool;
19  import com.liferay.portal.kernel.util.StringUtil;
20  import com.liferay.portal.kernel.util.Validator;
21  
22  /**
23   * <a href="DefaultFullNameGenerator.java.html"><b><i>View Source</i></b></a>
24   *
25   * @author Michael C. Han
26   */
27  public class DefaultFullNameGenerator implements FullNameGenerator {
28  
29      public String getFullName(
30          String firstName, String middleName, String lastName) {
31  
32          StringBuilder sb = new StringBuilder();
33  
34          sb.append(firstName);
35          sb.append(StringPool.SPACE);
36  
37          if (Validator.isNull(middleName)) {
38              sb.append(lastName);
39          }
40          else {
41              sb.append(middleName);
42              sb.append(StringPool.SPACE);
43              sb.append(lastName);
44          }
45  
46          return sb.toString();
47      }
48  
49      public String[] splitFullName(String fullName) {
50          String firstName = StringPool.BLANK;
51          String middleName = StringPool.BLANK;
52          String lastName = StringPool.BLANK;
53  
54          if (Validator.isNotNull(fullName)) {
55              String[] name = StringUtil.split(fullName, StringPool.SPACE);
56  
57              firstName = name[0];
58              middleName = StringPool.BLANK;
59              lastName = name[name.length - 1];
60  
61              if (name.length > 2) {
62                  for (int i = 1; i < name.length - 1; i++) {
63                      if (Validator.isNull(name[i].trim())) {
64                          continue;
65                      }
66  
67                      if (i != 1) {
68                          middleName += StringPool.SPACE;
69                      }
70  
71                      middleName += name[i].trim();
72                  }
73              }
74          }
75          else {
76              firstName = GetterUtil.getString(firstName, lastName);
77              lastName = firstName;
78          }
79  
80          return new String[] {firstName, middleName, lastName};
81      }
82  
83  }