Java Code Examples for org.jxmpp.jid.parts.Localpart#toString()

The following examples show how to use org.jxmpp.jid.parts.Localpart#toString() . 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: 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 2
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 3
Source File: WrappedJid.java    From Pix-Art-Messenger with GNU General Public License v3.0 4 votes vote down vote up
@Override
public String getEscapedLocal() {
    final Localpart localpart = inner.getLocalpartOrNull();
    return localpart == null ? null : localpart.toString();
}
 
Example 4
Source File: JID.java    From desktopclient-java with GNU General Public License v3.0 4 votes vote down vote up
public static JID fromSmack(Jid jid) {
    Localpart localpart = jid.getLocalpartOrNull();
    return new JID(localpart != null ? localpart.toString() : "",
            jid.getDomain().toString(),
            jid.getResourceOrEmpty().toString());
}
 
Example 5
Source File: WrappedJid.java    From Conversations with GNU General Public License v3.0 4 votes vote down vote up
@Override
public String getEscapedLocal() {
    final Localpart localpart = inner.getLocalpartOrNull();
    return localpart == null ? null : localpart.toString();
}
 
Example 6
Source File: ChatRoomImpl.java    From Spark with Apache License 2.0 4 votes vote down vote up
protected void loadHistory() {
	// Add VCard Panel
	vcardPanel = new VCardPanel(participantJID.asBareJid());
	getToolBar().add(vcardPanel, new GridBagConstraints(0, 1, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(0, 2, 0, 2), 0, 0));

   	if (!Default.getBoolean("HISTORY_DISABLED") && Enterprise.containsFeature(Enterprise.HISTORY_TRANSCRIPTS_FEATURE)) {
		final LocalPreferences localPreferences = SettingsManager.getLocalPreferences();
		if (!localPreferences.isChatHistoryEnabled()) {
			return;
		}

		if (!localPreferences.isPrevChatHistoryEnabled()) {
			return;
		}

		final ChatTranscript chatTranscript = ChatTranscripts.getCurrentChatTranscript(getParticipantJID());
		final String personalNickname = SparkManager.getUserManager().getNickname();

		for (HistoryMessage message : chatTranscript.getMessages()) {
			String nickname = SparkManager.getUserManager().getUserNicknameFromJID(message.getFrom().asBareJid());
			String messageBody = message.getBody();
			if (nickname.equals(message.getFrom().toString())) {
				BareJid otherJID = message.getFrom().asBareJid();
				EntityBareJid myJID = SparkManager.getSessionManager().getBareUserAddress();

				if (otherJID.equals(myJID)) {
					nickname = personalNickname;
				}
				else {
				    Resourcepart resourcepart = message.getFrom().getResourceOrNull();
				    if (resourcepart == null) {
				        Localpart localpart = message.getFrom().getLocalpartOrNull();
				        if (localpart != null) {
				            nickname = localpart.toString();
				        }
				    } else {
				        nickname = resourcepart.toString();
				    }
				}
			}

			if (ModelUtil.hasLength(messageBody) && messageBody.startsWith("/me ")) {
				messageBody = messageBody.replaceFirst("/me", nickname);
			}

			final Date messageDate = message.getDate();
			getTranscriptWindow().insertHistoryMessage(nickname, messageBody, messageDate);
		}
		if ( 0 < chatTranscript.getMessages().size() ) { // Check if we have history mesages
			getTranscriptWindow().insertHorizontalLine();
		}
		chatTranscript.release();
	}
}