Java Code Examples for org.jxmpp.jid.EntityBareJid#getLocalpart()

The following examples show how to use org.jxmpp.jid.EntityBareJid#getLocalpart() . 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: 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 2
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 3
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 4
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 5
Source File: JidCreateTest.java    From jxmpp with Apache License 2.0 5 votes vote down vote up
@Test
public void entityBareFromUnescapedTest() throws XmppStringprepException {
	EntityBareJid entityBareJid = JidCreate.entityBareFromUnescaped("foo@[email protected]/baz");

	// Tricky question. Currently yields '[email protected]'. Domainparts are U-Labels, so this may be correct, even
	// if it is not a valid DNS label/name.
	Domainpart domainpart = entityBareJid.getDomain();
	assertEquals(Domainpart.from("[email protected]"), domainpart);

	Localpart localpart = entityBareJid.getLocalpart();
	assertEquals(Localpart.from("foo"), localpart);
}
 
Example 6
Source File: BookmarksUI.java    From Spark with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the current bookmarks used with this account.
 *
 * @param bookmarks the current bookmarks used with this account.
 */
public void setBookmarks(Collection<BookmarkedConference> bookmarks) {

    for (BookmarkedConference bookmark : bookmarks) {
        DomainBareJid serviceName = bookmark.getJid().asDomainBareJid();
        EntityBareJid roomJID = bookmark.getJid();
        Localpart roomName = roomJID.getLocalpart();

        if (bookmark.isAutoJoin()) {
            ConferenceUtils.joinConferenceOnSeperateThread(roomName, bookmark.getJid(), bookmark.getPassword());
            ConferenceUtils.addUnclosableChatRoom(roomJID);
            autoJoinRooms.add(bookmark.getJid());
        }

        // Get Service Node
        TreePath path = tree.findByName(tree, new String[]{rootNode.getUserObject().toString(), serviceName.toString()});
        JiveTreeNode serviceNode;
        if (path == null) {
            serviceNode = addServiceToList(serviceName);
            path = tree.findByName(tree, new String[]{rootNode.getUserObject().toString(), serviceName.toString()});
        }
        else {
            serviceNode = (JiveTreeNode)path.getLastPathComponent();
        }

        addBookmark(serviceNode, roomName.toString(), roomJID.toString());

        tree.expandPath(path);
    }
}
 
Example 7
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 8
Source File: WorkgroupManager.java    From Spark with Apache License 2.0 4 votes vote down vote up
private void showWorkgroup(final ContactItem contactItem) throws Exception {
     VCard vcard = SparkManager.getVCardManager().getVCard();

     final Map<String, String> variables = new HashMap<String, String>();
     String firstName = vcard.getFirstName();
     String lastName = vcard.getLastName();

     if (ModelUtil.hasLength(firstName) && ModelUtil.hasLength(lastName)) {
         variables.put("username", firstName + " " + lastName);
     }
     else if (ModelUtil.hasLength(firstName)) {
         variables.put("username", firstName);
     }
     else if (ModelUtil.hasLength(lastName)) {
         variables.put("username", lastName);
     }

     String email = vcard.getEmailHome();
     String emailWork = vcard.getEmailWork();

     if (ModelUtil.hasLength(emailWork)) {
         email = emailWork;
     }

     if (ModelUtil.hasLength(email)) {
         variables.put("email", email);
     }


     EntityBareJid workgroupJID = contactItem.getJid().asEntityBareJidOrThrow();
     Localpart nameOfWorkgroup = workgroupJID.getLocalpart();
     final JDialog workgroupDialog = new JDialog(SparkManager.getMainWindow(), "Contact " + nameOfWorkgroup + " Workgroup");
     Workgroup workgroup = new Workgroup(workgroupJID, SparkManager.getConnection());

     final Form workgroupForm = workgroup.getWorkgroupForm();
     String welcomeText = FormText.getWelcomeText(workgroupJID.toString());
     String startButton = FormText.getStartButton(workgroupJID.toString());

     final WorkgroupDataForm formUI = new WorkgroupDataForm(workgroupForm, variables);
     formUI.setBackground(Color.white);

     final JPanel titlePane = new LiveTitlePane("Contact Workgroup", FastpathRes.getImageIcon(FastpathRes.FASTPATH_IMAGE_24x24)) {
private static final long serialVersionUID = -4484940286068835770L;

public Dimension getPreferredSize() {
             final Dimension size = super.getPreferredSize();
             size.width = 400;
             return size;
         }
     };


     formUI.add(titlePane, new GridBagConstraints(0, 0, 3, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));

     final JButton submitButton = new JButton("Start Chat!");
     submitButton.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent e) {
             if (validateForm(workgroupDialog, workgroupForm, formUI.getFilledForm())) {
                 enterQueue(contactItem.getJid().asEntityBareJidOrThrow(), formUI.getFilledForm());
                 workgroupDialog.dispose();
             }
         }
     });


     formUI.setEnterListener(new WorkgroupDataForm.EnterListener() {
         public void enterPressed() {
             if (validateForm(workgroupDialog, workgroupForm, formUI.getFilledForm())) {
                 enterQueue(contactItem.getJid().asEntityBareJidOrThrow(), formUI.getFilledForm());
                 workgroupDialog.dispose();
             }
         }
     });


     formUI.add(submitButton, new GridBagConstraints(1, 100, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));


     workgroupDialog.getContentPane().setLayout(new BorderLayout());
     workgroupDialog.getContentPane().add(formUI, BorderLayout.CENTER);

     workgroupDialog.pack();
     GraphicUtils.centerWindowOnScreen(workgroupDialog);
     workgroupDialog.setVisible(true);
 }