Source Code Cross Referenced for Contacts.java in  » Chat » claros-chat-1.0 » org » claros » chat » ajax » 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 » Chat » claros chat 1.0 » org.claros.chat.ajax 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.claros.chat.ajax;
002:
003:        import java.io.IOException;
004:        import java.io.PrintWriter;
005:        import java.util.ArrayList;
006:        import java.util.Collections;
007:        import java.util.Iterator;
008:
009:        import javax.servlet.ServletException;
010:        import javax.servlet.http.HttpServlet;
011:        import javax.servlet.http.HttpServletRequest;
012:        import javax.servlet.http.HttpServletResponse;
013:        import javax.servlet.http.HttpSession;
014:
015:        import org.claros.chat.models.Contact;
016:        import org.claros.chat.utility.RosterComparator;
017:        import org.jivesoftware.smack.Roster;
018:        import org.jivesoftware.smack.RosterEntry;
019:        import org.jivesoftware.smack.XMPPConnection;
020:        import org.jivesoftware.smack.packet.Presence;
021:        import org.jivesoftware.smack.packet.RosterPacket;
022:
023:        public class Contacts extends HttpServlet {
024:
025:            /**
026:             * 
027:             */
028:            private static final long serialVersionUID = -3626097157006365935L;
029:
030:            /**
031:             * Constructor of the object.
032:             */
033:            public Contacts() {
034:                super ();
035:            }
036:
037:            /**
038:             * The doGet method of the servlet. <br>
039:             *
040:             * This method is called when a form has its tag value method equals to get.
041:             * 
042:             * @param request the request send by the client to the server
043:             * @param response the response send by the server to the client
044:             * @throws ServletException if an error occurred
045:             * @throws IOException if an error occurred
046:             */
047:            public void doGet(HttpServletRequest request,
048:                    HttpServletResponse response) throws ServletException,
049:                    IOException {
050:                doPost(request, response);
051:            }
052:
053:            /**
054:             * The doPost method of the servlet. <br>
055:             *
056:             * This method is called when a form has its tag value method equals to post.
057:             * 
058:             * @param request the request send by the client to the server
059:             * @param response the response send by the server to the client
060:             * @throws ServletException if an error occurred
061:             * @throws IOException if an error occurred
062:             */
063:            public void doPost(HttpServletRequest request,
064:                    HttpServletResponse response) throws ServletException,
065:                    IOException {
066:
067:                // get the printwriter and prepare the html
068:                response.setHeader("Expires", "-1");
069:                response.setHeader("Pragma", "no-cache");
070:                response.setHeader("Cache-control", "no-cache");
071:                response.setHeader("Content-Type", "text/html; charset=utf-8");
072:
073:                PrintWriter out = response.getWriter();
074:
075:                XMPPConnection conn = (XMPPConnection) request.getSession()
076:                        .getAttribute("conn");
077:
078:                if (conn != null) {
079:                    Roster roster = conn.getRoster();
080:                    roster.setSubscriptionMode(Roster.SUBSCRIPTION_ACCEPT_ALL);
081:                    ArrayList contacts = new ArrayList();
082:                    RosterEntry en = null;
083:                    Contact cn = null;
084:                    for (Iterator i = roster.getEntries(); i.hasNext();) {
085:                        en = (RosterEntry) i.next();
086:                        cn = new Contact();
087:                        cn.setName(en.getName());
088:                        if (cn.getName() == null) {
089:                            cn.setName(en.getUser());
090:                            if (cn.getName().indexOf("@") > 0) {
091:                                cn.setName(cn.getName().substring(0,
092:                                        cn.getName().indexOf("@")));
093:                            }
094:                        }
095:
096:                        RosterPacket.ItemStatus st = en.getStatus();
097:                        if (st != null
098:                                && st
099:                                        .equals(RosterPacket.ItemStatus.SUBSCRIPTION_PENDING)) {
100:                            cn.setStatus("pending");
101:                        }
102:
103:                        Presence pr = roster.getPresence(en.getUser());
104:                        if (pr != null) {
105:                            Presence.Mode md = pr.getMode();
106:                            if (md != null) {
107:                                if (md.equals(Presence.Mode.AVAILABLE)) {
108:                                    cn.setPresence("available");
109:                                } else if (md.equals(Presence.Mode.AWAY)) {
110:                                    cn.setPresence("away");
111:                                } else if (md.equals(Presence.Mode.CHAT)) {
112:                                    cn.setPresence("chat");
113:                                } else if (md
114:                                        .equals(Presence.Mode.DO_NOT_DISTURB)) {
115:                                    cn.setPresence("disturb");
116:                                } else if (md
117:                                        .equals(Presence.Mode.EXTENDED_AWAY)) {
118:                                    cn.setPresence("extended_away");
119:                                } else if (md.equals(Presence.Mode.INVISIBLE)) {
120:                                    cn.setPresence("invisible");
121:                                }
122:                                if (pr.getStatus() != null
123:                                        && !pr.getStatus().equals("")) {
124:                                    cn.setMessage(pr.getStatus());
125:                                }
126:                            }
127:                        }
128:                        if (cn.getPresence() == null) {
129:                            cn.setPresence("offline");
130:                        }
131:                        cn.setUser(en.getUser());
132:                        contacts.add(cn);
133:
134:                    }
135:                    Collections.sort(contacts, new RosterComparator());
136:                    request.getSession().setAttribute("contacts", contacts);
137:
138:                    // all contacts are set, now generate the output
139:                    Contact tmp = null;
140:                    for (int i = 0; i < contacts.size(); i++) {
141:                        tmp = (Contact) contacts.get(i);
142:                        //				if (!tmp.getPresence().equals("offline")) {
143:                        out
144:                                .println("<div id=\"contact\" onclick=\"openChat(this);\" ondblclick=\"openChat(this);\" onmouseover=\"showInfoWin(this);\" onmouseout=\"unhoverContact(this);\" "
145:                                        + "user=\""
146:                                        + tmp.getUser()
147:                                        + "\" username=\""
148:                                        + tmp.getName()
149:                                        + "\" presence=\""
150:                                        + tmp.getPresence()
151:                                        + "\" msg=\""
152:                                        + tmp.getMessage()
153:                                        + "\">");
154:                        out
155:                                .println("<table width=\"134\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" height=\"20\">");
156:                        out.println("  <tr>");
157:                        String color = "gray";
158:                        if (tmp.getPresence().equals("available")) {
159:                            color = "green";
160:                        } else if (tmp.getPresence().equals("away")) {
161:                            color = "orange";
162:                        } else if (tmp.getPresence().equals("chat")) {
163:                            color = "green";
164:                        } else if (tmp.getPresence().equals("disturb")) {
165:                            color = "red";
166:                        } else if (tmp.getPresence().equals("extended_away")) {
167:                            color = "red";
168:                        } else if (tmp.getPresence().equals("invisible")) {
169:                            color = "orange";
170:                        }
171:                        out
172:                                .println("	<td width=\"10\"><img src=\"img/indicators/"
173:                                        + color
174:                                        + ".gif\" id=\"indicator\"/></td>");
175:                        out.println("	<td width=\"124\">");
176:                        out.println("		<div id=\"contactname\">");
177:                        out
178:                                .println("			<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"124\" height=\"20\">");
179:                        out
180:                                .println("				<tr><td nowrap=\"nowrap\"><a href=\"#\">"
181:                                        + tmp.getName() + "</a></td>");
182:                        out.println("				</tr>");
183:                        out.println("			</table>");
184:                        out.println("		</div>");
185:                        out.println("	</td>");
186:                        out.println("  </tr>");
187:                        out.println("</table>");
188:                        out.println("</div>");
189:                    }
190:                    //			}
191:                } else {
192:                    out
193:                            .print("<br /><br /><br /><div align=\"center\"><img src=\"img/loading.gif\" width=\"32\" height=\"32\">");
194:                }
195:
196:                out.flush();
197:                out.close();
198:            }
199:
200:            /**
201:             * Initialization of the servlet. <br>
202:             *
203:             * @throws ServletException if an error occure
204:             */
205:            public void init() throws ServletException {
206:                // Put your code here
207:            }
208:
209:            public static String findNameByUser(HttpSession sess, String user) {
210:                ArrayList contacts = (ArrayList) sess.getAttribute("contacts");
211:                if (contacts != null) {
212:                    Contact tmp = null;
213:                    String adr = null;
214:                    for (int i = 0; i < contacts.size(); i++) {
215:                        tmp = (Contact) contacts.get(i);
216:                        adr = tmp.getUser().substring(0);
217:                        if (adr.indexOf("@") > 0) {
218:                            adr = adr.substring(0, adr.indexOf("@"));
219:                        }
220:                        if (adr.equals(user)) {
221:                            if (tmp.getName() != null) {
222:                                return tmp.getName();
223:                            }
224:                        }
225:                    }
226:                }
227:                return user;
228:            }
229:
230:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.