001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.model;
016    
017    import com.liferay.portal.kernel.language.LanguageUtil;
018    import com.liferay.portal.kernel.util.StringPool;
019    import com.liferay.portal.kernel.util.StringUtil;
020    
021    import java.util.Locale;
022    
023    /**
024     * Contains constants used by roles, including the names of the default roles
025     * and the role types.
026     *
027     * @author Brian Wing Shun Chan
028     */
029    public class RoleConstants {
030    
031            public static final String ADMINISTRATOR = "Administrator";
032    
033            public static final String GUEST = "Guest";
034    
035            public static final String NAME_INVALID_CHARACTERS =
036                    StringPool.COMMA + StringPool.SPACE + StringPool.STAR;
037    
038            public static final String NAME_LABEL = "role-name";
039    
040            public static final String NAME_RESERVED_WORDS = StringPool.NULL;
041    
042            public static final String ORGANIZATION_ADMINISTRATOR =
043                    "Organization Administrator";
044    
045            public static final String ORGANIZATION_OWNER = "Organization Owner";
046    
047            public static final String ORGANIZATION_USER = "Organization User";
048    
049            public static final String OWNER = "Owner";
050    
051            public static final String PLACEHOLDER_DEFAULT_GROUP_ROLE =
052                    "PLACEHOLDER_DEFAULT_GROUP_ROLE";
053    
054            public static final String PORTAL_CONTENT_REVIEWER =
055                    "Portal Content Reviewer";
056    
057            public static final String POWER_USER = "Power User";
058    
059            public static final String SITE_ADMINISTRATOR = "Site Administrator";
060    
061            public static final String SITE_CONTENT_REVIEWER = "Site Content Reviewer";
062    
063            public static final String SITE_MEMBER = "Site Member";
064    
065            public static final String SITE_OWNER = "Site Owner";
066    
067            public static final String[] SYSTEM_ORGANIZATION_ROLES = {
068                    ORGANIZATION_ADMINISTRATOR, ORGANIZATION_OWNER, ORGANIZATION_USER
069            };
070    
071            public static final String[] SYSTEM_ROLES = {
072                    ADMINISTRATOR, GUEST, OWNER, POWER_USER, RoleConstants.USER
073            };
074    
075            public static final String[] SYSTEM_SITE_ROLES = {
076                    SITE_ADMINISTRATOR, SITE_MEMBER, SITE_OWNER
077            };
078    
079            public static final int TYPE_ORGANIZATION = 3;
080    
081            public static final String TYPE_ORGANIZATION_LABEL = "organization";
082    
083            public static final int TYPE_PROVIDER = 4;
084    
085            public static final int TYPE_REGULAR = 1;
086    
087            public static final String TYPE_REGULAR_LABEL = "regular";
088    
089            public static final int TYPE_SITE = 2;
090    
091            public static final String TYPE_SITE_LABEL = "site";
092    
093            public static final int[] TYPES_ORGANIZATION_AND_REGULAR =
094                    {TYPE_REGULAR, TYPE_ORGANIZATION};
095    
096            public static final int[] TYPES_ORGANIZATION_AND_REGULAR_AND_SITE = {
097                    TYPE_REGULAR, TYPE_ORGANIZATION, TYPE_SITE
098            };
099    
100            public static final int[] TYPES_REGULAR = {TYPE_REGULAR};
101    
102            public static final int[] TYPES_REGULAR_AND_SITE =
103                    {TYPE_REGULAR, TYPE_SITE};
104    
105            public static final String USER = "User";
106    
107            public static String getNameGeneralRestrictions(
108                    Locale locale, boolean allowNumeric) {
109    
110                    String nameGeneralRestrictions = StringUtil.toLowerCase(
111                            LanguageUtil.get(locale, "blank"));
112    
113                    if (!allowNumeric) {
114                            nameGeneralRestrictions +=
115                                    StringPool.COMMA_AND_SPACE +
116                                            StringUtil.toLowerCase(LanguageUtil.get(locale, "numeric"));
117                    }
118    
119                    return nameGeneralRestrictions;
120            }
121    
122            public static String getTypeLabel(int type) {
123                    if (type == TYPE_ORGANIZATION) {
124                            return TYPE_ORGANIZATION_LABEL;
125                    }
126                    else if (type == TYPE_SITE) {
127                            return TYPE_SITE_LABEL;
128                    }
129                    else {
130                            return TYPE_REGULAR_LABEL;
131                    }
132            }
133    
134    }