Source Code Cross Referenced for ChatDelivery.java in  » ERP-CRM-Financial » sakai » org » sakaiproject » chat » tool » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ERP CRM Financial » sakai » org.sakaiproject.chat.tool 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**********************************************************************************
002:         * $URL: https://source.sakaiproject.org/svn/chat/tags/sakai_2-4-1/chat-tool/tool/src/java/org/sakaiproject/chat/tool/ChatDelivery.java $
003:         * $Id: ChatDelivery.java 14062 2006-08-27 03:44:18Z csev@umich.edu $
004:         ***********************************************************************************
005:         *
006:         * Copyright (c) 2003, 2004, 2005, 2006 The Sakai Foundation.
007:         * 
008:         * Licensed under the Educational Community License, Version 1.0 (the "License"); 
009:         * you may not use this file except in compliance with the License. 
010:         * You may obtain a copy of the License at
011:         * 
012:         *      http://www.opensource.org/licenses/ecl1.php
013:         * 
014:         * Unless required by applicable law or agreed to in writing, software 
015:         * distributed under the License is distributed on an "AS IS" BASIS, 
016:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
017:         * See the License for the specific language governing permissions and 
018:         * limitations under the License.
019:         *
020:         **********************************************************************************/package org.sakaiproject.chat.tool;
021:
022:        import org.apache.commons.logging.Log;
023:        import org.apache.commons.logging.LogFactory;
024:        import org.sakaiproject.chat.api.ChatMessage;
025:        import org.sakaiproject.chat.cover.ChatService;
026:        import org.sakaiproject.entity.api.Reference;
027:        import org.sakaiproject.entity.cover.EntityManager;
028:        import org.sakaiproject.event.api.UsageSession;
029:        import org.sakaiproject.event.cover.UsageSessionService;
030:        import org.sakaiproject.exception.IdUnusedException;
031:        import org.sakaiproject.exception.PermissionException;
032:        import org.sakaiproject.message.api.MessageChannel;
033:        import org.sakaiproject.user.api.User;
034:        import org.sakaiproject.user.cover.UserDirectoryService;
035:        import org.sakaiproject.util.BaseDelivery;
036:        import org.sakaiproject.util.StringUtil;
037:        import org.sakaiproject.util.Web;
038:
039:        /**
040:         * <p>
041:         * ChatDelivery is a Delivery that causes a chat message to be appended to a table of chat messages in the HTML element identified by the address and elementID.
042:         * </p>
043:         */
044:        public class ChatDelivery extends BaseDelivery {
045:            /** Our logger. */
046:            private static Log M_log = LogFactory.getLog(ChatDelivery.class);
047:
048:            /** The messageId. */
049:            protected String m_messageId = null;
050:
051:            protected boolean m_beepOnDelivery = false;
052:
053:            /**
054:             * Construct.
055:             * 
056:             * @param address
057:             *        The address.
058:             * @param elementId
059:             *        The elementId.
060:             */
061:            public ChatDelivery(String address, String elementId,
062:                    String messageID, boolean beepOnDelivery) {
063:                super (address, elementId);
064:                m_messageId = messageID;
065:                m_beepOnDelivery = beepOnDelivery;
066:
067:            } // ChatDelivery
068:
069:            /**
070:             * Set the Message Id that this delivery is in reference to.
071:             * 
072:             * @param id
073:             *        The message Id that this delivery is in reference to.
074:             */
075:            public void setMessage(String id) {
076:                m_messageId = id;
077:
078:            } // setMessage
079:
080:            /**
081:             * Access the Message Id that this delivery is in reference to.
082:             * 
083:             * @return The Message Id that this delivery is in reference to.
084:             */
085:            public String getMessage() {
086:                return m_messageId;
087:
088:            } // getMessage
089:
090:            /**
091:             * Compose a javascript message for delivery to the browser client window.
092:             * 
093:             * @return The javascript message to send to the browser client window.
094:             */
095:            public String compose() {
096:                if (M_log.isDebugEnabled())
097:                    M_log.debug("compose() element: " + m_elementId
098:                            + ", message: " + m_messageId);
099:
100:                // generate a string of JavaScript commands to update the message log
101:
102:                Reference ref = EntityManager.newReference(m_messageId);
103:                ChatMessage msg = (ChatMessage) ref.getEntity();
104:                User sender = null;
105:                if (msg != null) {
106:                    sender = msg.getHeader().getFrom();
107:                }
108:                User myself = UserDirectoryService.getCurrentUser();
109:
110:                MessageChannel channel = null;
111:                try {
112:                    String channelRef = ChatService.channelReference(ref
113:                            .getContext(), ref.getContainer());
114:                    channel = ChatService.getChannel(channelRef);
115:                } catch (PermissionException e) {
116:                } catch (IdUnusedException e) {
117:                }
118:
119:                // We may not have a usage session
120:                UsageSession session = UsageSessionService.getSession();
121:                String browserId = UsageSession.UNKNOWN;
122:                if (session != null) {
123:                    browserId = session.getBrowserId();
124:                }
125:
126:                String retval = null;
127:
128:                // if we don't know we can do the DOM based refresh, or we are missing channel or msg (could have been a message delete)
129:                // trigger a panel refresh
130:                boolean browserSupportsDomRefresh = !browserId
131:                        .equals(UsageSession.UNKNOWN);
132:
133:                // TODO: temporary workaround - IE is not liking our DOM refresh, so don't use it there till we get it working -ggolden
134:                if (browserId.equals(UsageSession.WIN_IE))
135:                    browserSupportsDomRefresh = false;
136:
137:                if (!browserSupportsDomRefresh || channel == null
138:                        || msg == null) {
139:                    retval = "try { " + m_elementId
140:                            + ".location.replace(addAuto(" + m_elementId
141:                            + ".location));} catch (error) {}";
142:                }
143:
144:                // otherwise setup for a browser-side javascript DOM modification to insert the message
145:                else {
146:                    String msgbody = Web.escapeJsQuoted(Web
147:                            .escapeHtmlFormattedText(msg.getBody()));
148:
149:                    // is the user we are delivering to allowed to remove this message?
150:                    boolean removeable = false;
151:                    if (channel.allowRemoveMessage(msg))
152:                        removeable = true;
153:
154:                    retval = "try { " + m_elementId + ".appendMessage('"
155:                            + sender.getDisplayName() + "', '" + sender.getId()
156:                            + "', '" + new Boolean(removeable) + "', '"
157:                            + msg.getHeader().getDate().toStringLocalDate()
158:                            + "', '"
159:                            + msg.getHeader().getDate().toStringLocalTimeZ()
160:                            + "', '" + msgbody + "','"
161:                            + msg.getHeader().getId()
162:                            + "'); } catch (error) {} ";
163:                }
164:
165:                if (m_beepOnDelivery && (sender != null)
166:                        && sender.compareTo(myself) != 0) {
167:                    retval += "beep = true;";
168:                }
169:
170:                return retval;
171:
172:            } // compose
173:
174:            /**
175:             * Display.
176:             */
177:            public String toString() {
178:                return super .toString() + " : " + m_messageId;
179:
180:            } // toString
181:
182:            /**
183:             * Are these the same?
184:             * 
185:             * @return true if obj is the same Delivery as this one.
186:             */
187:            public boolean equals(Object obj) {
188:                if (!super .equals(obj))
189:                    return false;
190:
191:                ChatDelivery cob = (ChatDelivery) obj;
192:                if (StringUtil.different(cob.getMessage(), getMessage()))
193:                    return false;
194:
195:                return true;
196:            }
197:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.