use of org.dom4j.Element in project Openfire by igniterealtime.
the class GetGroupConversationTranscript method execute.
@Override
public void execute(SessionData data, Element command) {
Element note = command.addElement("note");
// Get handle on the Monitoring plugin
MonitoringPlugin plugin = (MonitoringPlugin) XMPPServer.getInstance().getPluginManager().getPlugin(MonitoringConstants.NAME);
ConversationManager conversationManager = (ConversationManager) plugin.getModule(ConversationManager.class);
if (!conversationManager.isArchivingEnabled()) {
note.addAttribute("type", "error");
note.setText("Message archiving is not enabled.");
DataForm form = new DataForm(DataForm.Type.result);
FormField field = form.addField();
field.setType(FormField.Type.hidden);
field.setVariable("FORM_TYPE");
field.addValue("http://jabber.org/protocol/admin");
field = form.addField();
field.setLabel("Conversation Found?");
field.setVariable("found");
field.addValue(false);
// Add form to reply
command.add(form.getElement());
return;
}
try {
JID participant = new JID(data.getData().get("participant").get(0));
JID room = new JID(data.getData().get("room").get(0));
Date time = DataForm.parseDate(data.getData().get("time").get(0));
boolean includePDF = DataForm.parseBoolean(data.getData().get("includePDF").get(0));
// Get archive searcher module
ArchiveSearcher archiveSearcher = (ArchiveSearcher) plugin.getModule(ArchiveSearcher.class);
ArchiveSearch search = new ArchiveSearch();
search.setParticipants(participant);
search.setIncludeTimestamp(time);
search.setRoom(room);
Collection<Conversation> conversations = archiveSearcher.search(search);
DataForm form = new DataForm(DataForm.Type.result);
FormField field = form.addField();
field.setType(FormField.Type.hidden);
field.setVariable("FORM_TYPE");
field.addValue("http://jabber.org/protocol/admin");
field = form.addField();
field.setLabel("Conversation Found?");
field.setVariable("found");
field.addValue(!conversations.isEmpty());
if (includePDF) {
ByteArrayOutputStream stream = null;
if (!conversations.isEmpty()) {
stream = new ConversationUtils().getConversationPDF(conversations.iterator().next());
}
if (stream != null) {
field = form.addField();
field.setLabel("PDF");
field.setVariable("pdf");
field.addValue(StringUtils.encodeBase64(stream.toByteArray()));
}
}
// Add form to reply
command.add(form.getElement());
} catch (Exception e) {
Log.error("Error occurred while running the command", e);
note.addAttribute("type", "error");
note.setText("Error while processing the command.");
}
}
use of org.dom4j.Element in project Openfire by igniterealtime.
the class IQListHandler method handleIQ.
public IQ handleIQ(IQ packet) throws UnauthorizedException {
IQ reply = IQ.createResultIQ(packet);
ListRequest listRequest = new ListRequest(packet.getChildElement());
JID from = packet.getFrom();
Element listElement = reply.setChildElement("list", NAMESPACE);
Collection<Conversation> conversations = list(from, listRequest);
XmppResultSet resultSet = listRequest.getResultSet();
for (Conversation conversation : conversations) {
addChatElement(listElement, conversation);
}
if (resultSet != null) {
listElement.add(resultSet.createResultElement());
}
return reply;
}
use of org.dom4j.Element in project Openfire by igniterealtime.
the class TransportBuddy method addVCardPhoto.
/**
* Adds the PHOTO vcard element (representing an avatar) to an existing vcard.
*
* This will add the avatar to a vcard if there's one to add. Otherwise will not add anything.
* If added, a properly formatted PHOTO element with base64 encoded data in it will be added.
*
* param vcard vcard to add PHOTO element to
*/
public void addVCardPhoto(Element vcard) {
if (!avatarSet) {
Log.debug("TransportBuddy: I've got nothing! (no avatar set)");
return;
}
Element photo = vcard.addElement("PHOTO");
if (avatar != null) {
try {
photo.addElement("TYPE").addCDATA(avatar.getMimeType());
photo.addElement("BINVAL").addCDATA(avatar.getImageData());
} catch (NotFoundException e) {
// No problem, leave it empty then.
}
}
}
use of org.dom4j.Element in project Openfire by igniterealtime.
the class TransportBuddy method setAvatar.
/**
* Sets the current avatar for this contact.
*
* @param avatar Avatar instance to associate with this contact.
*/
public void setAvatar(Avatar avatar) {
boolean triggerUpdate = false;
if ((avatar != null && this.avatar == null) || (avatar == null && this.avatar != null) || (avatar != null && !this.avatar.getXmppHash().equals(avatar.getXmppHash()))) {
triggerUpdate = true;
}
this.avatar = avatar;
this.avatarSet = true;
if (triggerUpdate) {
Presence p = new Presence();
p.setTo(getManager().getSession().getJID());
p.setFrom(jid);
getManager().getSession().getTransport().setUpPresencePacket(p, presence);
if (!verboseStatus.equals("")) {
p.setStatus(verboseStatus);
}
Element vcard = p.addChildElement("x", NameSpace.VCARD_TEMP_X_UPDATE);
if (avatar != null) {
vcard.addElement("photo").addCDATA(avatar.getXmppHash());
vcard.addElement("hash").addCDATA(avatar.getXmppHash());
}
getManager().sendPacket(p);
}
}
use of org.dom4j.Element in project Openfire by igniterealtime.
the class TransportBuddy method setVerboseStatus.
/**
* Sets the current verbose status.
*
* @param newstatus New verbose status.
*/
public void setVerboseStatus(String newstatus) {
if (newstatus == null) {
newstatus = "";
}
if (!verboseStatus.equals(newstatus)) {
Presence p = new Presence();
p.setTo(getManager().getSession().getJID());
p.setFrom(jid);
getManager().getSession().getTransport().setUpPresencePacket(p, presence);
if (!newstatus.equals("")) {
p.setStatus(newstatus);
}
if (avatarSet && avatar != null) {
Element vcard = p.addChildElement("x", NameSpace.VCARD_TEMP_X_UPDATE);
vcard.addElement("photo").addCDATA(avatar.getXmppHash());
vcard.addElement("hash").addCDATA(avatar.getXmppHash());
}
getManager().sendPacket(p);
}
verboseStatus = newstatus;
lastActivityTimestamp = new Date().getTime();
lastActivityEvent = verboseStatus;
}
Aggregations