Java Code Examples for org.jxmpp.jid.impl.JidCreate#entityFullFrom()

The following examples show how to use org.jxmpp.jid.impl.JidCreate#entityFullFrom() . 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: Jid.java    From Pix-Art-Messenger with GNU General Public License v3.0 6 votes vote down vote up
static Jid of(CharSequence local, CharSequence domain, CharSequence resource) {
    if (local == null) {
        if (resource == null) {
            return ofDomain(domain);
        } else {
            return ofDomainAndResource(domain, resource);
        }
    }
    if (resource == null) {
        return ofLocalAndDomain(local, domain);
    }
    try {
        return new WrappedJid(JidCreate.entityFullFrom(
                Localpart.fromUnescaped(local.toString()),
                Domainpart.from(domain.toString()),
                Resourcepart.from(resource.toString())
        ));
    } catch (XmppStringprepException e) {
        throw new IllegalArgumentException(e);
    }
}
 
Example 2
Source File: Jid.java    From Pix-Art-Messenger with GNU General Public License v3.0 6 votes vote down vote up
static Jid ofEscaped(CharSequence local, CharSequence domain, CharSequence resource) {
    try {
        if (resource == null) {
            return new WrappedJid(
                    JidCreate.bareFrom(
                            Localpart.from(local.toString()),
                            Domainpart.from(domain.toString())
                    )
            );
        }
        return new WrappedJid(JidCreate.entityFullFrom(
                Localpart.from(local.toString()),
                Domainpart.from(domain.toString()),
                Resourcepart.from(resource.toString())
        ));
    } catch (XmppStringprepException e) {
        throw new IllegalArgumentException(e);
    }
}
 
Example 3
Source File: Jid.java    From Conversations with GNU General Public License v3.0 6 votes vote down vote up
static Jid of(CharSequence local, CharSequence domain, CharSequence resource) {
    if (local == null) {
        if (resource == null) {
            return ofDomain(domain);
        } else {
            return ofDomainAndResource(domain, resource);
        }
    }
    if (resource == null) {
        return ofLocalAndDomain(local, domain);
    }
    try {
        return new WrappedJid(JidCreate.entityFullFrom(
                Localpart.fromUnescaped(local.toString()),
                Domainpart.from(domain.toString()),
                Resourcepart.from(resource.toString())
        ));
    } catch (XmppStringprepException e) {
        throw new IllegalArgumentException(e);
    }
}
 
Example 4
Source File: Jid.java    From Conversations with GNU General Public License v3.0 6 votes vote down vote up
static Jid ofEscaped(CharSequence local, CharSequence domain, CharSequence resource) {
    try {
        if (resource == null) {
            return new WrappedJid(
                    JidCreate.bareFrom(
                            Localpart.from(local.toString()),
                            Domainpart.from(domain.toString())
                    )
            );
        }
        return new WrappedJid(JidCreate.entityFullFrom(
                Localpart.from(local.toString()),
                Domainpart.from(domain.toString()),
                Resourcepart.from(resource.toString())
        ));
    } catch (XmppStringprepException e) {
        throw new IllegalArgumentException(e);
    }
}
 
Example 5
Source File: BindIQProvider.java    From Smack with Apache License 2.0 5 votes vote down vote up
@Override
public Bind parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException {
    String name;
    Bind bind = null;
    outerloop: while (true) {
        XmlPullParser.Event eventType = parser.next();
        switch (eventType) {
        case START_ELEMENT:
            name = parser.getName();
            switch (name) {
            case "resource":
                String resourceString = parser.nextText();
                bind = Bind.newSet(Resourcepart.from(resourceString));
                break;
            case "jid":
                EntityFullJid fullJid = JidCreate.entityFullFrom(parser.nextText());
                bind = Bind.newResult(fullJid);
                break;
            }
            break;
        case END_ELEMENT:
            if (parser.getDepth() == initialDepth) {
                break outerloop;
            }
            break;
        default:
            // Catch all for incomplete switch (MissingCasesInEnumSwitch) statement.
            break;
        }
    }
    return bind;
}
 
