Search in sources :

Example 1 with Form

use of org.jivesoftware.smackx.Form in project ecf by eclipse.

the class NodeUtils method getFormFromPacket.

/**
 * Get a {@link ConfigureForm} from a packet.
 *
 * @param packet
 * @param elem
 * @return The configuration form
 */
public static ConfigureForm getFormFromPacket(Packet packet, PubSubElementType elem) {
    FormNode config = (FormNode) packet.getExtension(elem.getElementName(), elem.getNamespace().getXmlns());
    Form formReply = config.getForm();
    return new ConfigureForm(formReply);
}
Also used : FormNode(org.jivesoftware.smackx.pubsub.FormNode) Form(org.jivesoftware.smackx.Form) ConfigureForm(org.jivesoftware.smackx.pubsub.ConfigureForm) ConfigureForm(org.jivesoftware.smackx.pubsub.ConfigureForm)

Example 2 with Form

use of org.jivesoftware.smackx.Form in project ecf by eclipse.

the class XMPPChatRoomManager method createChatRoom.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ecf.presence.chatroom.IChatRoomManager#createChatRoom(java.lang.String,
	 *      java.util.Map)
	 */
public IChatRoomInfo createChatRoom(String roomname, Map properties) throws ChatRoomCreateException {
    if (roomname == null)
        throw new ChatRoomCreateException(roomname, Messages.XMPPChatRoomManager_EXCEPTION_ROOM_CANNOT_BE_NULL);
    try {
        final String nickname = ecfConnection.getXMPPConnection().getUser();
        final String server = ecfConnection.getXMPPConnection().getHost();
        final String domain = (properties == null) ? XMPPRoomID.DOMAIN_DEFAULT : (String) properties.get(PROP_XMPP_CONFERENCE);
        final String conference = XMPPRoomID.fixConferenceDomain(domain, server);
        final String roomID = roomname + XMPPRoomID.AT_SIGN + conference;
        // create proxy to the room
        final MultiUserChat muc = new MultiUserChat(ecfConnection.getXMPPConnection(), roomID);
        if (!checkRoom(conference, roomID)) {
            // otherwise create a new one
            muc.create(nickname);
            muc.sendConfigurationForm(new Form(Form.TYPE_SUBMIT));
            final String subject = (properties == null) ? null : (String) properties.get(PROP_XMPP_SUBJECT);
            if (subject != null)
                muc.changeSubject(subject);
        }
        String longname = muc.getRoom();
        if (longname == null || longname.length() <= 0) {
            longname = roomID;
        }
        final RoomInfo info = MultiUserChat.getRoomInfo(ecfConnection.getXMPPConnection(), roomID);
        if (info != null) {
            final XMPPRoomID xid = new XMPPRoomID(connectedID.getNamespace(), ecfConnection.getXMPPConnection(), roomID, longname);
            return new ECFRoomInfo(xid, info, connectedID);
        } else
            throw new XMPPException(NLS.bind(Messages.XMPPChatRoomManager_EXCEPTION_NO_ROOM_INFO, roomID));
    } catch (final XMPPException e) {
        throw new ChatRoomCreateException(roomname, e.getMessage(), e);
    } catch (final URISyntaxException e) {
        throw new ChatRoomCreateException(roomname, e.getMessage(), e);
    }
}
Also used : MultiUserChat(org.jivesoftware.smackx.muc.MultiUserChat) Form(org.jivesoftware.smackx.Form) IChatRoomInfo(org.eclipse.ecf.presence.chatroom.IChatRoomInfo) RoomInfo(org.jivesoftware.smackx.muc.RoomInfo) XMPPRoomID(org.eclipse.ecf.provider.xmpp.identity.XMPPRoomID) URISyntaxException(java.net.URISyntaxException) XMPPException(org.jivesoftware.smack.XMPPException) ChatRoomCreateException(org.eclipse.ecf.presence.chatroom.ChatRoomCreateException)

Example 3 with Form

use of org.jivesoftware.smackx.Form in project ecf by eclipse.

the class XMPPUserSearchManager method search.

/**
 * Specific implementation for XMPP
 *
 * @see IUserSearchManager#search(ICriteria).
 */
