1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-22 20:12:07 +01:00

Use filters. Use context params.

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@1880 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Matt Tucker 2003-04-11 15:52:16 +00:00 committed by mtucker
parent 4ae4e66cbf
commit 3b9f9e7c12

View file

@ -3,7 +3,7 @@
* $Revision$ * $Revision$
* $Date$ * $Date$
* *
* Copyright (C) 2003 CoolServlets, Inc. All rights reserved. * Copyright (C) 2003 Jive Software. All rights reserved.
* *
* This software is the proprietary information of Jive Software. Use is subject to license terms. * This software is the proprietary information of Jive Software. Use is subject to license terms.
*/ */
@ -15,9 +15,7 @@ import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smack.packet.Message; import org.jivesoftware.smack.packet.Message;
import javax.servlet.http.*; import javax.servlet.http.*;
import javax.servlet.ServletException; import javax.servlet.*;
import javax.servlet.ServletConfig;
import javax.servlet.RequestDispatcher;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.util.*; import java.util.*;
@ -36,6 +34,8 @@ import java.util.*;
public class ChatServlet extends HttpServlet implements HttpSessionListener { public class ChatServlet extends HttpServlet implements HttpSessionListener {
private Map chatData = new HashMap(); private Map chatData = new HashMap();
private EmoticonFilter emoticonFilter = new EmoticonFilter();
private URLFilter urlFilter = new URLFilter();
private String host; private String host;
private int port = -1; private int port = -1;
@ -43,11 +43,12 @@ public class ChatServlet extends HttpServlet implements HttpSessionListener {
public void init(ServletConfig config) throws ServletException { public void init(ServletConfig config) throws ServletException {
super.init(config); super.init(config);
host = config.getInitParameter("host"); ServletContext context = config.getServletContext();
host = context.getInitParameter("host");
if (host == null) { if (host == null) {
throw new ServletException("Init parameter \"host\" must be set."); throw new ServletException("Init parameter \"host\" must be set.");
} }
String portString = config.getInitParameter("port"); String portString = context.getInitParameter("port");
if (portString != null) { if (portString != null) {
try { try {
port = Integer.parseInt(portString); port = Integer.parseInt(portString);
@ -56,7 +57,7 @@ public class ChatServlet extends HttpServlet implements HttpSessionListener {
throw new ServletException("Init parameter \"port\" must be a valid number.", nfe); throw new ServletException("Init parameter \"port\" must be a valid number.", nfe);
} }
} }
SSLEnabled = Boolean.valueOf(config.getInitParameter("SSLEnabled")).booleanValue(); SSLEnabled = Boolean.valueOf(context.getInitParameter("SSLEnabled")).booleanValue();
} }
public void destroy() { public void destroy() {
@ -156,6 +157,9 @@ public class ChatServlet extends HttpServlet implements HttpSessionListener {
body = replace(body, "\n", "<br>"); body = replace(body, "\n", "<br>");
// escape quotes // escape quotes
body = replace(body, "\"", "&quot;"); body = replace(body, "\"", "&quot;");
// Apply emoticons
body = urlFilter.applyFilter(body);
body = emoticonFilter.applyFilter(body);
reply.append("data[data.length] = new Array(\"" + from + "\", \"" + body + "\");\n"); reply.append("data[data.length] = new Array(\"" + from + "\", \"" + body + "\");\n");
message = data.groupChat.pollMessage(); message = data.groupChat.pollMessage();
} }
@ -190,7 +194,6 @@ public class ChatServlet extends HttpServlet implements HttpSessionListener {
String password = request.getParameter("password"); String password = request.getParameter("password");
String room = request.getParameter("room"); String room = request.getParameter("room");
String nickname = request.getParameter("nickname"); String nickname = request.getParameter("nickname");
String garbage = request.getParameter("garbage");
// Validate parameters // Validate parameters
Map errors = new HashMap(); Map errors = new HashMap();
if (username == null || "".equals(username.trim())) { if (username == null || "".equals(username.trim())) {
@ -239,7 +242,7 @@ public class ChatServlet extends HttpServlet implements HttpSessionListener {
} }
} }
// Login // Login
data.connection.login(username, password, "Jive Messenger Chat Servlet " + garbage); data.connection.login(username, password, "WebChat");
// Join groupChat room. // Join groupChat room.
data.groupChat = data.connection.createGroupChat(room); data.groupChat = data.connection.createGroupChat(room);
data.groupChat.join(nickname); data.groupChat.join(nickname);
@ -252,8 +255,7 @@ public class ChatServlet extends HttpServlet implements HttpSessionListener {
request.getSession().setAttribute("messenger.servlet.nickname", nickname); request.getSession().setAttribute("messenger.servlet.nickname", nickname);
} }
catch (XMPPException e) { catch (XMPPException e) {
errors.put("general",""); errors.put("general", e.getMessage());
e.printStackTrace();
} }
catch (ClassCastException e) { catch (ClassCastException e) {
// TODO: remove this catch - it's just a bug workaround for now // TODO: remove this catch - it's just a bug workaround for now