org.jxmpp.jid.util.JidUtil Java Examples

The following examples show how to use org.jxmpp.jid.util.JidUtil. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MucConfigFormManager.java    From Smack with Apache License 2.0 6 votes vote down vote up
/**
 * Create a new MUC config form manager.
 * <p>
 * Note that the answerForm needs to be filled out with the defaults.
 * </p>
 *
 * @param multiUserChat the MUC for this configuration form.
 * @throws InterruptedException if the calling thread was interrupted.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws XMPPErrorException if there was an XMPP error returned.
 * @throws NoResponseException if there was no response from the remote entity.
 */
MucConfigFormManager(MultiUserChat multiUserChat) throws NoResponseException,
                XMPPErrorException, NotConnectedException, InterruptedException {
    this.multiUserChat = multiUserChat;

    // Set the answer form
    Form configForm = multiUserChat.getConfigurationForm();
    this.answerForm = configForm.getFillableForm();

    // Set the local variables according to the fields found in the answer form
    FormField roomOwnersFormField = answerForm.getDataForm().getField(MUC_ROOMCONFIG_ROOMOWNERS);
    if (roomOwnersFormField != null) {
        // Set 'owners' to the currently configured owners
        List<? extends CharSequence> ownerStrings = roomOwnersFormField.getValues();
        owners = new ArrayList<>(ownerStrings.size());
        JidUtil.jidsFrom(ownerStrings, owners, null);
    }
    else {
        // roomowners not supported, this should barely be the case
        owners = null;
    }
}
 
Example #2
Source File: JID.java    From desktopclient-java with GNU General Public License v3.0 5 votes vote down vote up
private JID(String local, String domain, String resource) {
    mLocal = local;
    mDomain = domain;
    mResource = resource;

    mValid = !mLocal.isEmpty() && !mDomain.isEmpty()
            // NOTE: domain check could be stronger - compliant with RFC 6122, but
            // server does not accept most special characters
            // NOTE: resource not checked
            && JidUtil.isTypicalValidEntityBareJid(
                    XmppStringUtils.completeJidFrom(mLocal, mDomain));
}
 
Example #3
Source File: FillableForm.java    From Smack with Apache License 2.0 5 votes vote down vote up
public void setAnswer(String fieldName, Collection<? extends CharSequence> answers) {
    FormField blankField = getFieldOrThrow(fieldName);
    FormField.Type type = blankField.getType();

    FormField filledFormField;
    switch (type) {
    case list_multi:
    case text_multi:
        filledFormField = createMultiKindFieldbuilder(fieldName, type)
            .addValues(answers)
            .build();
        break;
    case jid_multi:
        List<Jid> jids = new ArrayList<>(answers.size());
        List<XmppStringprepException> exceptions = new ArrayList<>();
        JidUtil.jidsFrom(answers, jids, exceptions);
        if (!exceptions.isEmpty()) {
            // TODO: Report all exceptions here.
            throw new IllegalArgumentException(exceptions.get(0));
        }
        filledFormField = FormField.jidMultiBuilder(fieldName)
                        .addValues(jids)
                        .build();
        break;
    default:
        throw new IllegalArgumentException("");
    }
    write(filledFormField);
}
 
Example #4
Source File: FileTransferSettings.java    From Spark with Apache License 2.0 5 votes vote down vote up
/**
 * Loads the properties from the filesystem.
 */
public void load() {
    Properties props = new Properties();

    if (BACKING_STORE.exists()) {
        try {
            props.load(new FileInputStream(BACKING_STORE));

            String types = props.getProperty("extensions");
            if (types != null) {
                this.extensions = convertSettingsStringToList(types);
            }

            String users = props.getProperty("jids");
            if (users != null) {
                List<String> jidStrings = convertSettingsStringToList(users);
                Set<EntityBareJid> jidSet = JidUtil.entityBareJidSetFrom(jidStrings);
                this.JIDs = new ArrayList<>(jidSet);
            }

            String ignore = props.getProperty("checkFileSize");
            if (ignore != null) {
                this.checkSize = Boolean.valueOf(ignore);
            }

            String maxSize = props.getProperty("maxSize");
            if (maxSize != null) {
                this.kb = Integer.parseInt(maxSize);
            }

            this.cannedRejectionMessage = props.getProperty("cannedResponse");

        } catch (IOException ioe) {
            System.out.println("Error Loading properties from Filesystem"+ioe);
            //TODO handle error better.
        }
    }
}
 
