org.jxmpp.jid.parts.Localpart Java Examples

The following examples show how to use org.jxmpp.jid.parts.Localpart. 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: TicTacToePlugin.java    From Spark with Apache License 2.0 6 votes vote down vote up
/**
    * Creates The TicTacToe Window and starts the Game
    * @param gop
    * @param opponentJID
    */
   private void createTTTWindow(GameOfferPacket gop, EntityFullJid opponentJID) {

Localpart name = opponentJID.getLocalpart();

// tictactoe versus ${name}
JFrame f = new JFrame(TTTRes.getString("ttt.window.title", TTTRes.getString("ttt.game.name"),name.toString() ));

f.setIconImage(buttonimg.getImage());
GamePanel gp = new GamePanel(SparkManager.getConnection(),
	gop.getGameID(), gop.isStartingPlayer(), opponentJID,f);
f.add(gp);
f.pack();
f.setLocationRelativeTo(SparkManager.getChatManager().getChatContainer());
f.setVisible(true);

   }
 
Example #2
Source File: WrappedJid.java    From Pix-Art-Messenger with GNU General Public License v3.0 6 votes vote down vote up
@Override
public eu.siacs.conversations.xmpp.Jid withResource(CharSequence resource) {
    final Localpart localpart = inner.getLocalpartOrNull();
    try {
        final Resourcepart resourcepart = Resourcepart.from(resource.toString());
        if (localpart == null) {
            return new WrappedJid(JidCreate.domainFullFrom(inner.getDomain(),resourcepart));
        } else {
            return new WrappedJid(
                    JidCreate.fullFrom(
                            localpart,
                            inner.getDomain(),
                            resourcepart
                    ));
        }
    } catch (XmppStringprepException e) {
        throw new IllegalArgumentException(e);
    }
}
 
Example #3
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 #4
Source File: InvalidJidTestresult.java    From jxmpp with Apache License 2.0 6 votes vote down vote up
@Override
public String toString() {
	StringBuilder sb = new StringBuilder();
	sb.append(xmppStringPrepper)
	.append(" failed to handle the following invalid JID:\n")
	.append(invalidJid).append('\n')
	.append("as it produced the following JID (when it should have thrown an exception):\n")
	.append(jid).append('\n');
	Localpart localpart = jid.getLocalpartOrNull();
	if (localpart != null) {
		sb.append("- localpart: ").append(localpart).append('\n');
	}
	Domainpart domainpart = jid.getDomain();
	sb.append("- domanipart: ").append(domainpart).append('\n');
	Resourcepart resourcepart = jid.getResourceOrNull();
	if (resourcepart != null) {
		sb.append("- resourcepart: ").append(resourcepart).append('\n');
	}
	return sb.toString();
}
 
Example #5
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 #6
Source File: AccountManager.java    From Smack with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new account using the specified username, password and account attributes.
 * The attributes Map must contain only String name/value pairs and must also have values
 * for all required attributes.
 *
 * @param username the username.
 * @param password the password.
 * @param attributes the account attributes.
 * @throws XMPPErrorException if an error occurs creating the account.
 * @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.
 * @see #getAccountAttributes()
 */
public void createAccount(Localpart username, String password, Map<String, String> attributes)
                throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    if (!connection().isSecureConnection() && !allowSensitiveOperationOverInsecureConnection) {
        throw new IllegalStateException("Creating account over insecure connection");
    }
    if (username == null) {
        throw new IllegalArgumentException("Username must not be null");
    }
    if (StringUtils.isNullOrEmpty(password)) {
        throw new IllegalArgumentException("Password must not be null");
    }

    attributes.put("username", username.toString());
    attributes.put("password", password);
    Registration reg = new Registration(attributes);
    reg.setType(IQ.Type.set);
    reg.setTo(connection().getXMPPServiceDomain());
    createStanzaCollectorAndSend(reg).nextResultOrThrow();
}
 
Example #7
Source File: XmppTools.java    From Smack with Apache License 2.0 6 votes vote down vote up
public static boolean createAccount(DomainBareJid xmppDomain, Localpart username, String password)
        throws KeyManagementException, NoSuchAlgorithmException, SmackException, IOException, XMPPException,
        InterruptedException {
    XMPPTCPConnectionConfiguration.Builder configBuilder = XMPPTCPConnectionConfiguration.builder()
            .setXmppDomain(xmppDomain);
    TLSUtils.acceptAllCertificates(configBuilder);
    XMPPTCPConnectionConfiguration config = configBuilder.build();
    XMPPTCPConnection connection = new XMPPTCPConnection(config);
    connection.connect();
    try {
        if (!supportsIbr(connection))
            return false;

        AccountManager accountManager = AccountManager.getInstance(connection);
        accountManager.createAccount(username, password);
        return true;
    } finally {
        connection.disconnect();
    }
}
 
