Search in sources :

Example 21 with Element

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.");
    }
}
Also used : JID(org.xmpp.packet.JID) Element(org.dom4j.Element) ConversationManager(org.jivesoftware.openfire.archive.ConversationManager) Conversation(org.jivesoftware.openfire.archive.Conversation) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Date(java.util.Date) ConversationUtils(org.jivesoftware.openfire.archive.ConversationUtils) MonitoringPlugin(org.jivesoftware.openfire.plugin.MonitoringPlugin) ArchiveSearch(org.jivesoftware.openfire.archive.ArchiveSearch) DataForm(org.xmpp.forms.DataForm) FormField(org.xmpp.forms.FormField) ArchiveSearcher(org.jivesoftware.openfire.archive.ArchiveSearcher)

Example 22 with Element

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;
}
Also used : JID(org.xmpp.packet.JID) Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) Conversation(com.reucon.openfire.plugin.archive.model.Conversation) XmppResultSet(com.reucon.openfire.plugin.archive.xep0059.XmppResultSet)

Example 23 with Element

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.
        }
    }
}
Also used : Element(org.dom4j.Element) NotFoundException(org.jivesoftware.util.NotFoundException)

Example 24 with Element

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);
    }
}
Also used : Element(org.dom4j.Element) Presence(org.xmpp.packet.Presence)

Example 25 with Element

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;
}
Also used : Element(org.dom4j.Element) Presence(org.xmpp.packet.Presence) Date(java.util.Date)

Aggregations

Element (org.dom4j.Element)2207 Document (org.dom4j.Document)500 ArrayList (java.util.ArrayList)294 List (java.util.List)249 SAXReader (org.dom4j.io.SAXReader)196 Iterator (java.util.Iterator)163 IQ (org.xmpp.packet.IQ)142 HashMap (java.util.HashMap)135 IOException (java.io.IOException)114 File (java.io.File)101 Attribute (org.dom4j.Attribute)97 StringReader (java.io.StringReader)90 DefaultElement (org.dom4j.tree.DefaultElement)87 JID (org.xmpp.packet.JID)87 Test (org.junit.jupiter.api.Test)78 DocumentException (org.dom4j.DocumentException)74 QName (org.dom4j.QName)68 AnnotatedElement (java.lang.reflect.AnnotatedElement)64 Node (org.dom4j.Node)64 Test (org.junit.Test)64