sendalluserlist.java

来自「flex实现的前台」· Java 代码 · 共 43 行

JAVA
43
字号
/**
 * 
 */
package cn.humanmonth.chat.server.protocol.response;

import java.util.List;

import cn.humanmonth.chat.server.domain.User;
import cn.humanmonth.chat.server.protocol.Protocol;
import cn.humanmonth.framework.view.XmlUtil;

/**
 * @author Piterlin
 * 
 */
public class SendALlUserList {
	public static String action = "getAllUserListBack";
	public static String userXmlTag="UserList";

	private String getAllUsernameXml(List users) {
		StringBuffer result = new StringBuffer();
		result.append(XmlUtil.XML_HEADER);
		result.append(XmlUtil.getStartTag(action));
		for (int i = 0; i < users.size(); i++) {
			User tempUser = (User) users.get(i);
			result.append(XmlUtil.getStartTag(userXmlTag)+tempUser.getUserNameDetail()+XmlUtil.getEndTag(userXmlTag));
		}
		return result.append(XmlUtil.getEndTag(action)).toString();
	}

	public void deal(Protocol protocol) {
		for (int i = 0; i < protocol.getUsers().size(); i++) {
			try {
				User currentUser = (User) protocol.getUsers().get(i);
				protocol.sendStringToSingleClient(currentUser, this.getAllUsernameXml(protocol.getUsers()).replaceAll(
						currentUser.getUserNameDetailWithExcapeRegExp(), "你"));
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?