/sun/SimpleChat/trunk/src/ak/simplechat/MessageAction.java |
---|
0,0 → 1,32 |
package ak.simplechat; |
import java.util.List; |
import javax.servlet.http.HttpServletRequest; |
import javax.servlet.http.HttpServletResponse; |
import org.apache.struts.action.Action; |
import org.apache.struts.action.ActionMapping; |
import org.apache.struts.action.ActionForm; |
import org.apache.struts.action.ActionForward; |
public final class MessageAction |
extends Action |
{ |
public ActionForward execute(ActionMapping mapping, ActionForm form, |
HttpServletRequest request, HttpServletResponse response) |
throws Exception |
{ |
MessageForm theForm = (MessageForm)form; |
String user = null; |
String message = theForm.getMessage(); |
if(request.getUserPrincipal() != null) |
user = request.getUserPrincipal().getName(); |
if(message != null && !message.equals("")) |
Logic.addMessage(user, message); |
response.sendRedirect("display.do"); |
return null; |
} |
} |
Property changes: |
Added: svn:keywords |
+LastChangedDate LastChangedRevision LastChangedBy HeadURL Id |
\ No newline at end of property |
/sun/SimpleChat/trunk/src/ak/simplechat/DisplayAction.java |
---|
0,0 → 1,22 |
package ak.simplechat; |
import java.util.List; |
import javax.servlet.http.HttpServletRequest; |
import javax.servlet.http.HttpServletResponse; |
import org.apache.struts.action.Action; |
import org.apache.struts.action.ActionMapping; |
import org.apache.struts.action.ActionForm; |
import org.apache.struts.action.ActionForward; |
public final class DisplayAction |
extends Action |
{ |
public ActionForward execute(ActionMapping mapping, ActionForm form, |
HttpServletRequest request, HttpServletResponse response) |
throws Exception |
{ |
request.setAttribute("messages", Logic.getMessages()); |
return mapping.findForward("success"); |
} |
} |
Property changes: |
Added: svn:keywords |
+LastChangedDate LastChangedRevision LastChangedBy HeadURL Id |
\ No newline at end of property |
/sun/SimpleChat/trunk/src/ak/simplechat/Message.java |
---|
0,0 → 1,32 |
package ak.simplechat; |
import java.util.Date; |
public class Message |
{ |
private String user; |
private String message; |
private Date stamp; |
public Message(String user, String message, Date stamp) |
{ |
this.user = user; |
this.message = message; |
this.stamp = stamp; |
} |
public String getUser() |
{ |
return user; |
} |
public String getMessage() |
{ |
return message; |
} |
public Date getStamp() |
{ |
return stamp; |
} |
} |
Property changes: |
Added: svn:keywords |
+LastChangedDate LastChangedRevision LastChangedBy HeadURL Id |
\ No newline at end of property |
/sun/SimpleChat/trunk/src/ak/simplechat/MessageForm.java |
---|
0,0 → 1,28 |
package ak.simplechat; |
import javax.servlet.http.HttpServletRequest; |
import org.apache.struts.action.ActionError; |
import org.apache.struts.action.ActionErrors; |
import org.apache.struts.action.ActionForm; |
import org.apache.struts.action.ActionMapping; |
public class MessageForm |
extends ActionForm |
{ |
protected String message; |
public String getMessage() |
{ |
return message; |
} |
public void setMessage(String message) |
{ |
this.message = message; |
} |
public void reset(ActionMapping mapping, HttpServletRequest request) |
{ |
this.message = null; |
} |
} |
Property changes: |
Added: svn:keywords |
+LastChangedDate LastChangedRevision LastChangedBy HeadURL Id |
\ No newline at end of property |
/sun/SimpleChat/trunk/src/ak/simplechat/EncodingFilter.java |
---|
0,0 → 1,36 |
package ak.simplechat; |
import java.io.IOException; |
import javax.servlet.Filter; |
import javax.servlet.FilterChain; |
import javax.servlet.FilterConfig; |
import javax.servlet.ServletException; |
import javax.servlet.ServletRequest; |
import javax.servlet.ServletResponse; |
public class EncodingFilter implements Filter |
{ |
public static final String ENCODING = "UTF-8"; |
private FilterConfig filterConfig; |
public void init(FilterConfig filterConfig) |
throws ServletException |
{ |
this.filterConfig = filterConfig; |
} |
public void doFilter(ServletRequest request, ServletResponse response, |
FilterChain chain) |
throws IOException, ServletException |
{ |
if(request.getCharacterEncoding() == null) |
request.setCharacterEncoding(ENCODING); |
chain.doFilter(request, response); |
} |
public void destroy() |
{ |
} |
} |
Property changes: |
Added: svn:keywords |
+LastChangedDate LastChangedRevision LastChangedBy HeadURL Id |
\ No newline at end of property |
/sun/SimpleChat/trunk/src/ak/simplechat/Logic.java |
---|
0,0 → 1,32 |
package ak.simplechat; |
import java.util.Date; |
import java.util.List; |
import java.util.ArrayList; |
public class Logic |
{ |
public static final int MESSAGES_LIMIT = 30; |
private static ArrayList messages = new ArrayList(); |
public static void addMessage(String user, String message) |
{ |
synchronized(messages) { |
messages.add(0, new Message(user, message, new Date())); |
while(messages.size() > MESSAGES_LIMIT) |
messages.remove(messages.size() - 1); |
} |
} |
public static List getMessages() |
{ |
List result; |
synchronized(messages) { |
result = (List)messages.clone(); |
} |
return result; |
} |
} |
Property changes: |
Added: svn:keywords |
+LastChangedDate LastChangedRevision LastChangedBy HeadURL Id |
\ No newline at end of property |