public ISearch search(ICriteria criteria) throws UserSearchException {
    ResultList resultList = new ResultList();
    try {
        // initialize the form by chance it is null
        if (form == null)
            form = manager.getSearchForm(ecfConnection.getXMPPConnection(), SERVICE_SEARCH + ecfConnection.getXMPPConnection().getServiceName());
        /*
			 * For XMPP criterion is considered. The XMPP server will deal with
			 * the search.
			 */
        List criterions = criteria.getCriterions();
        // add the fields for the search dynamically
        // consider just the fields used on the search
        // fields checked by user
        String[] fields = getUserPropertiesFields();
        for (int i = 0; i < fields.length; i++) {
            Iterator criterionsIterator = criterions.iterator();
            // the partial result is added to the result list
            while (criterionsIterator.hasNext()) {
                ICriterion criterion = (ICriterion) criterionsIterator.next();
                if (criterion.equals(fields[i])) {
                    Form answerForm = form.createAnswerForm();
                    answerForm.setAnswer(fields[i], true);
                    answerForm.setAnswer(SEARCH_ACTION, criterion.toExpression());
                    ReportedData data = manager.sendSearchForm(ecfConnection.getXMPPConnection(), answerForm, SERVICE_SEARCH + ecfConnection.getXMPPConnection().getServiceName());
                    // create a result list from ReportedData
                    IResultList partialResultList = createResultList(data);
                    resultList.addAll(partialResultList.getResults());
                }
            }
        }
        return new XMPPSearch(resultList);
    } catch (final XMPPException e) {
        String message = null;
        if (e.getXMPPError() != null && e.getXMPPError().getCode() == 404) {
            message = Messages.XMPPContainer_UNRECOGONIZED_SEARCH_SERVICE;
        } else {
            message = e.getLocalizedMessage();
        }
        throw new UserSearchException(message, e, criteria);
    } catch (ECFException e) {
        throw new UserSearchException(e, criteria);
    }
}
Also used : IResultList(org.eclipse.ecf.presence.search.IResultList) ResultList(org.eclipse.ecf.presence.search.ResultList) Form(org.jivesoftware.smackx.Form) IResultList(org.eclipse.ecf.presence.search.IResultList) ECFException(org.eclipse.ecf.core.util.ECFException) Iterator(java.util.Iterator) IResultList(org.eclipse.ecf.presence.search.IResultList) List(java.util.List) ResultList(org.eclipse.ecf.presence.search.ResultList) XMPPException(org.jivesoftware.smack.XMPPException) ICriterion(org.eclipse.ecf.presence.search.ICriterion) UserSearchException(org.eclipse.ecf.presence.search.UserSearchException) ReportedData(org.jivesoftware.smackx.ReportedData)

Example 4 with Form

use of org.jivesoftware.smackx.Form in project Smack by igniterealtime.

the class MultiUserChatCreationTest method testCreateReservedRoom.

/**
 * Tests creating a new "Reserved Room".
 */
public void testCreateReservedRoom() {
    MultiUserChat muc = new MultiUserChat(getConnection(0), room);
    try {
        // Create the room
        muc.create("testbot1");
        // Get the the room's configuration form
        Form form = muc.getConfigurationForm();
        assertNotNull("No room configuration form", form);
        // Create a new form to submit based on the original form
        Form submitForm = form.createAnswerForm();
        // Add default answers to the form to submit
        for (Iterator<FormField> fields = form.getFields(); fields.hasNext(); ) {
            FormField field = fields.next();
            if (!FormField.TYPE_HIDDEN.equals(field.getType()) && field.getVariable() != null) {
                // Sets the default value as the answer
                submitForm.setDefaultAnswer(field.getVariable());
            }
        }
        List<String> owners = new ArrayList<String>();
        owners.add(getBareJID(0));
        submitForm.setAnswer("muc#roomconfig_roomowners", owners);
        // Update the new room's configuration
        muc.sendConfigurationForm(submitForm);
        // Destroy the new room
        muc.destroy("The room has almost no activity...", null);
    } catch (XMPPException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : Form(org.jivesoftware.smackx.Form) ArrayList(java.util.ArrayList) XMPPException(org.jivesoftware.smack.XMPPException) FormField(org.jivesoftware.smackx.FormField)

Example 5 with Form

use of org.jivesoftware.smackx.Form in project Smack by igniterealtime.

the class MultiUserChatTest method makeRoomModerated.

private void makeRoomModerated() throws XMPPException {
    // User1 (which is the room owner) converts the instant room into a moderated room
    Form form = muc.getConfigurationForm();
    Form answerForm = form.createAnswerForm();
    answerForm.setAnswer("muc#roomconfig_moderatedroom", true);
    answerForm.setAnswer("muc#roomconfig_whois", Arrays.asList("moderators"));
    // Keep the room owner
    try {
        List<String> owners = new ArrayList<String>();
        owners.add(getBareJID(0));
        answerForm.setAnswer("muc#roomconfig_roomowners", owners);
    } catch (IllegalArgumentException e) {
    // Do nothing
    }
    muc.sendConfigurationForm(answerForm);
}
Also used : Form(org.jivesoftware.smackx.Form) ArrayList(java.util.ArrayList)

Aggregations

Form (org.jivesoftware.smackx.Form)11 XMPPException (org.jivesoftware.smack.XMPPException)7 FormField (org.jivesoftware.smackx.FormField)4 ArrayList (java.util.ArrayList)2 XMPPError (org.jivesoftware.smack.packet.XMPPError)2 URISyntaxException (java.net.URISyntaxException)1 Iterator (java.util.Iterator)1 List (java.util.List)1 ECFException (org.eclipse.ecf.core.util.ECFException)1 ChatRoomCreateException (org.eclipse.ecf.presence.chatroom.ChatRoomCreateException)1 IChatRoomInfo (org.eclipse.ecf.presence.chatroom.IChatRoomInfo)1 ICriterion (org.eclipse.ecf.presence.search.ICriterion)1 IResultList (org.eclipse.ecf.presence.search.IResultList)1 ResultList (org.eclipse.ecf.presence.search.ResultList)1 UserSearchException (org.eclipse.ecf.presence.search.UserSearchException)1 XMPPRoomID (org.eclipse.ecf.provider.xmpp.identity.XMPPRoomID)1 ReportedData (org.jivesoftware.smackx.ReportedData)1 Action (org.jivesoftware.smackx.commands.AdHocCommand.Action)1 MultiUserChat (org.jivesoftware.smackx.muc.MultiUserChat)1 RoomInfo (org.jivesoftware.smackx.muc.RoomInfo)1