Example 6
Source File: ParserUtils.java    From Smack with Apache License 2.0 5 votes vote down vote up
public static EntityFullJid getFullJidAttribute(XmlPullParser parser, String name) throws XmppStringprepException {
    final String jidString = parser.getAttributeValue("", name);
    if (jidString == null) {
        return null;
    }
    return JidCreate.entityFullFrom(jidString);
}
 
Example 7
Source File: DummyConnection.java    From Smack with Apache License 2.0 5 votes vote down vote up
private EntityFullJid getUserJid() {
    try {
        return JidCreate.entityFullFrom(config.getUsername()
                        + "@"
                        + config.getXMPPServiceDomain()
                        + "/"
                        + (config.getResource() != null ? config.getResource() : "Test"));
    }
    catch (XmppStringprepException e) {
        throw new IllegalStateException(e);
    }
}
 
Example 8
Source File: MultiUserChat.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * Changes the occupant's nickname to a new nickname within the room. Each room occupant
 * will receive two presence packets. One of type "unavailable" for the old nickname and one
 * indicating availability for the new nickname. The unavailable presence will contain the new
 * nickname and an appropriate status code (namely 303) as extended presence information. The
 * status code 303 indicates that the occupant is changing his/her nickname.
 *
 * @param nickname the new nickname within the room.
 * @throws XMPPErrorException if the new nickname is already in use by another occupant.
 * @throws NoResponseException if there was no response from the server.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 * @throws MucNotJoinedException if not joined to the Multi-User Chat.
 */
public synchronized void changeNickname(Resourcepart nickname) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException, MucNotJoinedException  {
    Objects.requireNonNull(nickname, "Nickname must not be null or blank.");
    // Check that we already have joined the room before attempting to change the
    // nickname.
    if (!isJoined()) {
        throw new MucNotJoinedException(this);
    }
    final EntityFullJid jid = JidCreate.entityFullFrom(room, nickname);
    // We change the nickname by sending a presence packet where the "to"
    // field is in the form "roomName@service/nickname"
    // We don't have to signal the MUC support again
    Presence joinPresence = connection.getStanzaFactory().buildPresenceStanza()
            .to(jid)
            .ofType(Presence.Type.available)
            .build();

    // Wait for a presence packet back from the server.
    StanzaFilter responseFilter =
        new AndFilter(
            FromMatchesFilter.createFull(jid),
            new StanzaTypeFilter(Presence.class));
    StanzaCollector response = connection.createStanzaCollectorAndSend(responseFilter, joinPresence);
    // Wait up to a certain number of seconds for a reply. If there is a negative reply, an
    // exception will be thrown
    response.nextResultOrThrow();

    // TODO: Shouldn't this handle nickname rewriting by the MUC service?
    setNickname(nickname);
}
 
Example 9
Source File: UserManager.java    From Spark with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the occupant of the room identified by their nickname.
 *
 * @param groupChatRoom the GroupChatRoom.
 * @param nickname      the users nickname.
 * @return the Occupant found.
 */
public Occupant getOccupant(GroupChatRoom groupChatRoom, Resourcepart nickname) {
    EntityFullJid userJID = JidCreate.entityFullFrom(groupChatRoom.getRoomname(), nickname);
    Occupant occ = null;
    try {
        occ = groupChatRoom.getMultiUserChat().getOccupant(userJID);
    }
    catch (Exception e) {
        Log.error(e);
    }
    return occ;
}
 
Example 10
Source File: MultiUserChat.java    From Smack with Apache License 2.0 4 votes vote down vote up
private void setNickname(Resourcepart nickname) {
    this.myRoomJid = JidCreate.entityFullFrom(room, nickname);
}
 
Example 11
Source File: MucEnterConfiguration.java    From Smack with Apache License 2.0 4 votes vote down vote up
Presence getJoinPresence(MultiUserChat multiUserChat) {
    final EntityFullJid jid = JidCreate.entityFullFrom(multiUserChat.getRoom(), nickname);
    joinPresence.setTo(jid);
    return joinPresence;
}