Search in sources :

Example 1 with FormField

use of org.xmpp.forms.FormField in project Openfire by igniterealtime.

the class GetGroupConversationTranscript method addStageInformation.

@Override
protected void addStageInformation(SessionData data, Element command) {
    DataForm form = new DataForm(DataForm.Type.form);
    form.setTitle("Requesting PDF of conversation transcript");
    form.addInstruction("Fill out this form to request the conversation transcript in PDF format.");
    FormField field = form.addField();
    field.setType(FormField.Type.hidden);
    field.setVariable("FORM_TYPE");
    field.addValue("http://jabber.org/protocol/admin");
    field = form.addField();
    field.setType(FormField.Type.jid_single);
    field.setLabel("JID of the user that participated in the chat");
    field.setVariable("participant");
    field.setRequired(true);
    field = form.addField();
    field.setType(FormField.Type.jid_single);
    field.setLabel("JID of the room");
    field.setVariable("room");
    field.setRequired(true);
    field = form.addField();
    field.setType(FormField.Type.text_single);
    field.setLabel("Time when the chat took place");
    field.setVariable("time");
    field.setRequired(true);
    field = form.addField();
    field.setType(FormField.Type.boolean_type);
    field.setLabel("Include PDF");
    field.setVariable("includePDF");
    field.setRequired(true);
    // Add the form to the command
    command.add(form.getElement());
}
Also used : DataForm(org.xmpp.forms.DataForm) FormField(org.xmpp.forms.FormField)

Example 2 with FormField

use of org.xmpp.forms.FormField 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 3 with FormField

use of org.xmpp.forms.FormField in project Openfire by igniterealtime.

the class MultiUserChatServiceImpl method getExtendedInfo.

@Override
public DataForm getExtendedInfo(String name, String node, JID senderJID) {
    if (name != null && node == null) {
        // Answer the extended info of a given room
        MUCRoom room = getChatRoom(name);
        if (room != null) {
            final DataForm dataForm = new DataForm(Type.result);
            final FormField fieldType = dataForm.addField();
            fieldType.setVariable("FORM_TYPE");
            fieldType.setType(FormField.Type.hidden);
            fieldType.addValue("http://jabber.org/protocol/muc#roominfo");
            final FormField fieldDescr = dataForm.addField();
            fieldDescr.setVariable("muc#roominfo_description");
            fieldDescr.setLabel(LocaleUtils.getLocalizedString("muc.extended.info.desc"));
            fieldDescr.addValue(room.getDescription());
            final FormField fieldSubj = dataForm.addField();
            fieldSubj.setVariable("muc#roominfo_subject");
            fieldSubj.setLabel(LocaleUtils.getLocalizedString("muc.extended.info.subject"));
            fieldSubj.addValue(room.getSubject());
            final FormField fieldOcc = dataForm.addField();
            fieldOcc.setVariable("muc#roominfo_occupants");
            fieldOcc.setLabel(LocaleUtils.getLocalizedString("muc.extended.info.occupants"));
            fieldOcc.addValue(Integer.toString(room.getOccupantsCount()));
            /*field = new XFormFieldImpl("muc#roominfo_lang");
                field.setLabel(LocaleUtils.getLocalizedString("muc.extended.info.language"));
                field.addValue(room.getLanguage());
                dataForm.addField(field);*/
            final FormField fieldDate = dataForm.addField();
            fieldDate.setVariable("x-muc#roominfo_creationdate");
            fieldDate.setLabel(LocaleUtils.getLocalizedString("muc.extended.info.creationdate"));
            fieldDate.addValue(XMPPDateTimeFormat.format(room.getCreationDate()));
            return dataForm;
        }
    }
    return null;
}
Also used : MUCRoom(org.jivesoftware.openfire.muc.MUCRoom) DataForm(org.xmpp.forms.DataForm) FormField(org.xmpp.forms.FormField)

Example 4 with FormField

use of org.xmpp.forms.FormField in project Openfire by igniterealtime.

the class IQChatSearchHandler method init.

private void init() {
    // Configure the search form that will be sent to the agents
    this.searchForm = new DataForm(DataForm.Type.form);
    this.searchForm.setTitle("Chat search");
    this.searchForm.addInstruction("Fill out this form to search for chats");
    // Add starting date
    FormField field = this.searchForm.addField();
    field.setType(FormField.Type.text_single);
    field.setLabel("Starting Date");
    field.setVariable("date/start");
    // Add ending date
    field = this.searchForm.addField();
    field.setType(FormField.Type.text_single);
    field.setLabel("Ending Date");
    field.setVariable("date/end");
    // Add workgroup JID
    field = this.searchForm.addField();
    field.setType(FormField.Type.jid_multi);
    field.setLabel("Workgroup");
    field.setVariable("workgroups");
    // Add agent JID
    field = this.searchForm.addField();
    field.setType(FormField.Type.jid_single);
    field.setLabel("Agent");
    field.setVariable("agent");
    // Add query string
    field = this.searchForm.addField();
    field.setType(FormField.Type.text_single);
    field.setLabel("Search Terms");
    field.setVariable("queryString");
    field.setRequired(true);
    // Configure the form that will hold the search results
    this.resultForm = new DataForm(DataForm.Type.result);
    this.resultForm.addReportedField("workgroup", null, FormField.Type.jid_single);
    this.resultForm.addReportedField("sessionID", null, FormField.Type.text_single);
    this.resultForm.addReportedField("startDate", null, FormField.Type.text_single);
    this.resultForm.addReportedField("agentJIDs", null, FormField.Type.jid_multi);
    this.resultForm.addReportedField("relevance", null, FormField.Type.text_single);
}
Also used : DataForm(org.xmpp.forms.DataForm) FormField(org.xmpp.forms.FormField)

Example 5 with FormField

use of org.xmpp.forms.FormField in project Openfire by igniterealtime.

the class IQOfflineMessagesHandler method getExtendedInfo.

@Override
public DataForm getExtendedInfo(String name, String node, JID senderJID) {
    // Mark that offline messages shouldn't be sent when the user becomes available
    stopOfflineFlooding(senderJID);
    final DataForm dataForm = new DataForm(DataForm.Type.result);
    final FormField field1 = dataForm.addField();
    field1.setVariable("FORM_TYPE");
    field1.setType(FormField.Type.hidden);
    field1.addValue(NAMESPACE);
    final FormField field2 = dataForm.addField();
    field2.setVariable("number_of_messages");
    field2.addValue(String.valueOf(messageStore.getMessages(senderJID.getNode(), false).size()));
    return dataForm;
}
Also used : DataForm(org.xmpp.forms.DataForm) FormField(org.xmpp.forms.FormField)

Aggregations

FormField (org.xmpp.forms.FormField)92 DataForm (org.xmpp.forms.DataForm)80 Element (org.dom4j.Element)21 JID (org.xmpp.packet.JID)13 IQ (org.xmpp.packet.IQ)7 HashSet (java.util.HashSet)6 ClientSession (org.jivesoftware.openfire.session.ClientSession)6 ArrayList (java.util.ArrayList)4 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)4 ParseException (java.text.ParseException)3 Date (java.util.Date)3 UnauthorizedException (org.jivesoftware.openfire.auth.UnauthorizedException)3 Group (org.jivesoftware.openfire.group.Group)3 Test (org.junit.Test)3 List (java.util.List)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 PacketException (org.jivesoftware.openfire.PacketException)2 GroupJID (org.jivesoftware.openfire.group.GroupJID)2 GroupNotFoundException (org.jivesoftware.openfire.group.GroupNotFoundException)2 MUCRoom (org.jivesoftware.openfire.muc.MUCRoom)2