📄 sendalluserlist.java
字号:
/**
*
*/
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -