use of org.xmpp.packet.JID in project Openfire by igniterealtime.
the class StatsAction method getNLatestConversations.
/**
* Retrieves the last n conversations from the system that were created after
* the given conversationID.
*
* @param count the count of conversations to return.
* @param mostRecentConversationID the last conversationID that has been retrieved.
* @return a List of Map objects.
*/
public List<Map<String, Long>> getNLatestConversations(int count, long mostRecentConversationID) {
// TODO Fix plugin name 2 lines below and missing classes
List<Map<String, Long>> cons = new ArrayList<Map<String, Long>>();
MonitoringPlugin plugin = (MonitoringPlugin) XMPPServer.getInstance().getPluginManager().getPlugin(MonitoringConstants.NAME);
ConversationManager conversationManager = (ConversationManager) plugin.getModule(ConversationManager.class);
Collection<Conversation> conversations = conversationManager.getConversations();
List<Conversation> lConversations = Arrays.asList(conversations.toArray(new Conversation[conversations.size()]));
Collections.sort(lConversations, conversationComparator);
int counter = 0;
for (Iterator<Conversation> i = lConversations.iterator(); i.hasNext() && counter < count; ) {
Conversation con = i.next();
if (mostRecentConversationID == con.getConversationID()) {
break;
} else {
Map mCon = new HashMap();
mCon.put("conversationid", con.getConversationID());
String[] users;
int usersIdx = 0;
if (con.getRoom() == null) {
users = new String[con.getParticipants().size()];
for (JID jid : con.getParticipants()) {
String identifier = jid.toBareJID();
try {
identifier = UserNameManager.getUserName(jid, jid.toBareJID());
} catch (UserNotFoundException e) {
// Ignore
}
users[usersIdx++] = StringUtils.abbreviate(identifier, 20);
}
} else {
users = new String[2];
users[0] = LocaleUtils.getLocalizedString("dashboard.group_conversation", MonitoringConstants.NAME);
try {
users[1] = "(<i>" + LocaleUtils.getLocalizedString("muc.room.summary.room") + ": <a href='../../muc-room-occupants.jsp?roomName=" + URLEncoder.encode(con.getRoom().getNode(), "UTF-8") + "'>" + con.getRoom().getNode() + "</a></i>)";
} catch (UnsupportedEncodingException e) {
Log.error(e.getMessage(), e);
}
}
mCon.put("users", users);
mCon.put("lastactivity", formatTimeLong(con.getLastActivity()));
mCon.put("messages", con.getMessageCount());
cons.add(0, mCon);
counter++;
}
}
return cons;
}
use of org.xmpp.packet.JID in project Openfire by igniterealtime.
the class MUCRoomController method createRoom.
/**
* Creates the room.
*
* @param mucRoomEntity
* the MUC room entity
* @param serviceName
* the service name
* @throws NotAllowedException
* the not allowed exception
* @throws ForbiddenException
* the forbidden exception
* @throws ConflictException
* the conflict exception
*/
private void createRoom(MUCRoomEntity mucRoomEntity, String serviceName) throws NotAllowedException, ForbiddenException, ConflictException {
// Set owner
JID owner = XMPPServer.getInstance().createJID("admin", null);
if (mucRoomEntity.getOwners() != null && mucRoomEntity.getOwners().size() > 0) {
owner = new JID(mucRoomEntity.getOwners().get(0));
} else {
List<String> owners = new ArrayList<String>();
owners.add(owner.toBareJID());
mucRoomEntity.setOwners(owners);
}
MUCRoom room = XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(serviceName).getChatRoom(mucRoomEntity.getRoomName().toLowerCase(), owner);
// Set values
room.setNaturalLanguageName(mucRoomEntity.getNaturalName());
room.setSubject(mucRoomEntity.getSubject());
room.setDescription(mucRoomEntity.getDescription());
room.setPassword(mucRoomEntity.getPassword());
room.setPersistent(mucRoomEntity.isPersistent());
room.setPublicRoom(mucRoomEntity.isPublicRoom());
room.setRegistrationEnabled(mucRoomEntity.isRegistrationEnabled());
room.setCanAnyoneDiscoverJID(mucRoomEntity.isCanAnyoneDiscoverJID());
room.setCanOccupantsChangeSubject(mucRoomEntity.isCanOccupantsChangeSubject());
room.setCanOccupantsInvite(mucRoomEntity.isCanOccupantsInvite());
room.setChangeNickname(mucRoomEntity.isCanChangeNickname());
room.setModificationDate(mucRoomEntity.getModificationDate());
room.setLogEnabled(mucRoomEntity.isLogEnabled());
room.setLoginRestrictedToNickname(mucRoomEntity.isLoginRestrictedToNickname());
room.setMaxUsers(mucRoomEntity.getMaxUsers());
room.setMembersOnly(mucRoomEntity.isMembersOnly());
room.setModerated(mucRoomEntity.isModerated());
// Set broadcast presence roles
if (mucRoomEntity.getBroadcastPresenceRoles() != null) {
room.setRolesToBroadcastPresence(mucRoomEntity.getBroadcastPresenceRoles());
} else {
room.setRolesToBroadcastPresence(new ArrayList<String>());
}
// Set all roles
setRoles(room, mucRoomEntity);
// Set creation date
if (mucRoomEntity.getCreationDate() != null) {
room.setCreationDate(mucRoomEntity.getCreationDate());
} else {
room.setCreationDate(new Date());
}
// Set modification date
if (mucRoomEntity.getModificationDate() != null) {
room.setModificationDate(mucRoomEntity.getModificationDate());
} else {
room.setModificationDate(new Date());
}
// Unlock the room, because the default configuration lock the room.
room.unlock(room.getRole());
// Save the room to the DB if the room should be persistant
if (room.isPersistent()) {
room.saveToDB();
}
}
use of org.xmpp.packet.JID in project Openfire by igniterealtime.
the class MUCRoomController method setRoles.
/**
* Reset roles.
*
* @param room
* the room
* @param mucRoomEntity
* the muc room entity
* @throws ForbiddenException
* the forbidden exception
* @throws NotAllowedException
* the not allowed exception
* @throws ConflictException
* the conflict exception
*/
private void setRoles(MUCRoom room, MUCRoomEntity mucRoomEntity) throws ForbiddenException, NotAllowedException, ConflictException {
List<JID> roles = new ArrayList<JID>();
Collection<JID> owners = new ArrayList<JID>();
Collection<JID> existingOwners = new ArrayList<JID>();
List<JID> mucRoomEntityOwners = MUCRoomUtils.convertStringsToJIDs(mucRoomEntity.getOwners());
owners.addAll(room.getOwners());
// Find same owners
for (JID jid : owners) {
if (mucRoomEntityOwners.contains(jid)) {
existingOwners.add(jid);
}
}
// Don't delete the same owners
owners.removeAll(existingOwners);
room.addOwners(MUCRoomUtils.convertStringsToJIDs(mucRoomEntity.getOwners()), room.getRole());
// Collect all roles to reset
roles.addAll(owners);
roles.addAll(room.getAdmins());
roles.addAll(room.getMembers());
roles.addAll(room.getOutcasts());
for (JID jid : roles) {
room.addNone(jid, room.getRole());
}
room.addOwners(MUCRoomUtils.convertStringsToJIDs(mucRoomEntity.getOwners()), room.getRole());
if (mucRoomEntity.getAdmins() != null) {
room.addAdmins(MUCRoomUtils.convertStringsToJIDs(mucRoomEntity.getAdmins()), room.getRole());
}
if (mucRoomEntity.getMembers() != null) {
for (String memberJid : mucRoomEntity.getMembers()) {
room.addMember(new JID(memberJid), null, room.getRole());
}
}
if (mucRoomEntity.getOutcasts() != null) {
for (String outcastJid : mucRoomEntity.getOutcasts()) {
room.addOutcast(new JID(outcastJid), null, room.getRole());
}
}
}
use of org.xmpp.packet.JID in project Openfire by igniterealtime.
the class TextPresenceProvider method sendUserNotFound.
@Override
public void sendUserNotFound(HttpServletRequest request, HttpServletResponse response) throws IOException {
response.setContentType("text/plain");
PrintWriter out = response.getWriter();
// Send a forbidden presence
Presence presence = new Presence();
presence.setError(PacketError.Condition.forbidden);
try {
presence.setFrom(new JID(request.getParameter("jid")));
} catch (Exception e) {
}
try {
presence.setTo(new JID(request.getParameter("req_jid")));
} catch (Exception e) {
}
out.println(presence.getStatus());
out.flush();
}
use of org.xmpp.packet.JID in project Openfire by igniterealtime.
the class XMLPresenceProvider method sendUserNotFound.
@Override
public void sendUserNotFound(HttpServletRequest request, HttpServletResponse response) throws IOException {
response.setContentType("text/xml");
PrintWriter out = response.getWriter();
// Send a forbidden presence
Presence presence = new Presence();
presence.setError(PacketError.Condition.forbidden);
try {
presence.setFrom(new JID(request.getParameter("jid")));
} catch (Exception e) {
}
try {
presence.setTo(new JID(request.getParameter("req_jid")));
} catch (Exception e) {
}
out.println(presence.toXML());
out.flush();
}
Aggregations