Source Code Cross Referenced for ChatMessaging.java in  » Net » QuickServer » chatserver » 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 » Net » QuickServer » chatserver 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * This file is part of the QuickServer library 
003:         * Copyright (C) 2003-2005 QuickServer.org
004:         *
005:         * Use, modification, copying and distribution of this software is subject to
006:         * the terms and conditions of the GNU Lesser General Public License. 
007:         * You should have received a copy of the GNU LGP License along with this 
008:         * library; if not, you can download a copy from <http://www.quickserver.org/>.
009:         *
010:         * For questions, suggestions, bug-reports, enhancement-requests etc.
011:         * visit http://www.quickserver.org
012:         *
013:         */
014:
015:        package chatserver;
016:
017:        import java.io.*;
018:        import java.net.*;
019:        import org.quickserver.net.server.ClientHandler;
020:        import java.util.*;
021:        import java.util.logging.*;
022:
023:        /**
024:         *
025:         * @author  Akshathkumar Shetty
026:         */
027:        public class ChatMessaging {
028:            private static final Logger logger = Logger
029:                    .getLogger(ChatMessaging.class.getName());
030:
031:            public static void sendInfoMessage2Room(ClientHandler handler,
032:                    String room, String msg) throws SocketTimeoutException,
033:                    IOException {
034:                if (room == null || msg == null)
035:                    return;
036:                Iterator iterator = handler.getServer().findAllClientByKey(
037:                        ".+@" + room);
038:                ClientHandler toHandler = null;
039:                if (iterator.hasNext()) {
040:                    while (iterator.hasNext()) {
041:                        if (msg.equals("LoggedOut") == false)
042:                            handler.isConnected();//check if src is still alive
043:                        toHandler = (ClientHandler) iterator.next();
044:                        if (toHandler == handler)
045:                            continue;
046:                        sendInfoMessage(handler, toHandler, msg);
047:                    }
048:                } /*else {
049:                		handler.sendClientMsg("{system.error} MessageNotSent No Clients in that room");
050:                	}*/
051:            }
052:
053:            public static void sendInfoMessage(ClientHandler handler,
054:                    ClientHandler toHandler, String message) throws IOException {
055:                if (message == null)
056:                    return;
057:                logger.fine("From: " + handler + "To: " + toHandler + ", "
058:                        + message);
059:                if (toHandler == null)
060:                    return;
061:
062:                ChatData data = (ChatData) handler.getClientData();
063:                try {
064:                    toHandler.sendClientMsg("{user.info:" + data.getClientKey()
065:                            + "} " + message);
066:                } catch (Exception e) {
067:                    logger.fine("Error sending msg: " + e);
068:                }
069:            }
070:
071:            public static void sendMessageBwUsers(ClientHandler handler,
072:                    ClientHandler toHandler, String message) throws IOException {
073:                logger.fine("From: " + handler + "To: " + toHandler + ", "
074:                        + message);
075:                if (toHandler == null)
076:                    return;
077:
078:                ChatData data = (ChatData) handler.getClientData();
079:                try {
080:                    ChatData toCd = (ChatData) toHandler.getClientData();
081:                    toHandler.sendClientMsg("{user.msg:" + data.getClientKey()
082:                            + ":" + toCd.getClientKey() + "} " + message);
083:                    handler.sendClientMsg("{system.debug} SentMessageTo "
084:                            + toCd.getClientKey());
085:                } catch (Exception e) {
086:                    logger.warning("Error sending msg: " + e);
087:                    handler.sendClientMsg("{system.error} MessageNotSent "
088:                            + e.getMessage());
089:                }
090:            }
091:
092:            public static void sendMessage2Room(ClientHandler handler,
093:                    ClientHandler toHandler, String message) throws IOException {
094:                logger.fine("From: " + handler + "To: " + toHandler + ", "
095:                        + message);
096:                if (toHandler == null)
097:                    return;
098:
099:                ChatData data = (ChatData) handler.getClientData();
100:                try {
101:                    ChatData toCd = (ChatData) toHandler.getClientData();
102:                    toHandler.sendClientMsg("{user.msg:" + data.getClientKey()
103:                            + ":@" + toCd.getRoom() + "} " + message);
104:                    handler.sendClientMsg("{system.debug} SentMessageTo "
105:                            + toCd.getClientKey());
106:                } catch (Exception e) {
107:                    logger.warning("Error sending msg: " + e);
108:                    handler.sendClientMsg("{system.error} MessageNotSent "
109:                            + e.getMessage());
110:                }
111:            }
112:
113:            public static void printHelp(ClientHandler handler, String command)
114:                    throws IOException {
115:                if (command != null)
116:                    handler.sendClientMsg("{system.error} BadCommand "
117:                            + command);
118:                handler.sendClientMsg("{system.help} Sending Message Format:");
119:                handler
120:                        .sendClientMsg("{system.help} sendMsg <<username>> <<message>>");
121:                handler
122:                        .sendClientMsg("{system.help} sendMsg <<username@room>> <<message>>");
123:                handler
124:                        .sendClientMsg("{system.help} sendMsgToRoom <<room_name>> <<message>>");
125:                handler.sendClientMsg("{system.help} userList");
126:                handler.sendClientMsg("{system.help} changeRoom <<room_name>>");
127:            }
128:
129:            public static void sendMsgToRoom(ClientHandler handler,
130:                    String command) throws SocketTimeoutException, IOException {
131:                String room = null;
132:                String message = null;
133:                int i = command.indexOf(" ");
134:                if (i == -1) {
135:                    handler.sendClientMsg("{system.error} BadCommand "
136:                            + command);
137:                    return;
138:                }
139:                int j = command.indexOf(" ", i + 1);
140:                if (j == -1)
141:                    j = command.length();
142:                room = command.substring(i + 1, j);
143:
144:                if (j != command.length())
145:                    message = command.substring(j + 1);
146:                else
147:                    message = "";
148:
149:                Iterator iterator = handler.getServer().findAllClientByKey(
150:                        ".+@" + room);
151:                if (iterator.hasNext()) {
152:                    while (iterator.hasNext()) {
153:                        handler.isConnected();//check if src is still alive
154:                        ChatMessaging.sendMessage2Room(handler,
155:                                (ClientHandler) iterator.next(), message);
156:                    }
157:                } else {
158:                    handler
159:                            .sendClientMsg("{system.error} MessageNotSent No Clients in that room");
160:                }
161:            }
162:
163:            public static void sendMsg(ClientHandler handler, String command)
164:                    throws SocketTimeoutException, IOException {
165:                String id = null;
166:                String message = null;
167:                int i = command.indexOf(" ");
168:                if (i == -1) {
169:                    handler.sendClientMsg("{system.error} BadCommand "
170:                            + command);
171:                    return;
172:                }
173:                int j = command.indexOf(" ", i + 1);
174:                if (j == -1)
175:                    j = command.length();
176:                id = command.substring(i + 1, j);
177:                if (j != command.length())
178:                    message = command.substring(j + 1);
179:                else
180:                    message = "";
181:
182:                ClientHandler toHandler = null;
183:                Iterator iterator = null;
184:                if (id.indexOf("@") != -1) {
185:                    toHandler = handler.getServer().findClientByKey(id);
186:                    List list = new ArrayList();
187:                    if (toHandler != null) {
188:                        logger.finest("Found to by Key: " + toHandler);
189:                        list.add(toHandler);
190:                    }
191:                    iterator = list.iterator();
192:                } else {
193:                    logger.finest("Finding to by Id");
194:                    iterator = handler.getServer().findAllClientById(id);
195:                }
196:
197:                if (iterator.hasNext()) {
198:                    while (iterator.hasNext()) {
199:                        handler.isConnected();//check if src is still alive
200:                        toHandler = (ClientHandler) iterator.next();
201:                        ChatMessaging.sendMessageBwUsers(handler, toHandler,
202:                                message);
203:                    }//end of while
204:                } else {
205:                    handler
206:                            .sendClientMsg("{system.error} MessageNotSent No Client by that id");
207:                }
208:            }
209:
210:            public static void sendRoomList(ClientHandler handler)
211:                    throws SocketTimeoutException, IOException {
212:                ChatData data = (ChatData) handler.getClientData();
213:                Iterator iterator = handler.getServer().findAllClientByKey(
214:                        ".+@" + data.getRoom());
215:                if (iterator.hasNext()) {
216:                    while (iterator.hasNext()) {
217:                        handler.isConnected();//check if src is still alive
218:                        sendList(handler, (ClientHandler) iterator.next());
219:                    }
220:                }
221:            }
222:
223:            public static void sendList(ClientHandler toHandler,
224:                    ClientHandler handler) throws IOException {
225:                logger.finest("From: " + handler + "To: " + toHandler);
226:                if (handler == null)
227:                    return;
228:
229:                ChatData data = (ChatData) handler.getClientData();
230:                try {
231:                    toHandler.sendClientMsg("{user.list} "
232:                            + data.getClientKey());
233:                } catch (Exception e) {
234:                    logger.finest("Error sending msg: " + e);
235:                }
236:            }
237:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.