Example #8
Source File: WrappedJid.java    From Conversations with GNU General Public License v3.0 6 votes vote down vote up
@Override
public eu.siacs.conversations.xmpp.Jid withResource(CharSequence resource) {
    final Localpart localpart = inner.getLocalpartOrNull();
    try {
        final Resourcepart resourcepart = Resourcepart.from(resource.toString());
        if (localpart == null) {
            return new WrappedJid(JidCreate.domainFullFrom(inner.getDomain(),resourcepart));
        } else {
            return new WrappedJid(
                    JidCreate.fullFrom(
                            localpart,
                            inner.getDomain(),
                            resourcepart
                    ));
        }
    } catch (XmppStringprepException e) {
        throw new IllegalArgumentException(e);
    }
}
 
Example #9
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 #10
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 #11
Source File: ConferenceServices.java    From Spark with Apache License 2.0 6 votes vote down vote up
private void startConference(Collection<ContactItem> items) {
    final ContactList contactList = SparkManager.getWorkspace().getContactList();
    List<Jid> jids = new ArrayList<>();
    for (ContactItem item : items) {
        ContactGroup contactGroup = contactList.getContactGroup(item.getGroupName());
        contactGroup.clearSelection();

        if (item.isAvailable()) {
            jids.add(item.getJid());
        }
    }

    Localpart userName = SparkManager.getSessionManager().getJID().getLocalpart();
    final EntityBareJid roomName = JidCreate.entityBareFromOrThrowUnchecked(userName + "_" + StringUtils.randomString(3));

    DomainBareJid serviceName = getDefaultServiceName();
    if (serviceName != null) {
        ConferenceUtils.inviteUsersToRoom(serviceName, roomName, jids, true);
    }
}
 
Example #12
Source File: ChatManager.java    From Spark with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new public Conference Room.
 *
 * @param roomName    the name of the room.
 * @param serviceName the service name to use (ex.conference.jivesoftware.com)
 * @return the new ChatRoom created. If an error occured, null will be returned.
 */
public ChatRoom createConferenceRoom(Localpart roomName, DomainBareJid serviceName) {
    EntityBareJid roomAddress = JidCreate.entityBareFrom(roomName, serviceName);
    final MultiUserChat chatRoom = MultiUserChatManager.getInstanceFor( SparkManager.getConnection()).getMultiUserChat( roomAddress);

    final GroupChatRoom room = UIComponentRegistry.createGroupChatRoom(chatRoom);

    try {
        LocalPreferences pref = SettingsManager.getLocalPreferences();
        Resourcepart nickname = pref.getNickname();
        chatRoom.create(nickname);

        // Send an empty room configuration form which indicates that we want
        // an instant room
        chatRoom.sendConfigurationForm(new Form( DataForm.Type.submit ));
    }
    catch (XMPPException | SmackException | InterruptedException e1) {
        Log.error("Unable to send conference room chat configuration form.", e1);
        return null;
    }

    getChatContainer().addChatRoom(room);
    return room;
}
 
Example #13
Source File: MultiUserChatIntegrationTest.java    From Smack with Apache License 2.0 6 votes vote down vote up
@SmackIntegrationTest
public void mucJoinLeaveTest() throws XmppStringprepException, NotAMucServiceException, NoResponseException,
        XMPPErrorException, NotConnectedException, InterruptedException, MucNotJoinedException {
    EntityBareJid mucAddress = JidCreate.entityBareFrom(Localpart.from("smack-inttest-join-leave-" + randomString),
            mucService.getDomain());

    MultiUserChat muc = mucManagerOne.getMultiUserChat(mucAddress);

    muc.join(Resourcepart.from("nick-one"));

    Presence reflectedLeavePresence = muc.leave();

    MUCUser mucUser = MUCUser.from(reflectedLeavePresence);
    assertNotNull(mucUser);

    assertTrue(mucUser.getStatus().contains(MUCUser.Status.PRESENCE_TO_SELF_110));
}
 
