Java Code Examples for org.jivesoftware.smackx.vcardtemp.packet.VCard#getNickName()
The following examples show how to use
org.jivesoftware.smackx.vcardtemp.packet.VCard#getNickName() .
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: UserManager.java From Spark with Apache License 2.0 | 6 votes |
public String getNickname() { final VCardManager vCardManager = SparkManager.getVCardManager(); VCard vcard = vCardManager.getVCard(); if (vcard == null) { return SparkManager.getSessionManager().getUsername(); } else { String nickname = vcard.getNickName(); if (ModelUtil.hasLength(nickname)) { return nickname; } else { String firstName = vcard.getFirstName(); if (ModelUtil.hasLength(firstName)) { return firstName; } } } // Default to node if nothing. String username = SparkManager.getSessionManager().getUsername(); username = XmppStringUtils.unescapeLocalpart(username); return username; }
Example 2
Source File: UserManager.java From Spark with Apache License 2.0 | 6 votes |
public String getNickname(BareJid jid) { String vcardNickname = null; VCard vCard = SparkManager.getVCardManager().getVCard(jid); if (vCard != null && vCard.getError() == null) { String firstName = vCard.getFirstName(); String lastName = vCard.getLastName(); String nickname = vCard.getNickName(); if (ModelUtil.hasLength(nickname)) { vcardNickname = nickname; } else if (ModelUtil.hasLength(firstName) && ModelUtil.hasLength(lastName)) { vcardNickname = firstName + " " + lastName; } else if (ModelUtil.hasLength(firstName)) { vcardNickname = firstName; } } return vcardNickname; }
Example 3
Source File: Workspace.java From Spark with Apache License 2.0 | 5 votes |
/** * 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 4
Source File: RosterDialog.java From Spark with Apache License 2.0 | 4 votes |
/** * Method to handle the Add-Button */ private void addContactButton() { String errorMessage = Res.getString("title.error"); String jid = getJID(); UIManager.put("OptionPane.okButtonText", Res.getString("ok")); if(jid.length()==0) { JOptionPane.showMessageDialog(dialog, Res.getString("message.invalid.jid.error"), Res.getString("title.error"), JOptionPane.ERROR_MESSAGE); return; } String contact = UserManager.escapeJID(jid); String nickname = nicknameField.getText(); String group = (String) groupBox.getSelectedItem(); Transport transport = null; if (publicBox.isSelected()) { AccountItem item = (AccountItem) accounts.getSelectedItem(); transport = item.getTransport(); } if (transport == null) { if (!contact.contains("@")) { contact = contact + "@" + SparkManager.getConnection().getXMPPServiceDomain(); } } else { if (!contact.contains("@")) { contact = contact + "@" + transport.getXMPPServiceDomain(); } } if (!ModelUtil.hasLength(nickname) && ModelUtil.hasLength(contact)) { // Try to load nickname from VCard VCard vcard = new VCard(); try { EntityBareJid contactJid = JidCreate.entityBareFrom(contact); vcard.load(SparkManager.getConnection(), contactJid); nickname = vcard.getNickName(); } catch (XMPPException | SmackException | XmppStringprepException | InterruptedException e1) { Log.error(e1); } // If no nickname, use first name. if (!ModelUtil.hasLength(nickname)) { nickname = XmppStringUtils.parseLocalpart(contact); } nicknameField.setText(nickname); } ContactGroup contactGroup = contactList.getContactGroup(group); boolean isSharedGroup = contactGroup != null && contactGroup.isSharedGroup(); if (isSharedGroup) { errorMessage = Res .getString("message.cannot.add.contact.to.shared.group"); } else if (!ModelUtil.hasLength(contact)) { errorMessage = Res.getString("message.specify.contact.jid"); } else if (!XmppStringUtils.parseBareJid(contact).contains("@")) { errorMessage = Res.getString("message.invalid.jid.error"); } else if (!ModelUtil.hasLength(group)) { errorMessage = Res.getString("message.specify.group"); } else if (ModelUtil.hasLength(contact) && ModelUtil.hasLength(group) && !isSharedGroup) { addEntry(); dialog.setVisible(false); } else { JOptionPane.showMessageDialog(dialog, errorMessage, Res.getString("title.error"), JOptionPane.ERROR_MESSAGE); } }