Search in sources :

Example 1 with PrivacyItem

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());
}
Also used : Privacy(org.jivesoftware.smackx.privacy.packet.Privacy) IQ(org.jivesoftware.smack.packet.IQ) PrivacyItem(org.jivesoftware.smackx.privacy.packet.PrivacyItem) Test(org.junit.Test)

Example 2 with PrivacyItem

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);
}
Also used : Privacy(org.jivesoftware.smackx.privacy.packet.Privacy) PrivacyItem(org.jivesoftware.smackx.privacy.packet.PrivacyItem)

Example 3 with PrivacyItem

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
}
Also used : SmackException(org.jivesoftware.smack.SmackException) PrivacyItem(org.jivesoftware.smackx.privacy.packet.PrivacyItem)

Example 4 with PrivacyItem

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);
}
Also used : Privacy(org.jivesoftware.smackx.privacy.packet.Privacy) PrivacyItem(org.jivesoftware.smackx.privacy.packet.PrivacyItem)

Example 5 with PrivacyItem

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());
}
Also used : Privacy(org.jivesoftware.smackx.privacy.packet.Privacy) IQ(org.jivesoftware.smack.packet.IQ) PrivacyItem(org.jivesoftware.smackx.privacy.packet.PrivacyItem) Test(org.junit.Test)

Aggregations

PrivacyItem (org.jivesoftware.smackx.privacy.packet.PrivacyItem)5 Privacy (org.jivesoftware.smackx.privacy.packet.Privacy)4 IQ (org.jivesoftware.smack.packet.IQ)2 Test (org.junit.Test)2 SmackException (org.jivesoftware.smack.SmackException)1