Java源码示例:org.jxmpp.jid.EntityFullJid

示例1
public List<String> getRoomParticipants(String threadId) {
    List<EntityFullJid> usersJids = null;
    List<String> usersIds = new ArrayList<>();
    try {
        //RoomInfo roomInfo = manager.getRoomInfo(JidCreate.entityBareFrom(threadId));
        MultiUserChat multiUserChat = manager.getMultiUserChat(JidCreate.entityBareFrom(threadId));
        usersJids = multiUserChat.getOccupants();

        for (EntityFullJid entityFullJid : usersJids) {
            usersIds.add(entityFullJid.toString());
        }
    } catch (XmppStringprepException e) {
        e.printStackTrace();
    }

    return usersIds;
}
 
示例2
@Override
public void joined(EntityFullJid entityFullJid) {
     XmppAddress xa = new XmppAddress(entityFullJid.toString());
     ChatGroup chatGroup = mChatGroupManager.getChatGroup(xa);
     MultiUserChat muc = mChatGroupManager.getMultiUserChat(entityFullJid.asBareJid().toString());

     Occupant occupant = muc.getOccupant(entityFullJid);
     Jid jidSource = (occupant != null) ? occupant.getJid() : null;
     if (jidSource != null)
     xa = new XmppAddress(jidSource.toString());
     else
     xa = new XmppAddress(entityFullJid.toString());

     Contact mucContact = new Contact(xa, xa.getUser(), Imps.Contacts.TYPE_NORMAL);
     chatGroup.notifyMemberJoined(entityFullJid.toString(),mucContact);
    if (occupant != null) {
        chatGroup.notifyMemberRoleUpdate(mucContact, occupant.getRole().name(), occupant.getAffiliation().toString());
    }
}
 
示例3
/**
 * Returns the stream host information of the local SOCKS5 proxy containing the IP address and
 * the port or null if local SOCKS5 proxy is not running.
 *
 * @return the stream host information of the local SOCKS5 proxy or null if local SOCKS5 proxy
 *         is not running
 */
public List<StreamHost> getLocalStreamHost() {
    List<StreamHost> streamHosts = new ArrayList<>();

    XMPPConnection connection = connection();
    EntityFullJid myJid = connection.getUser();

    for (Socks5Proxy socks5Server : Socks5Proxy.getRunningProxies()) {
        List<InetAddress> addresses = socks5Server.getLocalAddresses();
        if (addresses.isEmpty()) {
            continue;
        }

        final int port = socks5Server.getPort();
        for (InetAddress address : addresses) {
            // Prevent loopback addresses from appearing as streamhost
            if (address.isLoopbackAddress()) {
                continue;
            }
            streamHosts.add(new StreamHost(myJid, address, port));
        }
    }

    return streamHosts;
}
 
示例4
/**
 * Get a {@link EntityFullJid} representing the given String.
 *
 * @param jid the JID's String.
 * @return a full JID representing the input String.
 * @throws XmppStringprepException if an error occurs.
 */
public static EntityFullJid entityFullFrom(String jid) throws XmppStringprepException {
	EntityFullJid fullJid = ENTITY_FULLJID_CACHE.lookup(jid);
	if (fullJid != null) {
		return fullJid;
	}

	String localpart = XmppStringUtils.parseLocalpart(jid);
	String domainpart = XmppStringUtils.parseDomain(jid);
	String resource = XmppStringUtils.parseResource(jid);
	try {
		fullJid = entityFullFrom(localpart, domainpart, resource);
	} catch (XmppStringprepException e) {
		throw new XmppStringprepException(jid, e);
	}
	ENTITY_FULLJID_CACHE.put(jid, fullJid);
	return fullJid;
}
 
示例5
Occupant(Presence presence) {
    MUCUser mucUser = (MUCUser) presence.getExtensionElement("x",
            "http://jabber.org/protocol/muc#user");
    MUCItem item = mucUser.getItem();
    this.jid = item.getJid();
    this.affiliation = item.getAffiliation();
    this.role = item.getRole();
    // Get the nickname from the FROM attribute of the presence
    EntityFullJid from = presence.getFrom().asEntityFullJidIfPossible();
    if (from == null) {
        LOGGER.warning("Occupant presence without resource: " + presence.getFrom());
        this.nick = null;
    } else {
        this.nick = from.getResourcepart();
    }
}
 
