KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > cms > applications > managementtool > actions > ViewMessageCenterAction


1 /* ===============================================================================
2  *
3  * Part of the InfoGlue Content Management Platform (www.infoglue.org)
4  *
5  * ===============================================================================
6  *
7  * Copyright (C)
8  *
9  * This program is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License version 2, as published by the
11  * Free Software Foundation. See the file LICENSE.html for more information.
12  *
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along with
18  * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
19  * Place, Suite 330 / Boston, MA 02111-1307 / USA.
20  *
21  * ===============================================================================
22  */

23
24 package org.infoglue.cms.applications.managementtool.actions;
25
26 import java.util.ArrayList JavaDoc;
27 import java.util.List JavaDoc;
28
29 import org.infoglue.cms.applications.common.actions.InfoGlueAbstractAction;
30 import org.infoglue.cms.entities.management.Chat;
31 import org.infoglue.cms.entities.management.Message;
32 import org.infoglue.cms.util.CmsSessionContextListener;
33
34 /**
35  * This class represents the message center where you can chat with users
36  *
37  * @author mattias
38  */

39
40 public class ViewMessageCenterAction extends InfoGlueAbstractAction
41 {
42     private static final long serialVersionUID = 1L;
43
44     private static Chat systemMessagesChat = new Chat();
45     private static Chat chat = new Chat();
46     private Integer JavaDoc lastId;
47     private String JavaDoc userName;
48     private String JavaDoc message;
49     private boolean isSystemMessage = false;
50     private List JavaDoc messages;
51     
52     private Integer JavaDoc INDEX_MESSAGE_TYPE = new Integer JavaDoc(-1);
53     private Integer JavaDoc SYSTEM_MESSAGE_TYPE = new Integer JavaDoc(0);
54     private Integer JavaDoc CHAT_MESSAGE_TYPE = new Integer JavaDoc(10);
55     
56     
57     public String JavaDoc doExecute() throws Exception JavaDoc
58     {
59         return "success";
60     }
61
62     public String JavaDoc doStandaloneChat() throws Exception JavaDoc
63     {
64         return "successStandaloneChat";
65     }
66
67     public String JavaDoc doGetMessages() throws Exception JavaDoc
68     {
69         if(lastId == null || lastId.intValue() == -1)
70             messages = chat.getMessages();
71         else
72             messages = chat.getMessages(lastId.intValue());
73
74         return "successGetMessages";
75     }
76
77     public String JavaDoc doGetSystemMessages() throws Exception JavaDoc
78     {
79         if(lastId == null || lastId.intValue() == -1)
80         {
81             Message message = new Message(systemMessagesChat.getMessageId(), "administrator", INDEX_MESSAGE_TYPE, "Undefined");
82             messages = new ArrayList JavaDoc();
83             messages.add(message);
84         }
85         else
86             messages = systemMessagesChat.getMessages(lastId.intValue());
87
88         return "successGetSystemMessages";
89     }
90
91     public String JavaDoc doSendMessage() throws Exception JavaDoc
92     {
93         //System.out.println("Adding message:" + message);
94

95         chat.addMessage(this.getUserName(), CHAT_MESSAGE_TYPE, this.message);
96         //System.out.println("this.isSystemMessage:" + this.isSystemMessage);
97
if(this.isSystemMessage)
98             systemMessagesChat.addMessage(this.getUserName(), SYSTEM_MESSAGE_TYPE, "openChat('" + this.message + "');");
99         
100         return "successMessageSent";
101     }
102
103     public List JavaDoc getSessionInfoBeanList()
104     {
105         return CmsSessionContextListener.getSessionInfoBeanList();
106     }
107     
108     public String JavaDoc getMessage()
109     {
110         return message;
111     }
112
113     public void setMessage(String JavaDoc message)
114     {
115         this.message = message;
116     }
117
118     public List JavaDoc getMessages()
119     {
120         return messages;
121     }
122
123     public Integer JavaDoc getLastId()
124     {
125         return lastId;
126     }
127
128     public void setLastId(Integer JavaDoc lastId)
129     {
130         this.lastId = lastId;
131     }
132     
133     public void setIsSystemMessage(boolean isSystemMessage)
134     {
135         this.isSystemMessage = isSystemMessage;
136     }
137 }
138
Popular Tags