/** * Answer every privacy list with the allowed and blocked permissions. * * @return an array of privacy lists. * @throws XMPPException if an error occurs. */ public PrivacyList[] getPrivacyLists() throws XMPPException { Privacy privacyAnswer = this.getPrivacyWithListNames(); Set<String> names = privacyAnswer.getPrivacyListNames(); PrivacyList[] lists = new PrivacyList[names.size()]; boolean isActiveList; boolean isDefaultList; int index=0; for (String listName : names) { isActiveList = listName.equals(privacyAnswer.getActiveName()); isDefaultList = listName.equals(privacyAnswer.getDefaultName()); lists[index] = new PrivacyList(isActiveList, isDefaultList, listName, getPrivacyListItems(listName)); index = index + 1; } return lists; }
public void parseList(XmlPullParser parser, Privacy privacy) throws Exception { boolean done = false; String listName = parser.getAttributeValue("", "name"); ArrayList<PrivacyItem> items = new ArrayList<PrivacyItem>(); while (!done) { int eventType = parser.next(); if (eventType == XmlPullParser.START_TAG) { if (parser.getName().equals("item")) { items.add(parseItem(parser)); } } else if (eventType == XmlPullParser.END_TAG) { if (parser.getName().equals("list")) { done = true; } } } privacy.setPrivacyList(listName, items); }
/** * Answer every privacy list with the allowed and blocked permissions. * * @return an array of privacy lists. * @throws XMPPException * if an error occurs. */ public PrivacyList[] getPrivacyLists() throws XMPPException { Privacy privacyAnswer = this.getPrivacyWithListNames(); Set<String> names = privacyAnswer.getPrivacyListNames(); PrivacyList[] lists = new PrivacyList[names.size()]; boolean isActiveList; boolean isDefaultList; int index = 0; for (String listName : names) { isActiveList = listName.equals(privacyAnswer.getActiveName()); isDefaultList = listName.equals(privacyAnswer.getDefaultName()); lists[index] = new PrivacyList(isActiveList, isDefaultList, listName, getPrivacyListItems(listName)); index = index + 1; } return lists; }
/** * Answer every privacy list with the allowed and blocked permissions. * * @return an array of privacy lists. * @throws org.jivesoftware.smack.XMPPException if an error occurs. */ public PrivacyList[] getPrivacyLists() throws XMPPException { Privacy privacyAnswer = this.getPrivacyWithListNames(); Set<String> names = privacyAnswer.getPrivacyListNames(); PrivacyList[] lists = new PrivacyList[names.size()]; boolean isActiveList; boolean isDefaultList; int index=0; for (String listName : names) { isActiveList = listName.equals(privacyAnswer.getActiveName()); isDefaultList = listName.equals(privacyAnswer.getDefaultName()); lists[index] = new PrivacyList(isActiveList, isDefaultList, listName, getPrivacyListItems(listName)); index = index + 1; } return lists; }
public void setStatus(byte statusId) { if (!connection.isConnected()) { return; } //TODO add full visibility list control support if (statusId == XMPPEntityAdapter.INVISIBLE_STATUS_ID) { Privacy privacy1 = new Privacy(); PrivacyItem item = new PrivacyItem(null, false, 1); item.setFilterPresence_out(true); privacy1.setPrivacyList("invisible", Arrays.asList(new PrivacyItem[]{ item })); connection.sendPacket(privacy1); Privacy privacy2 = new Privacy(); privacy2.setActiveName("invisible"); privacy2.setType(Type.SET); connection.sendPacket(privacy2); } Presence presence = getService().getEntityAdapter().userStatus2XMPPPresence(statusId); connection.sendPacket(presence); }
/** * Send the {@link Privacy} packet to the server in order to know some privacy content and then * waits for the answer. * * @param requestPrivacy is the {@link Privacy} packet configured properly whose XML * will be sent to the server. * @return a new {@link Privacy} with the data received from the server. * @exception XMPPException if the request or the answer failed, it raises an exception. */ private Privacy getRequest(Privacy requestPrivacy) throws XMPPException { // The request is a get iq type requestPrivacy.setType(Privacy.Type.GET); requestPrivacy.setFrom(this.getUser()); // Filter packets looking for an answer from the server. PacketFilter responseFilter = new PacketIDFilter(requestPrivacy.getPacketID()); PacketCollector response = connection.createPacketCollector(responseFilter); // Send create & join packet. connection.sendPacket(requestPrivacy); // Wait up to a certain number of seconds for a reply. Privacy privacyAnswer = (Privacy) response.nextResult(SmackConfiguration.getPacketReplyTimeout()); // Stop queuing results response.cancel(); // Interprete the result and answer the privacy only if it is valid if (privacyAnswer == null) { throw new XMPPException("No response from server."); } else if (privacyAnswer.getError() != null) { throw new XMPPException(privacyAnswer.getError()); } return privacyAnswer; }
/** * Send the {@link Privacy} packet to the server in order to modify the server privacy and * waits for the answer. * * @param requestPrivacy is the {@link Privacy} packet configured properly whose xml will be sent * to the server. * @return a new {@link Privacy} with the data received from the server. * @exception XMPPException if the request or the answer failed, it raises an exception. */ private Packet setRequest(Privacy requestPrivacy) throws XMPPException { // The request is a get iq type requestPrivacy.setType(Privacy.Type.SET); requestPrivacy.setFrom(this.getUser()); // Filter packets looking for an answer from the server. PacketFilter responseFilter = new PacketIDFilter(requestPrivacy.getPacketID()); PacketCollector response = connection.createPacketCollector(responseFilter); // Send create & join packet. connection.sendPacket(requestPrivacy); // Wait up to a certain number of seconds for a reply. Packet privacyAnswer = response.nextResult(SmackConfiguration.getPacketReplyTimeout()); // Stop queuing results response.cancel(); // Interprete the result and answer the privacy only if it is valid if (privacyAnswer == null) { throw new XMPPException("No response from server."); } else if (privacyAnswer.getError() != null) { throw new XMPPException(privacyAnswer.getError()); } return privacyAnswer; }
/** * Answer a privacy containing the list structre without {@link PrivacyItem}. * * @return a Privacy with the list names. * @throws XMPPException if an error occurs. */ private Privacy getPrivacyWithListNames() throws XMPPException { // The request of the list is an empty privacy message Privacy request = new Privacy(); // Send the package to the server and get the answer return getRequest(request); }
/** * Answer the active privacy list. * * @return the privacy list of the active list. * @throws XMPPException if an error occurs. */ public PrivacyList getActiveList() throws XMPPException { Privacy privacyAnswer = this.getPrivacyWithListNames(); String listName = privacyAnswer.getActiveName(); boolean isDefaultAndActive = privacyAnswer.getActiveName() != null && privacyAnswer.getDefaultName() != null && privacyAnswer.getActiveName().equals( privacyAnswer.getDefaultName()); return new PrivacyList(true, isDefaultAndActive, listName, getPrivacyListItems(listName)); }
/** * Answer the default privacy list. * * @return the privacy list of the default list. * @throws XMPPException if an error occurs. */ public PrivacyList getDefaultList() throws XMPPException { Privacy privacyAnswer = this.getPrivacyWithListNames(); String listName = privacyAnswer.getDefaultName(); boolean isDefaultAndActive = privacyAnswer.getActiveName() != null && privacyAnswer.getDefaultName() != null && privacyAnswer.getActiveName().equals( privacyAnswer.getDefaultName()); return new PrivacyList(isDefaultAndActive, true, listName, getPrivacyListItems(listName)); }
/** * Answer the privacy list items under listName with the allowed and blocked permissions. * * @param listName the name of the list to get the allowed and blocked permissions. * @return a list of privacy items under the list listName. * @throws XMPPException if an error occurs. */ private List<PrivacyItem> getPrivacyListItems(String listName) throws XMPPException { // The request of the list is an privacy message with an empty list Privacy request = new Privacy(); request.setPrivacyList(listName, new ArrayList<PrivacyItem>()); // Send the package to the server and get the answer Privacy privacyAnswer = getRequest(request); return privacyAnswer.getPrivacyList(listName); }
/** * Set or change the active list to listName. * * @param listName the list name to set as the active one. * @exception XMPPException if the request or the answer failed, it raises an exception. */ public void setActiveListName(String listName) throws XMPPException { // The request of the list is an privacy message with an empty list Privacy request = new Privacy(); request.setActiveName(listName); // Send the package to the server setRequest(request); }
/** * Client declines the use of active lists. * * @throws XMPPException if an error occurs. */ public void declineActiveList() throws XMPPException { // The request of the list is an privacy message with an empty list Privacy request = new Privacy(); request.setDeclineActiveList(true); // Send the package to the server setRequest(request); }
/** * Set or change the default list to listName. * * @param listName the list name to set as the default one. * @exception XMPPException if the request or the answer failed, it raises an exception. */ public void setDefaultListName(String listName) throws XMPPException { // The request of the list is an privacy message with an empty list Privacy request = new Privacy(); request.setDefaultName(listName); // Send the package to the server setRequest(request); }
/** * Client declines the use of default lists. * * @throws XMPPException if an error occurs. */ public void declineDefaultList() throws XMPPException { // The request of the list is an privacy message with an empty list Privacy request = new Privacy(); request.setDeclineDefaultList(true); // Send the package to the server setRequest(request); }
/** * The client has edited an existing list. It updates the server content with the resulting * list of privacy items. The {@link PrivacyItem} list MUST contain all elements in the * list (not the "delta"). * * @param listName the list that has changed its content. * @param privacyItems a List with every privacy item in the list. * @throws XMPPException if an error occurs. */ public void updatePrivacyList(String listName, List<PrivacyItem> privacyItems) throws XMPPException { // Build the privacy package to add or update the new list Privacy request = new Privacy(); request.setPrivacyList(listName, privacyItems); // Send the package to the server setRequest(request); }
/** * Remove a privacy list. * * @param listName the list that has changed its content. * @throws XMPPException if an error occurs. */ public void deletePrivacyList(String listName) throws XMPPException { // The request of the list is an privacy message with an empty list Privacy request = new Privacy(); request.setPrivacyList(listName, new ArrayList<PrivacyItem>()); // Send the package to the server setRequest(request); }
public IQ parseIQ(XmlPullParser parser) throws Exception { Privacy privacy = new Privacy(); /* privacy.addExtension(PacketParserUtils.parsePacketExtension(parser .getName(), parser.getNamespace(), parser)); */ privacy.addExtension(new DefaultPacketExtension(parser.getName(), parser.getNamespace())); boolean done = false; while (!done) { int eventType = parser.next(); if (eventType == XmlPullParser.START_TAG) { if (parser.getName().equals("active")) { String activeName = parser.getAttributeValue("", "name"); if (activeName == null) { privacy.setDeclineActiveList(true); } else { privacy.setActiveName(activeName); } } else if (parser.getName().equals("default")) { String defaultName = parser.getAttributeValue("", "name"); if (defaultName == null) { privacy.setDeclineDefaultList(true); } else { privacy.setDefaultName(defaultName); } } else if (parser.getName().equals("list")) { parseList(parser, privacy); } } else if (eventType == XmlPullParser.END_TAG) { if (parser.getName().equals("query")) { done = true; } } } return privacy; }