use of org.jivesoftware.smackx.privacy.packet.PrivacyItem in project Smack by igniterealtime.
the class PrivacyProviderTest method parsePrivacyList.
@Test
public void parsePrivacyList() throws Exception {
// @formatter:off
final String xmlPrivacyList = "<iq type='result' id='getlist2' to='romeo@example.net/orchard'>" + "<query xmlns='jabber:iq:privacy'>" + "<list name='public'>" + "<item type='jid'" + "value='tybalt@example.com'" + "action='deny'" + "order='1'/>" + "<item action='allow' order='2'/>" + "</list>" + "</query>" + "</iq>";
// @formatter:on
IQ iqPrivacyList = (IQ) PacketParserUtils.parseStanza(xmlPrivacyList);
assertTrue(iqPrivacyList instanceof Privacy);
Privacy privacyList = (Privacy) iqPrivacyList;
List<PrivacyItem> pl = privacyList.getPrivacyList("public");
PrivacyItem first = pl.get(0);
assertEquals(PrivacyItem.Type.jid, first.getType());
assertEquals("tybalt@example.com", first.getValue());
assertEquals(false, first.isAllow());
assertEquals(1, first.getOrder());
PrivacyItem second = pl.get(1);
assertEquals(true, second.isAllow());
assertEquals(2, second.getOrder());
}
use of org.jivesoftware.smackx.privacy.packet.PrivacyItem in project Smack by igniterealtime.
the class PrivacyListManager method getPrivacyListItems.
/**
* 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 XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
* @throws InterruptedException
*/
private List<PrivacyItem> getPrivacyListItems(String listName) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
assert StringUtils.isNotEmpty(listName);
// 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);
}
use of org.jivesoftware.smackx.privacy.packet.PrivacyItem in project Smack by igniterealtime.
the class PrivacyProvider method parseItem.
// Parse the list complex type
private static PrivacyItem parseItem(XmlPullParser parser) throws XmlPullParserException, IOException, SmackException {
// CHECKSTYLE:ON
// Retrieves the required attributes
String actionValue = parser.getAttributeValue("", "action");
// Set the order number, this attribute is required
long order = ParserUtils.getLongAttribute(parser, "order");
// If type is not set, then it's the fall-through case
String type = parser.getAttributeValue("", "type");
/*
* According the action value it sets the allow status. The fall-through action is assumed
* to be "allow"
*/
boolean allow;
switch(actionValue) {
case "allow":
allow = true;
break;
case "deny":
allow = false;
break;
default:
throw new SmackException("Unkown action value '" + actionValue + "'");
}
PrivacyItem item;
if (type != null) {
// If the type is not null, then we are dealing with a standard privacy item
String value = parser.getAttributeValue("", "value");
item = new PrivacyItem(PrivacyItem.Type.valueOf(type), value, allow, order);
} else {
// If the type is null, then we are dealing with the fall-through privacy item.
item = new PrivacyItem(allow, order);
}
parseItemChildElements(parser, item);
return item;
// CHECKSTYLE:OFF
}
use of org.jivesoftware.smackx.privacy.packet.PrivacyItem in project Smack by igniterealtime.
the class PrivacyListManager method deletePrivacyList.
/**
* Remove a privacy list.
*
* @param listName the list that has changed its content.
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
* @throws InterruptedException
*/
public void deletePrivacyList(String listName) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
// 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);
}
use of org.jivesoftware.smackx.privacy.packet.PrivacyItem in project Smack by igniterealtime.
the class PrivacyProviderTest method parsePrivacyListWithFallThroughInclChildElements.
@Test
public void parsePrivacyListWithFallThroughInclChildElements() throws Exception {
// @formatter:off
final String xmlPrivacyList = "<iq type='result' id='getlist2' to='romeo@example.net/orchard'>" + "<query xmlns='jabber:iq:privacy'>" + "<list name='public'>" + "<item type='jid'" + "value='tybalt@example.com'" + "action='deny'" + "order='1'/>" + "<item action='allow' order='2'>" + "<message/>" + "<presence-in/>" + "</item>" + "</list>" + "</query>" + "</iq>";
// @formatter:on
IQ iqPrivacyList = (IQ) PacketParserUtils.parseStanza(xmlPrivacyList);
assertTrue(iqPrivacyList instanceof Privacy);
Privacy privacyList = (Privacy) iqPrivacyList;
List<PrivacyItem> pl = privacyList.getPrivacyList("public");
PrivacyItem first = pl.get(0);
assertEquals(PrivacyItem.Type.jid, first.getType());
assertEquals("tybalt@example.com", first.getValue());
assertEquals(false, first.isAllow());
assertEquals(1, first.getOrder());
PrivacyItem second = pl.get(1);
assertTrue(second.isAllow());
assertEquals(2, second.getOrder());
assertTrue(second.isFilterMessage());
assertTrue(second.isFilterPresenceIn());
assertFalse(second.isFilterPresenceOut());
assertFalse(second.isFilterIQ());
}
Aggregations