org.jxmpp.jid.EntityBareJid Java Examples
The following examples show how to use
org.jxmpp.jid.EntityBareJid.
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: ChatService.java From xyTalk-pc with GNU Affero General Public License v3.0 | 6 votes |
public static void sendMessage(String roomId, String content,ExtensionElement ext) { EntityBareJid jid = null; try { jid = JidCreate.entityBareFrom(roomId); } catch (XmppStringprepException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } Chat chat = ChatManager.getInstanceFor(Launcher.connection).chatWith(jid); org.jivesoftware.smack.packet.Message message = new org.jivesoftware.smack.packet.Message(); message.setType(Type.chat); message.addExtension(ext); message.setBody(content); try { chat.send(message); DebugUtil.debug("chat.sendMessage::" + message.toString()); } catch (NotConnectedException | InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
Example #2
Source File: UserSearchResults.java From Spark with Apache License 2.0 | 6 votes |
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: AgentRoster.java From Smack with Apache License 2.0 | 6 votes |
/** * Constructs a new AgentRoster. * * @param connection an XMPP connection. * @throws NotConnectedException if the XMPP connection is not connected. * @throws InterruptedException if the calling thread was interrupted. */ AgentRoster(XMPPConnection connection, EntityBareJid workgroupJID) throws NotConnectedException, InterruptedException { this.connection = connection; this.workgroupJID = workgroupJID; // Listen for any roster packets. StanzaFilter rosterFilter = new StanzaTypeFilter(AgentStatusRequest.class); connection.addAsyncStanzaListener(new AgentStatusListener(), rosterFilter); // Listen for any presence packets. connection.addAsyncStanzaListener(new PresencePacketListener(), new StanzaTypeFilter(Presence.class)); // Send request for roster. AgentStatusRequest request = new AgentStatusRequest(); request.setTo(workgroupJID); connection.sendStanza(request); }
Example #4
Source File: ChatContainer.java From Spark with Apache License 2.0 | 6 votes |
/** * Returns a ChatRoom by name. * * @param roomAddress the name of the ChatRoom. * @return the ChatRoom * @throws ChatRoomNotFoundException if the room was not found. */ public ChatRoom getChatRoom(EntityBareJid roomAddress) throws ChatRoomNotFoundException { for (int i = 0; i < getTabCount(); i++) { ChatRoom room = null; try { room = getChatRoom(i); } catch (ChatRoomNotFoundException e1) { // Ignore } if (room != null && room.getRoomJid().equals(roomAddress) && room.isActive()) { return room; } } throw new ChatRoomNotFoundException(roomAddress + " not found."); }
Example #5
Source File: AgentRoster.java From Smack with Apache License 2.0 | 6 votes |
/** * Fires event to listeners. */ private void fireEvent(int eventType, Object eventObject) { AgentRosterListener[] listeners; synchronized (this.listeners) { listeners = new AgentRosterListener[this.listeners.size()]; this.listeners.toArray(listeners); } for (int i = 0; i < listeners.length; i++) { switch (eventType) { case EVENT_AGENT_ADDED: listeners[i].agentAdded((EntityBareJid) eventObject); break; case EVENT_AGENT_REMOVED: listeners[i].agentRemoved((EntityBareJid) eventObject); break; case EVENT_PRESENCE_CHANGED: listeners[i].presenceChanged((Presence) eventObject); break; } } }
Example #6
Source File: BookmarkManager.java From Smack with Apache License 2.0 | 6 votes |
/** * Removes a conference from the bookmarks. * * @param jid the jid of the conference to be removed. * @throws XMPPErrorException thrown when there is a problem with the connection attempting to * retrieve the bookmarks or persist the bookmarks. * @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 IllegalArgumentException thrown when the conference being removed is a shared * conference */ public void removeBookmarkedConference(EntityBareJid jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { retrieveBookmarks(); Iterator<BookmarkedConference> it = bookmarks.getBookmarkedConferences().iterator(); while (it.hasNext()) { BookmarkedConference conference = it.next(); if (conference.getJid().equals(jid)) { if (conference.isShared()) { throw new IllegalArgumentException("Conference is shared and can't be removed"); } it.remove(); privateDataManager.setPrivateData(bookmarks); return; } } }
Example #7
Source File: AbstractJid.java From jxmpp with Apache License 2.0 | 6 votes |
@Override public final boolean isParentOf(Jid jid) { EntityFullJid fullJid = jid.asEntityFullJidIfPossible(); if (fullJid != null) { return isParentOf(fullJid); } EntityBareJid bareJid = jid.asEntityBareJidIfPossible(); if (bareJid != null) { return isParentOf(bareJid); } DomainFullJid domainFullJid = jid.asDomainFullJidIfPossible(); if (domainFullJid != null) { return isParentOf(domainFullJid); } return isParentOf(jid.asDomainBareJid()); }
Example #8
Source File: MUCUserProvider.java From Smack with Apache License 2.0 | 6 votes |
private static MUCUser.Decline parseDecline(XmlPullParser parser) throws XmlPullParserException, IOException { String reason = null; EntityBareJid to = ParserUtils.getBareJidAttribute(parser, "to"); EntityBareJid from = ParserUtils.getBareJidAttribute(parser, "from"); outerloop: while (true) { XmlPullParser.Event eventType = parser.next(); if (eventType == XmlPullParser.Event.START_ELEMENT) { if (parser.getName().equals("reason")) { reason = parser.nextText(); } } else if (eventType == XmlPullParser.Event.END_ELEMENT) { if (parser.getName().equals("decline")) { break outerloop; } } } return new MUCUser.Decline(reason, from, to); }
Example #9
Source File: Workpane.java From Spark with Apache License 2.0 | 6 votes |
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 #10
Source File: ConferenceServices.java From Spark with Apache License 2.0 | 6 votes |
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 #11
Source File: ChatTranscripts.java From Spark with Apache License 2.0 | 6 votes |
/** * Appends the given ChatTranscript to the transcript file associated with a JID. * * @param jid the jid of the user. * @param transcript the ChatTranscript. */ public static void appendToTranscript(EntityBareJid jid, ChatTranscript transcript) { final File transcriptFile = getTranscriptFile(jid); if (!Default.getBoolean("HISTORY_DISABLED") && Enterprise.containsFeature(Enterprise.HISTORY_TRANSCRIPTS_FEATURE)) { // Write Full Transcript, appending the messages. writeToFile(transcriptFile, transcript.getMessages(), true); // Write to current history File final File currentHistoryFile = getCurrentHistoryFile(jid); ChatTranscript tempTranscript = getCurrentChatTranscript(jid); for (HistoryMessage message : transcript.getMessages()) { tempTranscript.addHistoryMessage(message); } int max = SettingsManager.getLocalPreferences().getMaxCurrentHistorySize(); writeToFile(currentHistoryFile, tempTranscript.getNumberOfEntries(max), false); } }
Example #12
Source File: MUCUserProvider.java From Smack with Apache License 2.0 | 6 votes |
private static MUCUser.Invite parseInvite(XmlPullParser parser) throws XmlPullParserException, IOException { String reason = null; EntityBareJid to = ParserUtils.getBareJidAttribute(parser, "to"); EntityJid from = ParserUtils.getEntityJidAttribute(parser, "from"); outerloop: while (true) { XmlPullParser.Event eventType = parser.next(); if (eventType == XmlPullParser.Event.START_ELEMENT) { if (parser.getName().equals("reason")) { reason = parser.nextText(); } } else if (eventType == XmlPullParser.Event.END_ELEMENT) { if (parser.getName().equals("invite")) { break outerloop; } } } return new MUCUser.Invite(reason, from, to); }
Example #13
Source File: ChatContainer.java From Spark with Apache License 2.0 | 5 votes |
/** * Handles the presence of a one to one chat room. * * @param p the presence to handle. */ private void handleRoomPresence(final Presence p) { final EntityBareJid roomname = p.getFrom().asEntityBareJidIfPossible(); ChatRoom chatRoom; try { chatRoom = getChatRoom(roomname); } catch (ChatRoomNotFoundException e1) { Log.debug("Could not locate chat room " + roomname); return; } final Resourcepart userid = p.getFrom().getResourceOrNull(); if (p.getType() == Presence.Type.unavailable) { fireUserHasLeft(chatRoom, userid); } else if (p.getType() == Presence.Type.available) { fireUserHasJoined(chatRoom, userid); } // Change tab icon if (chatRoom instanceof ChatRoomImpl) { // Notify state change. int tabLoc = indexOfComponent(chatRoom); if (tabLoc != -1) { SparkManager.getChatManager().notifySparkTabHandlers(chatRoom); } } }
Example #14
Source File: ServiceAdministrationManager.java From Smack with Apache License 2.0 | 5 votes |
public void addUser(final EntityBareJid userJid, final String password) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { RemoteCommand command = addUser(); command.execute(); FillableForm answerForm = new FillableForm(command.getForm()); answerForm.setAnswer("accountjid", userJid); answerForm.setAnswer("password", password); answerForm.setAnswer("password-verify", password); command.execute(answerForm); assert command.isCompleted(); }
Example #15
Source File: OnlineAgents.java From Spark with Apache License 2.0 | 5 votes |
@Override public void presenceChanged(Presence presence) { BareJid jid = presence.getFrom().asBareJid(); ContactItem item = contactGroup.getContactItemByJID(jid); if (item != null) { item.setPresence(presence); if (presence.getType() == Presence.Type.unavailable) { contactGroup.removeContactItem(item); } else if (presence.getType() == Presence.Type.available) { Icon icon = PresenceManager.getIconFromPresence(presence); if (icon == null) { icon = FastpathRes.getImageIcon(FastpathRes.GREEN_BALL); } item.setIcon(icon); } } else { if (presence.getType() == Presence.Type.available) { EntityBareJid agent = presence.getFrom().asEntityBareJidOrThrow(); String nickname = SparkManager.getUserManager().getUserNicknameFromJID(agent); if (nickname == null) { nickname = agent.toString(); } ContactItem contactItem = new ContactItem(nickname,nickname, presence.getFrom().asBareJid()); contactItem.setPresence(presence); contactGroup.addContactItem(contactItem); } } contactGroup.fireContactGroupUpdated(); }
Example #16
Source File: RoomCreationDialog.java From Spark with Apache License 2.0 | 5 votes |
private MultiUserChat createGroupChat(String roomName, DomainBareJid serviceName) { String roomString = roomName.replaceAll(" ", "_") + "@" + serviceName; EntityBareJid room = JidCreate.entityBareFromOrThrowUnchecked(roomString); // Create a group chat with valid information return MultiUserChatManager.getInstanceFor( SparkManager.getConnection() ).getMultiUserChat( room ); }
Example #17
Source File: ConferenceUtils.java From Spark with Apache License 2.0 | 5 votes |
/** * Joins a conference room using another thread. This allows for a smoother opening of rooms. * * @param roomName the name of the room. * @param roomJID the jid of the room. * @param password the rooms password if required. */ public static void joinConferenceOnSeperateThread(final CharSequence roomName, EntityBareJid roomJID, String password, final String inviteMessage, final Collection<EntityBareJid> invites ) { final JoinRoomSwingWorker worker = new JoinRoomSwingWorker( roomJID, password, roomName.toString() ); if ( invites != null && !invites.isEmpty() ) { final InviteSwingWorker inviteSwingWorker = new InviteSwingWorker( roomJID, new HashSet<>( invites ), inviteMessage ); worker.setFollowUp( inviteSwingWorker ); } worker.start(); }
Example #18
Source File: MucManager.java From Yahala-Messenger with MIT License | 5 votes |
@Override public void invitationReceived(XMPPConnection conn, MultiUserChat room, String inviter, String reason, String password, Message message) { final EntityBareJid roomBareJid = room.getRoom(); if (!manager.getJoinedRooms().contains(room.getRoom())) { joinRoom(roomBareJid); //List<String> usersJids = getRoomParticipants(roomBareJid.asEntityBareJidString()); //DbHelper.addRoomToDb(roomBareJid, "", null); } }
Example #19
Source File: XmppConnection.java From Zom-Android-XMPP with GNU General Public License v3.0 | 5 votes |
@Override public void grantAdminAsync(ChatGroup group, Contact contact) { String chatRoomJid = group.getAddress().getAddress(); if (mMUCs.containsKey(chatRoomJid)) { MultiUserChat muc = mMUCs.get(chatRoomJid); try { EntityBareJid contactJid = JidCreate.entityBareFrom(contact.getAddress().getAddress()); muc.grantAdmin(contactJid); } catch (Exception e) { e.printStackTrace(); } } }
Example #20
Source File: JidCreate.java From jxmpp with Apache License 2.0 | 5 votes |
/** * Get a {@link EntityBareJid} 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 EntityBareJid entityBareFromUnescapedOrNull(CharSequence cs) { try { return entityBareFromUnescaped(cs.toString()); } catch (XmppStringprepException e) { return null; } }
Example #21
Source File: AgentConversations.java From Spark with Apache License 2.0 | 5 votes |
private void calculateNumberOfChats(AgentRoster agentRoster) { int counter = 0; // TODO: CHECK FASTPATH for (EntityBareJid agent : agentRoster.getAgents()) { Presence presence = agentRoster.getPresence(agent); if (presence.isAvailable()) { AgentStatus agentStatus = (AgentStatus)presence.getExtension("agent-status", "http://jabber.org/protocol/workgroup"); if (agentStatus != null) { counter += agentStatus.getCurrentChats().size(); } } } FastpathPlugin.getUI().setTitleForComponent(FpRes.getString("message.current.chats", counter), this); }
Example #22
Source File: MultiUserChatIntegrationTest.java From Smack with Apache License 2.0 | 5 votes |
@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 #23
Source File: WorkgroupInvitationDialog.java From Spark with Apache License 2.0 | 5 votes |
/** * Returns a Collection of agents available to receive either an invitation or transfer request. * * @param roster the AgentRoster of the workgroup. * @param roomName the name of the room to check. * @return collection of available agents. */ private Collection<EntityBareJid> getAvailableAgents(AgentRoster roster, EntityBareJid roomName) { final Set<EntityBareJid> availableAgents = new HashSet<>(); final Iterator<EntityBareJid> agents = roster.getAgents().iterator(); while (agents.hasNext()) { EntityBareJid agent = agents.next(); if (PresenceManager.isAvailable(agent)) { final Iterator<String> agentsInRoom = SparkManager.getUserManager().getUserJidsInRoom(roomName, false).iterator(); boolean alreadyExists = false; while (agentsInRoom.hasNext()) { String userid = agentsInRoom.next(); if (agent.equals(userid)) { alreadyExists = true; } } if (!alreadyExists) { availableAgents.add(agent); } } } return availableAgents; }
Example #24
Source File: JidCreateTest.java From jxmpp with Apache License 2.0 | 5 votes |
@Test public void bareFromThrowTest() { final String notABareJid = "example.org/test"; try { EntityBareJid jid = JidCreate.entityBareFrom(notABareJid); // Should throw fail(jid + " should never been created"); } catch (XmppStringprepException e) { assertEquals(notABareJid, e.getCausingString()); } }
Example #25
Source File: JidCreateTest.java From jxmpp with Apache License 2.0 | 5 votes |
@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 #26
Source File: MultiUserChatIntegrationTest.java From Smack with Apache License 2.0 | 5 votes |
@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: RequestUtils.java From Spark with Apache License 2.0 | 5 votes |
/** * Returns the Unique Identifier of the user. * * @return the unique id of the user or {@code null}. */ public EntityBareJid getUserID() { if (getMetadata() == null) { return null; } final String userID = getFirstValue("userID");//NOTRANS return JidCreate.entityBareFromUnescapedOrThrowUnchecked(userID); }
Example #28
Source File: ParserUtils.java From Smack with Apache License 2.0 | 5 votes |
public static EntityBareJid getBareJidAttribute(XmlPullParser parser, String name) throws XmppStringprepException { final String jidString = parser.getAttributeValue("", name); if (jidString == null) { return null; } return JidCreate.entityBareFrom(jidString); }
Example #29
Source File: GroupChatRoom.java From Spark with Apache License 2.0 | 5 votes |
private void reconnectionSuccessful() { final EntityBareJid roomJID = chat.getRoom(); final String roomName = tabTitle; isActive = false; EventQueue.invokeLater( () -> { ConferenceUtils.joinConferenceOnSeperateThread( roomName, roomJID, password ); closeChatRoom(); } ); }
Example #30
Source File: UserTuneIntegrationTest.java From Smack with Apache License 2.0 | 5 votes |
@SmackIntegrationTest public void test() throws Exception { URI uri = new URI("http://www.yesworld.com/lyrics/Fragile.html#9"); UserTuneElement.Builder builder = UserTuneElement.getBuilder(); UserTuneElement userTuneElement1 = builder.setArtist("Yes") .setLength(686) .setRating(8) .setSource("Yessongs") .setTitle("Heart of the Sunrise") .setTrack("3") .setUri(uri) .build(); IntegrationTestRosterUtil.ensureBothAccountsAreSubscribedToEachOther(conOne, conTwo, timeout); final SimpleResultSyncPoint userTuneReceived = new SimpleResultSyncPoint(); final PepEventListener<UserTuneElement> userTuneListener = new PepEventListener<UserTuneElement>() { @Override public void onPepEvent(EntityBareJid jid, UserTuneElement userTuneElement, String id, Message message) { if (userTuneElement.equals(userTuneElement1)) { userTuneReceived.signal(); } } }; utm2.addUserTuneListener(userTuneListener); try { utm1.publishUserTune(userTuneElement1); userTuneReceived.waitForResult(timeout); } finally { utm2.removeUserTuneListener(userTuneListener); } }