示例6
/**
 * Creates an OutgoingFileTransfer to send a file to another user.
 *
 * @param userID TODO javadoc me please
 *            The fully qualified jabber ID (i.e. full JID) with resource of the user to
 *            send the file to.
 * @return The send file object on which the negotiated transfer can be run.
 * @exception IllegalArgumentException if userID is null or not a full JID
 */
public OutgoingFileTransfer createOutgoingFileTransfer(EntityFullJid userID) {
    // We need to create outgoing file transfers with a full JID since this method will later
    // use XEP-0095 to negotiate the stream. This is done with IQ stanzas that need to be addressed to a full JID
    // in order to reach an client entity.
    if (userID == null) {
        throw new IllegalArgumentException("userID was null");
    }

    return new OutgoingFileTransfer(connection().getUser(), userID,
            FileTransferNegotiator.getNextStreamID(),
            fileTransferNegotiator);
}
 
示例7
/**
 * Get a {@link EntityFullJid} from a given {@link CharSequence} or {@code null} if the input does not represent a JID.
 *
 * @param cs the input {@link CharSequence}
 * @return a JID or {@code null}
 */
public static EntityFullJid entityFullFromOrNull(CharSequence cs) {
	try {
		return entityFullFrom(cs);
	} catch (XmppStringprepException e) {
		return null;
	}
}
 
示例8
/**
 * 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 "[email protected]/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);
}
 
示例9
@Test
public void fullFromThrowTest() {
	final String notAFullJid = "[email protected]/";
	try {
		EntityFullJid jid = JidCreate.entityFullFrom(notAFullJid);
		// Should throw
		fail(jid + " should never been created");
	} catch (XmppStringprepException e) {
		assertEquals(notAFullJid, e.getCausingString());
	}
}
 
示例10
@Test
public void entityFullFromUnsecapedComplexTest() throws XmppStringprepException {
	EntityFullJid entityFullJid = JidCreate.entityFullFromUnescaped("[email protected]@example.org/[email protected]");

	Domainpart domainpart = entityFullJid.getDomain();
	assertEquals(Domainpart.from("[email protected]"), domainpart);

	Localpart localpart = entityFullJid.getLocalpart();
	assertEquals(Localpart.from("foo"), localpart);

	Resourcepart resourcepart = entityFullJid.getResourcepart();
	assertEquals(Resourcepart.from("[email protected]"), resourcepart);
}
 
示例11
private void addCarbonsListener(XMPPConnection connection) {
    EntityFullJid localAddress = connection.getUser();
    if (localAddress == null) {
        // We where not connected yet and thus we don't know our XMPP address at the moment, which we need to match incoming
        // carbons securely. Abort here. The ConnectionListener above will eventually setup the carbons listener.
        return;
    }

    // XEP-0280 § 11. Security Considerations "Any forwarded copies received by a Carbons-enabled client MUST be
    // from that user's bare JID; any copies that do not meet this requirement MUST be ignored." Otherwise, if
    // those copies do not get ignored, malicious users may be able to impersonate other users. That is why the
    // 'from' matcher is important here.
    connection.addSyncStanzaListener(carbonsListener, new AndFilter(CARBON_EXTENSION_FILTER,
                    FromMatchesFilter.createBare(localAddress)));
}
 
示例12
/**
 * The the XMPP address of this MAM archive. Note that this method may return {@code null} if this MamManager
 * handles the local entity's archive and if the connection has never been authenticated at least once.
 *
 * @return the XMPP address of this MAM archive or {@code null}.
 * @since 4.3.0
 */
public Jid getArchiveAddress() {
    if (archiveAddress == null) {
        EntityFullJid localJid = connection().getUser();
        if (localJid == null) {
            return null;
        }
        return localJid.asBareJid();
    }
    return archiveAddress;
}
 
示例13
protected void banUser(Resourcepart displayName) {
	try {
	    EntityFullJid entityFullJid = userMap.get(displayName);
		Occupant occupant = chat.getOccupant(entityFullJid);
		if (occupant != null) {
			EntityBareJid bareJID = occupant.getJid().asEntityBareJidOrThrow();
			chat.banUser(bareJID, Res
					.getString("message.you.have.been.banned"));
		}
	} catch (XMPPException | SmackException | InterruptedException | IllegalStateException e) {
	    groupChatRoom.getTranscriptWindow().
	    insertNotificationMessage("No can do "+e.getMessage(), ChatManager.ERROR_COLOR);
	}
}
 