Example #14
Source File: Workpane.java    From Spark with Apache License 2.0 6 votes vote down vote up
public Properties getWorkgroupProperties() {
    Localpart workgroupName = FastpathPlugin.getWorkgroup().getWorkgroupJID().getLocalpartOrThrow();

    File workgroupDir = new File(Spark.getSparkUserHome(), "workgroups/" + workgroupName);
    workgroupDir.mkdirs();

    File propertiesFile = new File(workgroupDir, "workgroup.properties");
    Properties props = new Properties();
    try {
        props.load(new FileInputStream(propertiesFile));
    }
    catch (IOException e) {
        // File does not exist.
    }
    return props;
}
 
Example #15
Source File: Workpane.java    From Spark with Apache License 2.0 6 votes vote down vote up
public void decorateRoom(ChatRoom room, Map metadata) {
    EntityBareJid roomName = room.getRoomJid();
    Localpart sessionID =roomName.getLocalpart();


    RequestUtils utils = new RequestUtils(metadata);

    addRoomInfo(sessionID, utils, room);

    addButtons(sessionID.toString(), utils, room);

    // Specify to use Typing notifications.
    GroupChatRoom groupChat = (GroupChatRoom)room;
    groupChat.setChatStatEnabled(true);

    Properties props = FastpathPlugin.getLitWorkspace().getWorkgroupProperties();
    String initialResponse = props.getProperty(INITIAL_RESPONSE_PROPERTY);
    if (ModelUtil.hasLength(initialResponse)) {
        Message message = new Message();
        message.setBody(initialResponse);
        GroupChatRoom groupChatRoom = (GroupChatRoom)room;
        groupChatRoom.sendMessage(message);
    }
}
 
Example #16
Source File: WorkgroupManager.java    From Spark with Apache License 2.0 6 votes vote down vote up
@Override
public boolean handleInvitation(final XMPPConnection conn, final MultiUserChat room, final EntityBareJid inviter, final String reason, final String password, final Message message) {
    invites.add(inviter);

    if (message.getExtension("workgroup", "http://jabber.org/protocol/workgroup") != null) {
        Localpart workgroupName = inviter.getLocalpart();
        GroupChatRoom groupChatRoom = ConferenceUtils.enterRoomOnSameThread(workgroupName, room.getRoom(), password);

        int tabLocation = SparkManager.getChatManager().getChatContainer().indexOfComponent(groupChatRoom);
        groupChatRoom.setTabIcon(FastpathRes.getImageIcon(FastpathRes.FASTPATH_IMAGE_16x16));
        if (tabLocation != -1) {
            SparkTab tab = SparkManager.getChatManager().getChatContainer().getTabAt(tabLocation);
            tab.setIcon(FastpathRes.getImageIcon(FastpathRes.FASTPATH_IMAGE_16x16));
        }
        return true;
    }

    return false;
}
 
Example #17
Source File: GrowlMessageListener.java    From Spark with Apache License 2.0 6 votes vote down vote up
/**
 * Show a global Growl Notification
 *
 * @param message
 *            , {@link Message} containing Body and Sender
 */
private void showGrowlNotification( Message message )
{
    try
    {
        String name = SparkManager.getUserManager().getUserNicknameFromJID( message.getFrom().asBareJid() );
        Jid jid = message.getFrom();

        if ( name == null )
        {
            Localpart localpart = message.getFrom().getLocalpartOrNull();
            if (localpart != null) {
                name = localpart.toString();
            }
        }

        talker.sendNotificationWithCallback( name, message.getBody(), jid.toString() );
    }
    catch ( Exception e )
    {
        Log.error( e.getMessage(), e );
    }

}
 
Example #18
Source File: SparkMeetPlugin.java    From Spark with Apache License 2.0 6 votes vote down vote up
public void chatRoomClosed(ChatRoom chatroom)
{
    Localpart roomId = chatroom.getRoomJid().getLocalpart();

    Log.debug("chatRoomClosed:  " + roomId);

    if (decorators.containsKey(roomId))
    {
        ChatRoomDecorator decorator = decorators.remove(roomId);
        decorator.finished();
        decorator = null;
    }

    if (browser != null)
    {
        browser.dispose();
        browser = null;
    }
}
 
