01: /**********************************************************************************
02: * $URL: https://source.sakaiproject.org/svn/portal/trunk/portal-util/util/src/java/org/sakaiproject/portal/util/PortalSiteHelper.java $
03: * $Id: PortalSiteHelper.java 21708 2007-02-18 21:59:28Z ian@caret.cam.ac.uk $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2007 The Sakai Foundation.
07: *
08: * Licensed under the Educational Community License, Version 1.0 (the "License");
09: * you may not use this file except in compliance with the License.
10: * You may obtain a copy of the License at
11: *
12: * http://www.opensource.org/licenses/ecl1.php
13: *
14: * Unless required by applicable law or agreed to in writing, software
15: * distributed under the License is distributed on an "AS IS" BASIS,
16: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: * See the License for the specific language governing permissions and
18: * limitations under the License.
19: *
20: **********************************************************************************/package org.sakaiproject.chat2.tool;
21:
22: import org.sakaiproject.chat2.model.ChatMessage;
23: import org.sakaiproject.time.api.Time;
24: import org.sakaiproject.time.cover.TimeService;
25:
26: public class DecoratedChatMessage {
27:
28: private ChatMessage chatMessage;
29:
30: private ChatTool chatTool;
31:
32: private Time messageTime;
33:
34: public DecoratedChatMessage(ChatTool chatTool,
35: ChatMessage chatMessage) {
36: this .chatTool = chatTool;
37: this .chatMessage = chatMessage;
38: messageTime = TimeService.newTime(chatMessage.getMessageDate()
39: .getTime());
40: }
41:
42: public String getColor() {
43: return chatTool.getColorMapper().getColor(
44: chatMessage.getOwner());
45: }
46:
47: public ChatMessage getChatMessage() {
48: return chatMessage;
49: }
50:
51: public String getDateTime() {
52: return messageTime.toStringLocalFullZ();
53: }
54:
55: public String getDate() {
56: return messageTime.toStringLocalDate();
57: }
58:
59: public String getTime() {
60: return messageTime.toStringLocalTimeZ();
61: }
62:
63: /**
64: * Returns the body of the message, but limited to the number of characters
65: * specified in the tool's configuration properties
66: * @return
67: */
68: public String getRestrictedBody() {
69: String message = chatMessage.getBody();
70: int maxLength = chatTool.lookupSynopticOptions().getChars();
71: int actualLength = message.length();
72: if (maxLength < actualLength) {
73: message = message.substring(0, maxLength).concat("...");
74: }
75: return message;
76: }
77:
78: public boolean getCanRemoveMessage() {
79: return chatTool.getCanRemoveMessage(chatMessage);
80: }
81:
82: public String processActionDeleteMessage() {
83: return chatTool.processActionDeleteMessageConfirm(this );
84: }
85:
86: public String getOwner() {
87: return chatTool.getMessageOwnerDisplayName(chatMessage);
88: }
89:
90: public ChatTool getChatTool() {
91: return chatTool;
92: }
93:
94: }
|