示例14
private void leaveWorkgroup() {
    workgroupLabel.setText(FpRes.getString("workgroup") + ":");
    logoutButton.setVisible(false);
    joinButton.setVisible(true);
    comboBox.setVisible(true);

    comboBox.removeAllItems();
    // Log into workgroup
    DomainBareJid workgroupService = JidCreate.domainBareFromOrThrowUnchecked("workgroup." + SparkManager.getSessionManager().getServerAddress());
    EntityFullJid jid = SparkManager.getSessionManager().getJID();

    try {
        Collection<String> col = Agent.getWorkgroups(workgroupService, jid, SparkManager.getConnection());
        // Add workgroups to combobox
        Iterator<String> workgroups = col.iterator();
        while (workgroups.hasNext()) {
            String workgroup = workgroups.next();
            String componentAddress = XmppStringUtils.parseDomain(workgroup);
            setComponentAddress(componentAddress);
            comboBox.addItem(XmppStringUtils.parseLocalpart(workgroup));
        }
    }
    catch (XMPPException | SmackException | InterruptedException ee) {
        // If the user does not belong to a workgroup, then don't initialize the rest of the plugin.
        return;
    }

    try {
        agentSession.setOnline(false);
    }
    catch (XMPPException | SmackException | InterruptedException e1) {
        Log.error(e1);
    }
    litWorkspace.unload();
    wgroup = null;

    // UnRegister tab handler
    SparkManager.getChatManager().removeSparkTabHandler(fastpathTabHandler);
}
 
示例15
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);
}
 
示例16
private EntityFullJid getUserJid() {
    try {
        return JidCreate.entityFullFrom(config.getUsername()
                        + "@"
                        + config.getXMPPServiceDomain()
                        + "/"
                        + (config.getResource() != null ? config.getResource() : "Test"));
    }
    catch (XmppStringprepException e) {
        throw new IllegalStateException(e);
    }
}
 
示例17
/**
 * Handle all presence packets being sent to this Group Chat Room.
 *
 * @param stanza the presence packet.
 */
private void handlePresencePacket( Stanza stanza )
{
    final Presence presence = (Presence) stanza;
    if ( presence.getError() != null )
    {
        return;
    }

    final EntityFullJid from = presence.getFrom().asEntityFullJidIfPossible();
    if (from == null) {
       return;
    }

    final Resourcepart nickname = from.getResourcepart();

    final MUCUser mucUser = stanza.getExtension( "x", "http://jabber.org/protocol/muc#user" );
    final Set<MUCUser.Status> status = new HashSet<>();
    if ( mucUser != null )
    {
        status.addAll( mucUser.getStatus() );
        final Destroy destroy = mucUser.getDestroy();
        if ( destroy != null )
        {
            UIManager.put( "OptionPane.okButtonText", Res.getString( "ok" ) );
            JOptionPane.showMessageDialog( this,
                    Res.getString( "message.room.destroyed", destroy.getReason() ),
                    Res.getString( "title.room.destroyed" ),
                    JOptionPane.INFORMATION_MESSAGE );
            leaveChatRoom();
            return;
        }
    }

    if ( presence.getType() == Presence.Type.unavailable && !status.contains( MUCUser.Status.NEW_NICKNAME_303 ) )
    {
        if ( currentUserList.contains( from ) )
        {
            if ( pref.isShowJoinLeaveMessagesEnabled() )
            {
                getTranscriptWindow().insertNotificationMessage( Res.getString( "message.user.left.room", nickname ), ChatManager.NOTIFICATION_COLOR );
                scrollToBottom();
            }
            currentUserList.remove( from );
        }
    }
    else
    {
        if ( !currentUserList.contains( from ) )
        {
            currentUserList.add( from );
            getChatInputEditor().setEnabled( true );
            if ( pref.isShowJoinLeaveMessagesEnabled() )
            {
                getTranscriptWindow().insertNotificationMessage(
                        Res.getString( "message.user.joined.room", nickname ),
                        ChatManager.NOTIFICATION_COLOR );
                scrollToBottom();
            }
        }
    }
}
 
示例18
@Override
public void kicked(EntityFullJid entityFullJid, Jid jid, String s) {
   //TODO figure out what to do here
}
 