Example #19
Source File: SparkMeetPlugin.java    From Spark with Apache License 2.0 6 votes vote down vote up
@Override
public void messageReceived(ChatRoom room, Message message) {

    try {
        Localpart roomId = room.getRoomJid().getLocalpart();
        String body = message.getBody();

        if ( body.startsWith("https://") && body.endsWith("/" + roomId) ) {
            showInvitationAlert(message.getBody(), room, roomId);
        }


    } catch (Exception e) {
        // i don't care
    }

}
 
Example #20
Source File: UserSearchResults.java    From Spark with Apache License 2.0 6 votes vote down vote up
private void openChatRoom(int row) {
    String jidString = (String)resultsTable.getValueAt(row, 0);
    EntityBareJid jid = JidCreate.entityBareFromOrThrowUnchecked(jidString);
    Localpart nickname = jid.getLocalpart();

    TableColumn column;
    try {
        column = resultsTable.getColumn("nick");
        int col = column.getModelIndex();
        String nicknameString = (String)resultsTable.getValueAt(row, col);
        if (!ModelUtil.hasLength(nicknameString)) {
            nickname = JidCreate.from(nicknameString).getLocalpartOrThrow();
        }
    }
    catch (Exception e1) {
        // Ignore e1
    }

    ChatManager chatManager = SparkManager.getChatManager();
    ChatRoom chatRoom = chatManager.createChatRoom(jid, nickname, nickname);

    ChatContainer chatRooms = chatManager.getChatContainer();
    chatRooms.activateChatRoom(chatRoom);
}
 
Example #21
Source File: ChatArgumentsPlugin.java    From Spark with Apache License 2.0 6 votes vote down vote up
@Override
public void initialize() {
       EntityBareJid start_chat_jid = null;
       try {
           start_chat_jid = JidCreate.entityBareFromUnescaped(Spark.getArgumentValue("start_chat_jid"));
       } catch (XmppStringprepException e1) {
       }
       EntityBareJid start_chat_muc = null;
       try {
           start_chat_muc = JidCreate.entityBareFromUnescaped(Spark.getArgumentValue("start_chat_muc"));
       } catch (XmppStringprepException e) {
       }

       if (start_chat_jid != null) {
           Localpart nickname = start_chat_jid.getLocalpart();
           SparkManager.getChatManager().createChatRoom(start_chat_jid, nickname.toString(), start_chat_jid.toString());
       }

       if (start_chat_muc != null) {
           ConferenceUtils.joinConferenceOnSeperateThread(start_chat_muc, start_chat_muc, null);
       }

   }
 
Example #22
Source File: ConversationInvitation.java    From Spark with Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(ActionEvent actionEvent) {
       final Object obj = actionEvent.getSource();
       if (obj == joinButton) {
           Localpart name = roomName.getLocalpart();
           ConferenceUtils.enterRoomOnSameThread(name.toString(), roomName, password);
       }
       else {
           try
           {
               MultiUserChatManager.getInstanceFor( SparkManager.getConnection() ).decline( roomName, inviter, "No thank you");
           }
           catch ( SmackException.NotConnectedException | InterruptedException e )
           {
               Log.warning( "unable to decline invatation from " + inviter + " to join room " + roomName, e );
           }
       }

       // Close Container
       ChatManager chatManager = SparkManager.getChatManager();
       chatManager.getChatContainer().closeTab(this);
   }
 
Example #23
Source File: Workspace.java    From Spark with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new room based on an anonymous user.
 *
 * @param bareJID the bareJID of the anonymous user.
 * @param message the message from the anonymous user.
 */
private void createOneToOneRoom(EntityBareJid bareJID, Message message) {
    ContactItem contact = contactList.getContactItemByJID(bareJID);
    Localpart localpart = bareJID.getLocalpartOrNull();
    String nickname = null;
    if (localpart != null) {
        nickname = localpart.toString();
    }
    if (contact != null) {
        nickname = contact.getDisplayName();
    }
    else {
        // Attempt to load VCard from users who we are not subscribed to.
        VCard vCard = SparkManager.getVCardManager().getVCard(bareJID);
        if (vCard != null && vCard.getError() == null) {
            String firstName = vCard.getFirstName();
            String lastName = vCard.getLastName();
            String userNickname = vCard.getNickName();
            if (ModelUtil.hasLength(userNickname)) {
                nickname = userNickname;
            }
            else if (ModelUtil.hasLength(firstName) && ModelUtil.hasLength(lastName)) {
                nickname = firstName + " " + lastName;
            }
            else if (ModelUtil.hasLength(firstName)) {
                nickname = firstName;
            }
        }
    }

    SparkManager.getChatManager().createChatRoom(bareJID, nickname, nickname);
    try {
        insertMessage(bareJID, message);
    }
    catch (ChatRoomNotFoundException e) {
        Log.error("Could not find chat room.", e);
    }
}
 
