Commit 19f32d8f authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

Added support for filtering vCards fields. JM-684

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@3881 b35dd754-fafc-0310-a699-88a17e54d16e
parent 8ed0c7c4
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
package org.jivesoftware.wildfire.handler; package org.jivesoftware.wildfire.handler;
import org.dom4j.Element; import org.dom4j.Element;
import org.dom4j.QName;
import org.jivesoftware.util.Log; import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.IQHandlerInfo; import org.jivesoftware.wildfire.IQHandlerInfo;
import org.jivesoftware.wildfire.PacketException; import org.jivesoftware.wildfire.PacketException;
...@@ -25,6 +26,8 @@ import org.xmpp.packet.IQ; ...@@ -25,6 +26,8 @@ import org.xmpp.packet.IQ;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
import org.xmpp.packet.PacketError; import org.xmpp.packet.PacketError;
import java.util.Iterator;
/** /**
* Implements the TYPE_IQ vcard-temp protocol. Clients * Implements the TYPE_IQ vcard-temp protocol. Clients
* use this protocol to set and retrieve the vCard information * use this protocol to set and retrieve the vCard information
...@@ -103,6 +106,22 @@ public class IQvCardHandler extends IQHandler { ...@@ -103,6 +106,22 @@ public class IQvCardHandler extends IQHandler {
VCardManager vManager = VCardManager.getInstance(); VCardManager vManager = VCardManager.getInstance();
Element userVCard = vManager.getVCard(recipient.getNode()); Element userVCard = vManager.getVCard(recipient.getNode());
if (userVCard != null) { if (userVCard != null) {
// Check if the requester wants to ignore some vCard's fields
Element filter = packet.getChildElement()
.element(QName.get("filter", "vcard-temp-filter"));
if (filter != null) {
// Create a copy so we don't modify the original vCard
userVCard = userVCard.createCopy();
// Ignore fields requested by the user
for (Iterator toFilter = filter.elementIterator(); toFilter.hasNext();)
{
Element field = (Element) toFilter.next();
Element fieldToRemove = userVCard.element(field.getName());
if (fieldToRemove != null) {
fieldToRemove.detach();
}
}
}
result.setChildElement(userVCard); result.setChildElement(userVCard);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment