Search in sources :

Example 1 with PrivacyItem

use of org.jivesoftware.smack.packet.PrivacyItem in project ecf by eclipse.

the class PrivacyListManager method deletePrivacyList.

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

Example 2 with PrivacyItem

use of org.jivesoftware.smack.packet.PrivacyItem in project ecf by eclipse.

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

Example 3 with PrivacyItem

use of org.jivesoftware.smack.packet.PrivacyItem in project ecf by eclipse.

the class PrivacyListManager method init.

/**
 * Initializes the packet listeners of the connection that will notify for any set privacy
 * package.
 */
private void init() {
    // Register the new instance and associate it with the connection
    instances.put(connection, this);
    // Add a listener to the connection that removes the registered instance when
    // the connection is closed
    connection.addConnectionListener(new ConnectionListener() {

        public void connectionClosed() {
            // Unregister this instance since the connection has been closed
            instances.remove(connection);
        }

        public void connectionClosedOnError(Exception e) {
        // ignore
        }

        public void reconnectionFailed(Exception e) {
        // ignore
        }

        public void reconnectingIn(int seconds) {
        // ignore
        }

        public void reconnectionSuccessful() {
        // ignore
        }
    });
    connection.addPacketListener(new PacketListener() {

        public void processPacket(Packet packet) {
            if (packet == null || packet.getError() != null) {
                return;
            }
            // The packet is correct.
            Privacy privacy = (Privacy) packet;
            // Notifies the event to the listeners.
            synchronized (listeners) {
                for (PrivacyListListener listener : listeners) {
                    // Notifies the created or updated privacy lists
                    for (Map.Entry<String, List<PrivacyItem>> entry : privacy.getItemLists().entrySet()) {
                        String listName = entry.getKey();
                        List<PrivacyItem> items = entry.getValue();
                        if (items.isEmpty()) {
                            listener.updatedPrivacyList(listName);
                        } else {
                            listener.setPrivacyList(listName, items);
                        }
                    }
                }
            }
            // Send a result package acknowledging the reception of a privacy package.
            // Prepare the IQ packet to send
            IQ iq = new IQ() {

                public String getChildElementXML() {
                    return "";
                }
            };
            iq.setType(IQ.Type.RESULT);
            iq.setFrom(packet.getFrom());
            iq.setPacketID(packet.getPacketID());
            // Send create & join packet.
            connection.sendPacket(iq);
        }
    }, packetFilter);
}
Also used : Packet(org.jivesoftware.smack.packet.Packet) Privacy(org.jivesoftware.smack.packet.Privacy) IQ(org.jivesoftware.smack.packet.IQ) PrivacyItem(org.jivesoftware.smack.packet.PrivacyItem)

Example 4 with PrivacyItem

use of org.jivesoftware.smack.packet.PrivacyItem in project ecf by eclipse.

the class PrivacyProvider method parseItem.

// Parse the list complex type
public PrivacyItem parseItem(XmlPullParser parser) throws Exception {
    boolean done = false;
    // Retrieves the required attributes
    String actionValue = parser.getAttributeValue("", "action");
    String orderValue = parser.getAttributeValue("", "order");
    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 = true;
    if ("allow".equalsIgnoreCase(actionValue)) {
        allow = true;
    } else if ("deny".equalsIgnoreCase(actionValue)) {
        allow = false;
    }
    // Set the order number
    int order = Integer.parseInt(orderValue);
    // Create the privacy item
    PrivacyItem item = new PrivacyItem(type, allow, order);
    item.setValue(parser.getAttributeValue("", "value"));
    while (!done) {
        int eventType = parser.next();
        if (eventType == XmlPullParser.START_TAG) {
            if (parser.getName().equals("iq")) {
                item.setFilterIQ(true);
            }
            if (parser.getName().equals("message")) {
                item.setFilterMessage(true);
            }
            if (parser.getName().equals("presence-in")) {
                item.setFilterPresence_in(true);
            }
            if (parser.getName().equals("presence-out")) {
                item.setFilterPresence_out(true);
            }
        } else if (eventType == XmlPullParser.END_TAG) {
            if (parser.getName().equals("item")) {
                done = true;
            }
        }
    }
    return item;
}
Also used : PrivacyItem(org.jivesoftware.smack.packet.PrivacyItem)

Aggregations

PrivacyItem (org.jivesoftware.smack.packet.PrivacyItem)4 Privacy (org.jivesoftware.smack.packet.Privacy)3 IQ (org.jivesoftware.smack.packet.IQ)1 Packet (org.jivesoftware.smack.packet.Packet)1