Example #24
Source File: BuzzPlugin.java    From Spark with Apache License 2.0 5 votes vote down vote up
private void shakeWindow(Message message) {

	EntityBareJid bareJID = message.getFrom().asEntityBareJidOrThrow();
	ContactItem contact = SparkManager.getWorkspace().getContactList()
		.getContactItemByJID(bareJID);
	Localpart nickname = bareJID.getLocalpart();
	if (contact != null) {
	    nickname = Localpart.fromUnescapedOrThrowUnchecked(contact.getDisplayName());
	}

	ChatRoom room;
	try {
	    room = SparkManager.getChatManager().getChatContainer()
		    .getChatRoom(bareJID);
	} catch (ChatRoomNotFoundException e) {
	    // Create the room if it does not exist.
	    room = SparkManager.getChatManager().createChatRoom(bareJID,
		    nickname.toString(), nickname.toString());
	}

	ChatFrame chatFrame = SparkManager.getChatManager().getChatContainer()
		.getChatFrame();
	if (chatFrame != null) {
	    if (SettingsManager.getLocalPreferences().isBuzzEnabled()) {
		chatFrame.buzz();
		SparkManager.getChatManager().getChatContainer()
			.activateChatRoom(room);
	    }
	}

	// Insert offline message
	room.getTranscriptWindow().insertNotificationMessage(
		Res.getString("message.buzz.message", nickname),
		ChatManager.NOTIFICATION_COLOR);
	room.scrollToBottom();
    }
 
Example #25
Source File: MultiUserChatIntegrationTest.java    From Smack with Apache License 2.0 5 votes vote down vote up
@SmackIntegrationTest
public void mucTest() throws Exception {
    EntityBareJid mucAddress = JidCreate.entityBareFrom(Localpart.from("smack-inttest-" + randomString), mucService.getDomain());

    MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress);
    MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress);

    final String mucMessage = "Smack Integration Test MUC Test Message " + randomString;
    final ResultSyncPoint<String, Exception> resultSyncPoint = new ResultSyncPoint<>();

    mucAsSeenByTwo.addMessageListener(new MessageListener() {
        @Override
        public void processMessage(Message message) {
            String body = message.getBody();
            if (mucMessage.equals(body)) {
                resultSyncPoint.signal(body);
            }
        }
    });

    MucCreateConfigFormHandle handle = mucAsSeenByOne.createOrJoin(Resourcepart.from("one-" + randomString));
    if (handle != null) {
        handle.makeInstant();
    }
    mucAsSeenByTwo.join(Resourcepart.from("two-" + randomString));

    mucAsSeenByOne.sendMessage(mucMessage);
    resultSyncPoint.waitForResult(timeout);

    mucAsSeenByOne.leave();
    mucAsSeenByTwo.leave();
}
 
Example #26
Source File: MultiUserChatIntegrationTest.java    From Smack with Apache License 2.0 5 votes vote down vote up
@SmackIntegrationTest
public void mucDestroyTest() throws TimeoutException, Exception {

    EntityBareJid mucAddress = JidCreate.entityBareFrom(Localpart.from("smack-inttest-join-leave-" + randomString),
                                                        mucService.getDomain());

    MultiUserChat muc = mucManagerOne.getMultiUserChat(mucAddress);
    muc.join(Resourcepart.from("nick-one"));

    final SimpleResultSyncPoint mucDestroyed = new SimpleResultSyncPoint();

    @SuppressWarnings("deprecation")
    DefaultUserStatusListener userStatusListener = new DefaultUserStatusListener() {
        @Override
        public void roomDestroyed(MultiUserChat alternateMUC, String reason) {
            mucDestroyed.signal();
        }
    };

    muc.addUserStatusListener(userStatusListener);

    assertTrue(mucManagerOne.getJoinedRooms().size() == 1);
    assertTrue(muc.getOccupantsCount() == 1);
    assertTrue(muc.getNickname() != null);

    try {
        muc.destroy("Dummy reason", null);
        mucDestroyed.waitForResult(timeout);
    } finally {
        muc.removeUserStatusListener(userStatusListener);
    }

    assertTrue(mucManagerOne.getJoinedRooms().size() == 0);
    assertTrue(muc.getOccupantsCount() == 0);
    assertTrue(muc.getNickname() == null);
}
 
