org.jxmpp.jid.Jid Java Examples
The following examples show how to use
org.jxmpp.jid.Jid.
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: RosterManager.java From mangosta-android with Apache License 2.0 | 6 votes |
public Presence.Type getStatusFromContact(String name) { try { HashMap<Jid, Presence.Type> buddies = getContacts(); for (Map.Entry<Jid, Presence.Type> pair : buddies.entrySet()) { if (XMPPUtils.fromJIDToUserName(pair.getKey().toString()).equals(name)) { return pair.getValue(); } } } catch (Exception e) { e.printStackTrace(); } return Presence.Type.unavailable; }
Example #2
Source File: BlockingService.java From xyTalk-pc with GNU Affero General Public License v3.0 | 6 votes |
public BlockingService() { //初始化实例Blocking Command Manager BlockingCommandManager blockingCommandManager = BlockingCommandManager.getInstanceFor(Launcher.connection); //检查是否有阻止服务支持 try { boolean isSupported = blockingCommandManager.isSupportedByServer(); //获取block list List<Jid> blockList = blockingCommandManager.getBlockList(); } catch (NoResponseException | XMPPErrorException | NotConnectedException | InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } //阻止一个人 //blockingCommandManager.blockContact(jid); //解锁Unblock //blockingCommandManager.unblockContact(jid); //全部解锁 //blockingCommandManager.unblockAll(); }
Example #3
Source File: MUCLightInfoIQProvider.java From Smack with Apache License 2.0 | 6 votes |
private static HashMap<Jid, MUCLightAffiliation> iterateOccupants(XmlPullParser parser) throws XmlPullParserException, IOException { HashMap<Jid, MUCLightAffiliation> occupants = new HashMap<>(); int depth = parser.getDepth(); outerloop: while (true) { XmlPullParser.Event eventType = parser.next(); if (eventType == XmlPullParser.Event.START_ELEMENT) { if (parser.getName().equals("user")) { MUCLightAffiliation affiliation = MUCLightAffiliation .fromString(parser.getAttributeValue("", "affiliation")); occupants.put(JidCreate.from(parser.nextText()), affiliation); } } else if (eventType == XmlPullParser.Event.END_ELEMENT) { if (parser.getDepth() == depth) { break outerloop; } } } return occupants; }
Example #4
Source File: MUCLightChangeAffiliationsIQTest.java From Smack with Apache License 2.0 | 6 votes |
@Test public void checkChangeAffiliationsMUCLightStanza() throws Exception { HashMap<Jid, MUCLightAffiliation> affiliations = new HashMap<>(); affiliations.put(JidCreate.from("[email protected]"), MUCLightAffiliation.owner); affiliations.put(JidCreate.from("[email protected]"), MUCLightAffiliation.member); affiliations.put(JidCreate.from("[email protected]"), MUCLightAffiliation.none); MUCLightChangeAffiliationsIQ mucLightChangeAffiliationsIQ = new MUCLightChangeAffiliationsIQ( JidCreate.from("[email protected]"), affiliations); mucLightChangeAffiliationsIQ.setStanzaId("member1"); assertEquals(mucLightChangeAffiliationsIQ.getTo(), "[email protected]"); assertEquals(mucLightChangeAffiliationsIQ.getType(), IQ.Type.set); HashMap<Jid, MUCLightAffiliation> iqAffiliations = mucLightChangeAffiliationsIQ.getAffiliations(); assertEquals(iqAffiliations.get(JidCreate.from("[email protected]")), MUCLightAffiliation.member); assertEquals(iqAffiliations.get(JidCreate.from("[email protected]")), MUCLightAffiliation.owner); assertEquals(iqAffiliations.get(JidCreate.from("[email protected]")), MUCLightAffiliation.none); }
Example #5
Source File: InvitationManager.java From Spark with Apache License 2.0 | 6 votes |
/** * Invite or transfer a queue. * * @param chatRoom the <code>ChatRoom</code> to invite or transfer. * @param sessionID the sessionID of this Fastpath session. * @param jid the jid of the room. * @param messageText the message to send to the user. * @param transfer true if this is a transfer. */ public static void transferOrInviteToWorkgroup(ChatRoom chatRoom, String workgroup, String sessionID, final Jid jid, String messageText, final boolean transfer) { String msg = messageText != null ? StringUtils.escapeForXml(messageText).toString() : FpRes.getString("message.please.join.me.in.conference"); try { if (!transfer) { // TODO : CHECK FASHPATH FastpathPlugin.getAgentSession().sendRoomInvitation(RoomInvitation.Type.workgroup, jid, sessionID, msg); } else { FastpathPlugin.getAgentSession().sendRoomTransfer(RoomTransfer.Type.workgroup, jid.toString(), sessionID, msg); } } catch (XMPPException | SmackException | InterruptedException e) { Log.error(e); } String username = SparkManager.getUserManager().getUserNicknameFromJID(jid.asBareJid()); String notification = FpRes.getString("message.user.has.been.invited", username); if (transfer) { notification = FpRes.getString("message.waiting.for.user", username); } chatRoom.getTranscriptWindow().insertNotificationMessage(notification, ChatManager.NOTIFICATION_COLOR); }
Example #6
Source File: MainMenuActivity.java From mangosta-android with Apache License 2.0 | 6 votes |
private void manageCallFromRosterRequestNotification() { Bundle bundle = getIntent().getExtras(); if (bundle != null) { boolean newRosterRequest = bundle.getBoolean(NEW_ROSTER_REQUEST, false); if (newRosterRequest) { try { String sender = bundle.getString(NEW_ROSTER_REQUEST_SENDER); Jid jid = JidCreate.from(sender); RosterNotifications.cancelRosterRequestNotification(this, sender); answerSubscriptionRequest(jid); } catch (Exception e) { e.printStackTrace(); } } } }
Example #7
Source File: XmppConnection.java From Zom-Android-XMPP with GNU General Public License v3.0 | 6 votes |
private void handleSubscribeRequest (Jid jid) throws ImException, RemoteException { Contact contact = mContactListManager.getContact(jid.asBareJid().toString()); if (contact == null) { XmppAddress xAddr = new XmppAddress(jid.toString()); contact = new Contact(xAddr, xAddr.getUser(), Imps.Contacts.TYPE_NORMAL); } if (contact.getSubscriptionType() == Imps.Contacts.SUBSCRIPTION_TYPE_BOTH || contact.getSubscriptionType() == Imps.Contacts.SUBSCRIPTION_TYPE_TO) { mContactListManager.approveSubscriptionRequest(contact); } else { ContactList cList = getContactListManager().getDefaultContactList(); contact.setSubscriptionStatus(Imps.Contacts.SUBSCRIPTION_STATUS_SUBSCRIBE_PENDING); contact.setSubscriptionType(Imps.Contacts.SUBSCRIPTION_TYPE_FROM); mContactListManager.doAddContactToListAsync(contact, cList, false); mContactListManager.getSubscriptionRequestListener().onSubScriptionRequest(contact, mProviderId, mAccountId); } ChatSession session = findOrCreateSession(jid.toString(), false, true); }
Example #8
Source File: ParserUtils.java From Smack with Apache License 2.0 | 6 votes |
public static EntityJid getEntityJidAttribute(XmlPullParser parser, String name) throws XmppStringprepException { final String jidString = parser.getAttributeValue("", name); if (jidString == null) { return null; } Jid jid = JidCreate.from(jidString); if (!jid.hasLocalpart()) return null; EntityFullJid fullJid = jid.asEntityFullJidIfPossible(); if (fullJid != null) { return fullJid; } EntityBareJid bareJid = jid.asEntityBareJidIfPossible(); return bareJid; }
Example #9
Source File: TranscriptsProvider.java From Smack with Apache License 2.0 | 6 votes |
@Override public Transcripts parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException { Jid userID = ParserUtils.getJidAttribute(parser, "userID"); List<Transcripts.TranscriptSummary> summaries = new ArrayList<>(); boolean done = false; while (!done) { XmlPullParser.Event eventType = parser.next(); if (eventType == XmlPullParser.Event.START_ELEMENT) { if (parser.getName().equals("transcript")) { summaries.add(parseSummary(parser)); } } else if (eventType == XmlPullParser.Event.END_ELEMENT) { if (parser.getName().equals("transcripts")) { done = true; } } } return new Transcripts(userID, summaries); }
Example #10
Source File: TransportUtils.java From Spark with Apache License 2.0 | 6 votes |
/** * Checks if the user is registered with a gateway. * * @param con the XMPPConnection. * @param transport the transport. * @return true if the user is registered with the transport. */ public static boolean isRegistered(XMPPConnection con, Transport transport) { if (!con.isConnected()) { return false; } ServiceDiscoveryManager discoveryManager = ServiceDiscoveryManager.getInstanceFor(con); try { Jid jid = JidCreate.from(transport.getXMPPServiceDomain()); DiscoverInfo info = discoveryManager.discoverInfo(jid); return info.containsFeature("jabber:iq:registered"); } catch (XMPPException | SmackException | XmppStringprepException | InterruptedException e) { Log.error(e); } return false; }
Example #11
Source File: DnsOverXmppManager.java From Smack with Apache License 2.0 | 5 votes |
public DnsMessage query(Jid jid, Question question) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { DnsMessage queryMessage = DnsMessage.builder() .addQuestion(question) .setId(RandomUtil.nextSecureRandomInt()) .setRecursionDesired(true) .build(); return query(jid, queryMessage); }
Example #12
Source File: MamPrefIQProviderTest.java From Smack with Apache License 2.0 | 5 votes |
@Test public void checkMamPrefResult() throws Exception { IQ iq = PacketParserUtils.parseStanza(exampleMamPrefsResultIQ); MamPrefsIQ mamPrefsIQ = (MamPrefsIQ) iq; List<Jid> alwaysJids = mamPrefsIQ.getAlwaysJids(); List<Jid> neverJids = mamPrefsIQ.getNeverJids(); assertEquals(alwaysJids.size(), 1); assertEquals(neverJids.size(), 2); assertEquals(alwaysJids.get(0).toString(), "[email protected]"); assertEquals(neverJids.get(1).toString(), "[email protected]"); }
Example #13
Source File: XMPPSession.java From mangosta-android with Apache License 2.0 | 5 votes |
private boolean checkIfMyIsAffiliationNone(Message message) { if (hasAffiliationsChangeExtension(message)) { MUCLightElements.AffiliationsChangeExtension affiliationsChangeExtension = MUCLightElements.AffiliationsChangeExtension.from(message); try { Jid jid = JidCreate.from(Preferences.getInstance().getUserXMPPJid()); MUCLightAffiliation affiliation = affiliationsChangeExtension.getAffiliations().get(jid.asEntityJidIfPossible()); return affiliation == MUCLightAffiliation.none; } catch (XmppStringprepException e) { e.printStackTrace(); } } return false; }
Example #14
Source File: OfferConfirmation.java From Smack with Apache License 2.0 | 5 votes |
NotifyServicePacket(Jid workgroup, String roomName) { super("offer-confirmation", "http://jabber.org/protocol/workgroup"); this.setTo(workgroup); this.setType(IQ.Type.result); this.roomName = roomName; }
Example #15
Source File: IoTDiscoveryManager.java From Smack with Apache License 2.0 | 5 votes |
public boolean isRegistry(BareJid jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { Objects.requireNonNull(jid, "JID argument must not be null"); // At some point 'usedRegistries' will also contain the registry returned by findRegistry(), but since this is // not the case from the beginning, we perform findRegistry().equals(jid) too. Jid registry = findRegistry(); if (jid.equals(registry)) { return true; } if (usedRegistries.contains(jid)) { return true; } return false; }
Example #16
Source File: JidCreate.java From jxmpp with Apache License 2.0 | 5 votes |
/** * Get a {@link Jid} from the given String. * * @param jidString the input String. * @param context the JXMPP context. * @return the Jid represented by the input String. * @throws XmppStringprepException if an error occurs. * @see #from(CharSequence) */ public static Jid from(String jidString, JxmppContext context) throws XmppStringprepException { String localpart = XmppStringUtils.parseLocalpart(jidString); String domainpart = XmppStringUtils.parseDomain(jidString); String resource = XmppStringUtils.parseResource(jidString); try { return from(localpart, domainpart, resource, context); } catch (XmppStringprepException e) { throw new XmppStringprepException(jidString, e); } }
Example #17
Source File: MessageEventManager.java From Smack with Apache License 2.0 | 5 votes |
/** * Sends the notification that the receiver of the message is composing a reply. * * @param to the recipient of the notification. * @param packetID the id of the message to send. * @throws NotConnectedException if the XMPP connection is not connected. * @throws InterruptedException if the calling thread was interrupted. */ public void sendComposingNotification(Jid to, String packetID) throws NotConnectedException, InterruptedException { // Create a MessageEvent Package and add it to the message MessageEvent messageEvent = new MessageEvent(); messageEvent.setComposing(true); messageEvent.setStanzaId(packetID); XMPPConnection connection = connection(); Message msg = connection.getStanzaFactory().buildMessageStanza() .to(to) .addExtension(messageEvent) .build(); // Send the packet connection.sendStanza(msg); }
Example #18
Source File: ServiceDiscoveryManager.java From Smack with Apache License 2.0 | 5 votes |
public boolean supportsFeatures(Jid jid, Collection<? extends CharSequence> features) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { DiscoverInfo result = discoverInfo(jid); for (CharSequence feature : features) { if (!result.containsFeature(feature)) { return false; } } return true; }
Example #19
Source File: AgentSession.java From Smack with Apache License 2.0 | 5 votes |
private void fireInvitationEvent(Jid groupChatJID, String sessionID, String body, Jid from, Map<String, List<String>> metaData) { WorkgroupInvitation invitation = new WorkgroupInvitation(connection.getUser(), groupChatJID, workgroupJID, sessionID, body, from, metaData); synchronized (invitationListeners) { for (WorkgroupInvitationListener listener : invitationListeners) { listener.invitationReceived(invitation); } } }
Example #20
Source File: Roster.java From Smack with Apache License 2.0 | 5 votes |
/** * Check if the given JID is subscribed to the user's presence. * <p> * If the JID is subscribed to the user's presence then it is allowed to see the presence and * will get notified about presence changes. Also returns true, if the JID is the service * name of the XMPP connection (the "XMPP domain"), i.e. the XMPP service is treated like * having an implicit subscription to the users presence. * </p> * Note that if the roster is not loaded, then this method will always return false. * * @param jid TODO javadoc me please * @return true if the given JID is allowed to see the users presence. * @since 4.1 */ public boolean isSubscribedToMyPresence(Jid jid) { if (jid == null) { return false; } BareJid bareJid = jid.asBareJid(); if (connection().getXMPPServiceDomain().equals(bareJid)) { return true; } RosterEntry entry = getEntry(bareJid); if (entry == null) { return false; } return entry.canSeeMyPresence(); }
Example #21
Source File: IoTRemoveProvider.java From Smack with Apache License 2.0 | 5 votes |
@Override public IoTRemove parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws IOException { Jid jid = ParserUtils.getJidAttribute(parser); if (jid.hasResource()) { // TODO: Should be SmackParseException. throw new IOException("JID must be without resourcepart"); } BareJid bareJid = jid.asBareJid(); NodeInfo nodeInfo = NodeInfoParser.parse(parser); return new IoTRemove(bareJid, nodeInfo); }
Example #22
Source File: ClientUtils.java From desktopclient-java with GNU General Public License v3.0 | 5 votes |
private static MessageIDs create(Message m, Jid jid, String receiptID) { return new MessageIDs( JID.fromSmack(jid), !receiptID.isEmpty() ? receiptID : StringUtils.defaultString(m.getStanzaId()), StringUtils.defaultString(m.getThread())); }
Example #23
Source File: ChatService.java From xyTalk-pc with GNU Affero General Public License v3.0 | 5 votes |
public static void recivePacket(org.jivesoftware.smack.packet.Message message) { // 消息抵达后,客户端处在4种状况 // 1、当前聊天者即为新消息发送者 // 2、当前聊天者不为新消息发送者,联系人列表中存在消息发送者 // 3、当前聊天者不为新消息发送者,联系人列表中不存在新消息发送者 // 4、用户离线,但上线后同样在1-3之间处理 Jid fromJID = message.getFrom(); String body = message.getBody(); String barejid = fromJID.asBareJid().toString(); if (barejid != null && body != null) { if (Launcher.currRoomId.equals(barejid)) { // 1、当前聊天者即为新消息发送者 updateChatPanel(message); } else { if (Launcher.roomService.exist(barejid)) { // 2、联系人列表中存在消息发送者,更新未读信息 updateRoom(message); } else { // 3、联系人中不存在新消息发送者,则新建一个联系人 createNewRoom(message); } dbMessagePersistence(message); } } }
Example #24
Source File: KonRosterListener.java From desktopclient-java with GNU General Public License v3.0 | 5 votes |
@Override public void entriesDeleted(Collection<Jid> addresses) { for (Jid jid: addresses) { LOGGER.info("address: "+jid); mHandler.onEntryDeleted(JID.fromSmack(jid)); } }
Example #25
Source File: RosterExchangeManager.java From Smack with Apache License 2.0 | 5 votes |
/** * Sends a roster entry to userID. * * @param rosterEntry the roster entry to send * @param targetUserID the user that will receive the roster entries * @throws NotConnectedException if the XMPP connection is not connected. * @throws InterruptedException if the calling thread was interrupted. */ public void send(RosterEntry rosterEntry, Jid targetUserID) throws NotConnectedException, InterruptedException { XMPPConnection connection = weakRefConnection.get(); // Create a new message to send the roster MessageBuilder messageBuilder = connection.getStanzaFactory().buildMessageStanza().to(targetUserID); // Create a RosterExchange Package and add it to the message RosterExchange rosterExchange = new RosterExchange(); rosterExchange.addRosterEntry(rosterEntry); messageBuilder.addExtension(rosterExchange); // Send the message that contains the roster connection.sendStanza(messageBuilder.build()); }
Example #26
Source File: UnblockContactsIQProvider.java From Smack with Apache License 2.0 | 5 votes |
@Override public UnblockContactsIQ parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException { List<Jid> jids = null; outerloop: while (true) { XmlPullParser.Event eventType = parser.next(); switch (eventType) { case START_ELEMENT: if (parser.getName().equals("item")) { if (jids == null) { jids = new ArrayList<>(); } jids.add(JidCreate.from(parser.getAttributeValue("", "jid"))); } break; case END_ELEMENT: if (parser.getDepth() == initialDepth) { break outerloop; } break; default: // Catch all for incomplete switch (MissingCasesInEnumSwitch) statement. break; } } return new UnblockContactsIQ(jids); }
Example #27
Source File: MultipleAddresses.java From Smack with Apache License 2.0 | 5 votes |
/** * Adds a new address to which the stanza is going to be sent or was sent. * * @param type on of the static type (BCC, CC, NO_REPLY, REPLY_ROOM, etc.) * @param jid the JID address of the recipient. * @param node used to specify a sub-addressable unit at a particular JID, corresponding to * a Service Discovery node. * @param desc used to specify human-readable information for this address. * @param delivered true when the stanza was already delivered to this address. * @param uri used to specify an external system address, such as a sip:, sips:, or im: URI. */ public void addAddress(Type type, Jid jid, String node, String desc, boolean delivered, String uri) { // Create a new address with the specified configuration Address address = new Address(type); address.setJid(jid); address.setNode(node); address.setDescription(desc); address.setDelivered(delivered); address.setUri(uri); // Add the new address to the list of multiple recipients addresses.add(address); }
Example #28
Source File: OmemoService.java From Smack with Apache License 2.0 | 5 votes |
/** * Return the joined MUC with EntityBareJid jid, or null if its not a room and/or not joined. * * @param connection xmpp connection * @param jid jid (presumably) of the MUC * @return MultiUserChat or null if not a MUC. */ private static MultiUserChat getMuc(XMPPConnection connection, Jid jid) { EntityBareJid ebj = jid.asEntityBareJidIfPossible(); if (ebj == null) { return null; } MultiUserChatManager mucm = MultiUserChatManager.getInstanceFor(connection); Set<EntityBareJid> joinedRooms = mucm.getJoinedRooms(); if (joinedRooms.contains(ebj)) { return mucm.getMultiUserChat(ebj); } return null; }
Example #29
Source File: JID.java From desktopclient-java with GNU General Public License v3.0 | 5 votes |
public Jid toSmack() { try { return JidCreate.from(this.string()); } catch (XmppStringprepException ex) { LOGGER.log(Level.WARNING, "could not convert to smack", ex); throw new RuntimeException("Not even a simple Jid?"); } }
Example #30
Source File: Roster.java From Smack with Apache License 2.0 | 5 votes |
/** * Check if the XMPP entity this roster belongs to is subscribed to the presence of the given JID. * * @param jid the jid to check. * @return <code>true</code> if we are subscribed to the presence of the given jid. * @since 4.2 */ public boolean iAmSubscribedTo(Jid jid) { if (jid == null) { return false; } BareJid bareJid = jid.asBareJid(); RosterEntry entry = getEntry(bareJid); if (entry == null) { return false; } return entry.canSeeHisPresence(); }