001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portal.model.impl;
022:
023: import com.liferay.portal.PortalException;
024: import com.liferay.portal.SystemException;
025: import com.liferay.portal.kernel.util.Base64;
026: import com.liferay.portal.kernel.util.StringPool;
027: import com.liferay.portal.kernel.util.Validator;
028: import com.liferay.portal.model.Account;
029: import com.liferay.portal.model.Company;
030: import com.liferay.portal.model.User;
031: import com.liferay.portal.service.AccountLocalServiceUtil;
032: import com.liferay.portal.service.UserLocalServiceUtil;
033: import com.liferay.portal.util.PrefsPropsUtil;
034: import com.liferay.portal.util.PropsUtil;
035: import com.liferay.portal.util.PropsValues;
036:
037: import java.security.Key;
038:
039: import java.util.Locale;
040: import java.util.TimeZone;
041:
042: import org.apache.commons.logging.Log;
043: import org.apache.commons.logging.LogFactory;
044:
045: /**
046: * <a href="CompanyImpl.java.html"><b><i>View Source</i></b></a>
047: *
048: * @author Brian Wing Shun Chan
049: *
050: */
051: public class CompanyImpl extends CompanyModelImpl implements Company {
052:
053: public static final String DEFAULT_WEB_ID = PropsUtil
054: .get(PropsUtil.COMPANY_DEFAULT_WEB_ID);
055:
056: public static final String AUTH_TYPE_EA = "emailAddress";
057:
058: public static final String AUTH_TYPE_SN = "screenName";
059:
060: public static final String AUTH_TYPE_ID = "userId";
061:
062: public static final long SYSTEM = 0;
063:
064: public static final String SYSTEM_STRING = String.valueOf(SYSTEM);
065:
066: public CompanyImpl() {
067: }
068:
069: public void setKey(String key) {
070: _keyObj = null;
071:
072: super .setKey(key);
073: }
074:
075: public Key getKeyObj() {
076: if (_keyObj == null) {
077: String key = getKey();
078:
079: if (Validator.isNotNull(key)) {
080: _keyObj = (Key) Base64.stringToObject(key);
081: }
082: }
083:
084: return _keyObj;
085: }
086:
087: public void setKeyObj(Key keyObj) {
088: _keyObj = keyObj;
089:
090: super .setKey(Base64.objectToString(keyObj));
091: }
092:
093: public Account getAccount() {
094: Account account = null;
095:
096: try {
097: account = AccountLocalServiceUtil
098: .getAccount(getAccountId());
099: } catch (Exception e) {
100: account = new AccountImpl();
101:
102: _log.error(e);
103: }
104:
105: return account;
106: }
107:
108: public String getName() {
109: return getAccount().getName();
110: }
111:
112: public String getShortName() {
113: return getName();
114: }
115:
116: public String getEmailAddress() {
117:
118: // Primary email address
119:
120: return "admin@" + getMx();
121: }
122:
123: public User getDefaultUser() {
124: User defaultUser = null;
125:
126: try {
127: defaultUser = UserLocalServiceUtil
128: .getDefaultUser(getCompanyId());
129: } catch (Exception e) {
130: _log.error(e);
131: }
132:
133: return defaultUser;
134: }
135:
136: public Locale getLocale() {
137: return getDefaultUser().getLocale();
138: }
139:
140: public TimeZone getTimeZone() {
141: return getDefaultUser().getTimeZone();
142: }
143:
144: public String getAdminName() {
145: return "Administrator";
146: }
147:
148: public String getAuthType() throws PortalException, SystemException {
149: return PrefsPropsUtil.getString(getCompanyId(),
150: PropsUtil.COMPANY_SECURITY_AUTH_TYPE,
151: PropsValues.COMPANY_SECURITY_AUTH_TYPE);
152: }
153:
154: public boolean isAutoLogin() throws PortalException,
155: SystemException {
156: return PrefsPropsUtil.getBoolean(getCompanyId(),
157: PropsUtil.COMPANY_SECURITY_AUTO_LOGIN,
158: PropsValues.COMPANY_SECURITY_AUTO_LOGIN);
159: }
160:
161: public boolean isSendPassword() throws PortalException,
162: SystemException {
163: return PrefsPropsUtil.getBoolean(getCompanyId(),
164: PropsUtil.COMPANY_SECURITY_SEND_PASSWORD,
165: PropsValues.COMPANY_SECURITY_SEND_PASSWORD);
166: }
167:
168: public boolean isStrangers() throws PortalException,
169: SystemException {
170: return PrefsPropsUtil.getBoolean(getCompanyId(),
171: PropsUtil.COMPANY_SECURITY_STRANGERS,
172: PropsValues.COMPANY_SECURITY_STRANGERS);
173: }
174:
175: public boolean isStrangersWithMx() throws PortalException,
176: SystemException {
177: return PrefsPropsUtil.getBoolean(getCompanyId(),
178: PropsUtil.COMPANY_SECURITY_STRANGERS_WITH_MX,
179: PropsValues.COMPANY_SECURITY_STRANGERS_WITH_MX);
180: }
181:
182: public boolean isStrangersVerify() throws PortalException,
183: SystemException {
184: return PrefsPropsUtil.getBoolean(getCompanyId(),
185: PropsUtil.COMPANY_SECURITY_STRANGERS_VERIFY,
186: PropsValues.COMPANY_SECURITY_STRANGERS_VERIFY);
187: }
188:
189: public boolean isCommunityLogo() throws PortalException,
190: SystemException {
191: return PrefsPropsUtil.getBoolean(getCompanyId(),
192: PropsUtil.COMPANY_SECURITY_COMMUNITY_LOGO,
193: PropsValues.COMPANY_SECURITY_COMMUNITY_LOGO);
194: }
195:
196: public boolean hasCompanyMx(String emailAddress) {
197: emailAddress = emailAddress.trim().toLowerCase();
198:
199: int pos = emailAddress.indexOf(StringPool.AT);
200:
201: if (pos == -1) {
202: return false;
203: }
204:
205: String mx = emailAddress.substring(pos + 1, emailAddress
206: .length());
207:
208: if (mx.equals(getMx())) {
209: return true;
210: }
211:
212: try {
213: String[] mailHostNames = PrefsPropsUtil.getStringArray(
214: getCompanyId(), PropsUtil.ADMIN_MAIL_HOST_NAMES,
215: StringPool.NEW_LINE,
216: PropsValues.ADMIN_MAIL_HOST_NAMES);
217:
218: for (int i = 0; i < mailHostNames.length; i++) {
219: if (mx.equalsIgnoreCase(mailHostNames[i])) {
220: return true;
221: }
222: }
223: } catch (Exception e) {
224: _log.error(e);
225: }
226:
227: return false;
228: }
229:
230: public int compareTo(Object obj) {
231: Company company = (Company) obj;
232:
233: String webId1 = getWebId();
234: String webId2 = company.getWebId();
235:
236: if (webId1.equals(DEFAULT_WEB_ID)) {
237: return -1;
238: } else if (webId2.equals(DEFAULT_WEB_ID)) {
239: return 1;
240: } else {
241: return webId1.compareTo(webId2);
242: }
243: }
244:
245: private static Log _log = LogFactory.getLog(CompanyImpl.class);
246:
247: private Key _keyObj = null;
248:
249: }
|