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.kernel.util.StringPool;
024: import com.liferay.portal.model.User;
025: import com.liferay.portal.model.UserTracker;
026: import com.liferay.portal.model.UserTrackerPath;
027: import com.liferay.portal.service.UserLocalServiceUtil;
028:
029: import java.util.ArrayList;
030: import java.util.List;
031:
032: import javax.servlet.http.HttpSession;
033:
034: import org.apache.commons.logging.Log;
035: import org.apache.commons.logging.LogFactory;
036:
037: /**
038: * <a href="UserTrackerImpl.java.html"><b><i>View Source</i></b></a>
039: *
040: * @author Brian Wing Shun Chan
041: *
042: */
043: public class UserTrackerImpl extends UserTrackerModelImpl implements
044: UserTracker {
045:
046: public UserTrackerImpl() {
047: }
048:
049: public HttpSession getHttpSession() {
050: return _ses;
051: }
052:
053: public void setHttpSession(HttpSession ses) {
054: _ses = ses;
055:
056: setSessionId(_ses.getId());
057: }
058:
059: public String getFullName() {
060: if (_fullName == null) {
061: try {
062: if (_user == null) {
063: _user = UserLocalServiceUtil
064: .getUserById(getUserId());
065: }
066:
067: _fullName = _user.getFullName();
068: } catch (Exception e) {
069: }
070: }
071:
072: if (_fullName == null) {
073: _fullName = StringPool.BLANK;
074: }
075:
076: return _fullName;
077: }
078:
079: public String getEmailAddress() {
080: if (_emailAddress == null) {
081: try {
082: if (_user == null) {
083: _user = UserLocalServiceUtil
084: .getUserById(getUserId());
085: }
086:
087: _emailAddress = _user.getEmailAddress();
088: } catch (Exception e) {
089: }
090: }
091:
092: if (_emailAddress == null) {
093: _emailAddress = StringPool.BLANK;
094: }
095:
096: return _emailAddress;
097: }
098:
099: public List getPaths() {
100: return _paths;
101: }
102:
103: public void addPath(UserTrackerPath path) {
104: try {
105: _paths.add(path);
106: } catch (ArrayIndexOutOfBoundsException aioobe) {
107: if (_log.isWarnEnabled()) {
108: _log.warn(aioobe);
109: }
110: }
111:
112: setModifiedDate(path.getPathDate());
113: }
114:
115: public int getHits() {
116: return _paths.size();
117: }
118:
119: public int compareTo(Object obj) {
120: UserTracker userTracker = (UserTracker) obj;
121:
122: String userName1 = getFullName().toLowerCase();
123: String userName2 = userTracker.getFullName().toLowerCase();
124:
125: int value = userName1.compareTo(userName2);
126:
127: if (value == 0) {
128: value = getModifiedDate().compareTo(
129: userTracker.getModifiedDate());
130: }
131:
132: return value;
133: }
134:
135: private static Log _log = LogFactory.getLog(UserTrackerImpl.class);
136:
137: private HttpSession _ses;
138: private User _user;
139: private String _fullName;
140: private String _emailAddress;
141: private List _paths = new ArrayList();
142:
143: }
|