Example #5
Source File: TransferSettingsPanel.java    From Spark with Apache License 2.0 4 votes vote down vote up
public List<EntityBareJid> getBlockedPeople() {
    List<String> jidStrings = FileTransferSettings.convertSettingsStringToList(txtBlockedPeople.getText());
    Set<EntityBareJid> jidSet = JidUtil.entityBareJidSetFrom(jidStrings);
    List<EntityBareJid> jids = new ArrayList<>(jidSet);
    return jids;
}
 
Example #6
Source File: UserInvitationPane.java    From Spark with Apache License 2.0 4 votes vote down vote up
/**
 * Removes oneself as an owner of the room.
 *
 * @param muc the <code>MultiUserChat</code> of the chat room.
 */
private void removeOwner(MultiUserChat muc) {
    if (muc.isJoined()) {
        // Try and remove myself as an owner if I am one.
        Collection<Affiliate> owners = null;
        try {
            owners = muc.getOwners();
        }
        catch (XMPPException | SmackException | InterruptedException e1) {
            return;
        }

        if (owners == null) {
            return;
        }

        Iterator<Affiliate> iter = owners.iterator();

        List<Jid> list = new ArrayList<>();
        while (iter.hasNext()) {
            Affiliate affilitate = iter.next();
            Jid jid = affilitate.getJid();
            if (!jid.equals(SparkManager.getSessionManager().getBareUserAddress())) {
                list.add(jid);
            }
        }
        if (list.size() > 0) {
            try {
                Form form = muc.getConfigurationForm().createAnswerForm();
                List<String> jidStrings = JidUtil.toStringList(list);
                form.setAnswer("muc#roomconfig_roomowners", jidStrings);

                // new DataFormDialog(groupChat, form);
                muc.sendConfigurationForm(form);
            }
            catch (XMPPException | SmackException | InterruptedException e) {
                Log.error(e);
            }
        }
    }
}
 
Example #7
Source File: InvitationPane.java    From Spark with Apache License 2.0 4 votes vote down vote up
/**
 * Removes oneself as an owner of the room.
 *
 * @param muc the <code>MultiUserChat</code> of the chat room.
 */
private void removeOwner(MultiUserChat muc) {
    if (muc.isJoined()) {
        // Try and remove myself as an owner if I am one.
        Collection owners = null;
        try {
            owners = muc.getOwners();
        }
        catch (XMPPException | SmackException | InterruptedException e1) {
            return;
        }

        if (owners == null) {
            return;
        }

        Iterator iter = owners.iterator();

        List<Jid> list = new ArrayList<>();
        while (iter.hasNext()) {
            Affiliate affilitate = (Affiliate)iter.next();
            Jid jid = affilitate.getJid();
            if (!jid.equals(SparkManager.getSessionManager().getBareUserAddress())) {
                list.add(jid);
            }
        }
        if (list.size() > 0) {
            try {
                Form form = muc.getConfigurationForm().createAnswerForm();
                List<String> jidStrings = new ArrayList<>(list.size());
                JidUtil.toStrings(list, jidStrings);
                form.setAnswer("muc#roomconfig_roomowners", jidStrings);

                // new DataFormDialog(groupChat, form);
                muc.sendConfigurationForm(form);
            }
            catch (XMPPException | SmackException | InterruptedException e) {
                Log.error(e);
            }
        }
    }
}
 
Example #8
Source File: MucConfigFormManager.java    From Smack with Apache License 2.0 3 votes vote down vote up
/**
 * Submit the configuration as {@link FilledForm} to the room.
 *
 * @throws NoResponseException if there was no response from the room.
 * @throws XMPPErrorException if there was an XMPP error returned.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
public void submitConfigurationForm() throws NoResponseException, XMPPErrorException, NotConnectedException,
                InterruptedException {
    if (owners != null) {
        answerForm.setAnswer(MUC_ROOMCONFIG_ROOMOWNERS, JidUtil.toStringList(owners));
    }
    multiUserChat.sendConfigurationForm(answerForm);
}