示例19
@Override
public void membershipGranted(EntityFullJid entityFullJid) {
        joined(entityFullJid);
}
 
示例20
@Override
public void membershipRevoked(EntityFullJid entityFullJid) {
        left(entityFullJid);
}
 
示例21
@Override
public void ownershipGranted(EntityFullJid entityFullJid) {
    joined(entityFullJid);
}
 
示例22
@Override
public void adminGranted(EntityFullJid participant) {
}
 
示例23
@Override
public void adminGranted(EntityFullJid entityFullJid) {
    joined(entityFullJid);
}
 
示例24
/**
    * Add the TTT-Button to every opening Chatroom
    * and create Listeners for it
    */
   private void addButtonToToolBar() {


_chatRoomListener = new ChatRoomListenerAdapter() {
    @Override
    public void chatRoomOpened(final ChatRoom room) {
	
	if(!(room instanceof ChatRoomImpl))
	{
	    // Don't do anything if this is not a 1on1-Chat
	    return;
	}
	
	final ChatRoomButton sendGameButton = new ChatRoomButton(buttonimg);
	room.getToolBar().addChatRoomButton(sendGameButton);

	final EntityFullJid opponentJID = ((ChatRoomImpl) room).getJID();

	sendGameButton.addActionListener(new ActionListener() {

	    @Override
	    public void actionPerformed(ActionEvent e) {
		
		if(_currentInvitations.contains(opponentJID.asBareJid()))
		{
		    return;
		}
		
		final GameOfferPacket offer = new GameOfferPacket();
		offer.setTo(opponentJID);
		offer.setType(IQ.Type.get );
		
		_currentInvitations.add(opponentJID.asEntityBareJid());
		room.getTranscriptWindow().insertCustomText
		    (TTTRes.getString("ttt.request.sent"), false, false, Color.BLUE);
			try
			{
				SparkManager.getConnection().sendStanza(offer);
			}
			catch ( SmackException.NotConnectedException | InterruptedException e1 )
			{
				Log.warning( "Unable to send offer to " + opponentJID, e1 );
			}

			SparkManager.getConnection().addAsyncStanzaListener(
			new StanzaListener() {
			    @Override
			    public void processStanza(Stanza stanza) {

				GameOfferPacket answer = (GameOfferPacket)stanza;
				answer.setStartingPlayer(offer.isStartingPlayer());
				answer.setGameID(offer.getGameID());
				if (answer.getType() == IQ.Type.result) {
				    // ACCEPT
				    _currentInvitations.remove(opponentJID.asBareJid());
				    
				    room.getTranscriptWindow().insertCustomText
				    (TTTRes.getString("ttt.request.accept"), false, false, Color.BLUE);
				    
				    createTTTWindow(answer, opponentJID);
				} else {
				    // DECLINE
				    room.getTranscriptWindow().insertCustomText
				    (TTTRes.getString("ttt.request.decline"), false, false, Color.RED);
				    _currentInvitations.remove(opponentJID.asBareJid());
				}

			    }
			},
			// TODO: Just filtering by stanza id is insure, should use Smack's IQ send-response mechanisms.
			new StanzaIdFilter(offer));
	    }
	});

    }

    @Override
    public void chatRoomClosed(ChatRoom room) {
	if (room instanceof ChatRoomImpl) {
	    ChatRoomImpl cri = (ChatRoomImpl) room;
	    _currentInvitations.remove(cri.getParticipantJID());
	}
    }
};


SparkManager.getChatManager().addChatRoomListener(_chatRoomListener);

   }
 
示例25
@Override
public boolean isParentOf(EntityFullJid fullJid) {
	return false;
}
 
示例26
@Override
public EntityFullJid asEntityFullJidIfPossible() {
	return null;
}
 
示例27
@Override
public EntityFullJid asFullJidOrThrow() {
	EntityFullJid entityFullJid = asEntityFullJidIfPossible();
	if (entityFullJid == null) throwIse("can not be converted to EntityBareJid");
	return entityFullJid;
}
 
示例28
@Override
public EntityFullJid asEntityFullJidIfPossible() {
	return null;
}
 
示例29
@Override
public boolean isParentOf(EntityFullJid fullJid) {
	return domain.equals(fullJid.getDomain());
}
 
示例30
public Invite(String reason, EntityFullJid from) {
    this(reason, from, null);
}