Example #27
Source File: MultiUserChatLowLevelIntegrationTest.java    From Smack with Apache License 2.0 5 votes vote down vote up
@SmackIntegrationTest
public void testMucBookmarksAutojoin(AbstractXMPPConnection connection) throws InterruptedException,
                TestNotPossibleException, XMPPException, SmackException, IOException {
    final BookmarkManager bookmarkManager = BookmarkManager.getBookmarkManager(connection);
    if (!bookmarkManager.isSupported()) {
        throw new TestNotPossibleException("Private data storage not supported");
    }
    final MultiUserChatManager multiUserChatManager = MultiUserChatManager.getInstanceFor(connection);
    final Resourcepart mucNickname = Resourcepart.from("Nick-" + StringUtils.randomString(6));
    final String randomMucName = StringUtils.randomString(6);
    final DomainBareJid mucComponent = multiUserChatManager.getMucServiceDomains().get(0);
    final MultiUserChat muc = multiUserChatManager.getMultiUserChat(JidCreate.entityBareFrom(
                    Localpart.from(randomMucName), mucComponent));

    MucCreateConfigFormHandle handle = muc.createOrJoin(mucNickname);
    if (handle != null) {
        handle.makeInstant();
    }
    muc.leave();

    bookmarkManager.addBookmarkedConference("Smack Inttest: " + testRunId, muc.getRoom(), true,
                    mucNickname, null);

    connection.disconnect();
    connection.connect().login();

    // MucBookmarkAutojoinManager is also able to do its task automatically
    // after every login, it's not deterministic when this will be finished.
    // So we trigger it manually here.
    MucBookmarkAutojoinManager.getInstanceFor(connection).autojoinBookmarkedConferences();

   assertTrue(muc.isJoined());

   // If the test went well, leave the MUC
   muc.leave();
}
 
Example #28
Source File: XmppConnectionManager.java    From Smack with Apache License 2.0 5 votes vote down vote up
private void registerAccount(String username, String password) throws NoResponseException, XMPPErrorException,
                NotConnectedException, InterruptedException, XmppStringprepException {
    if (accountRegistrationConnection == null) {
        throw new IllegalStateException("Account registration not configured");
    }

    switch (sinttestConfiguration.accountRegistration) {
    case serviceAdministration:
        EntityBareJid userJid = JidCreate.entityBareFrom(Localpart.from(username),
                        accountRegistrationConnection.getXMPPServiceDomain());
        adminManager.addUser(userJid, password);
        break;
    case inBandRegistration:
        if (!accountManager.supportsAccountCreation()) {
            throw new UnsupportedOperationException("Account creation/registation is not supported");
        }
        Set<String> requiredAttributes = accountManager.getAccountAttributes();
        if (requiredAttributes.size() > 4) {
            throw new IllegalStateException("Unkown required attributes");
        }
        Map<String, String> additionalAttributes = new HashMap<>();
        additionalAttributes.put("name", "Smack Integration Test");
        additionalAttributes.put("email", "[email protected]");
        Localpart usernameLocalpart = Localpart.from(username);
        accountManager.createAccount(usernameLocalpart, password, additionalAttributes);
        break;
    case disabled:
        throw new IllegalStateException("Account creation no possible");
    }
}
 
Example #29
Source File: XmppTools.java    From Smack with Apache License 2.0 5 votes vote down vote up
public static boolean createAccount(String xmppDomain, String username, String password)
        throws KeyManagementException, NoSuchAlgorithmException, SmackException, IOException, XMPPException,
        InterruptedException {
    DomainBareJid xmppDomainJid = JidCreate.domainBareFrom(xmppDomain);
    Localpart localpart = Localpart.from(username);
    return createAccount(xmppDomainJid, localpart, password);
}
 
Example #30
Source File: GroupChatInvitationUI.java    From Spark with Apache License 2.0 5 votes vote down vote up
/**
  * Action taking when a user clicks on the accept button.
  */
 private void acceptInvitation() {
     setVisible(false);
     Localpart name = room.getLocalpart();
     ConferenceUtils.enterRoomOnSameThread(name.toString(), room, password);

     final TimerTask removeUITask = new SwingTimerTask() {
         @Override
public void doRun() {
             removeUI();
         }
     };

     TaskEngine.getInstance().schedule(removeUITask, 2000);
 }