use of org.jivesoftware.openfire.vcard.VCardManager in project Openfire by igniterealtime.
the class IQvCardHandler method handleIQ.
@Override
public IQ handleIQ(IQ packet) throws UnauthorizedException, PacketException {
IQ result = IQ.createResultIQ(packet);
IQ.Type type = packet.getType();
if (type.equals(IQ.Type.set)) {
try {
User user = userManager.getUser(packet.getFrom().getNode());
Element vcard = packet.getChildElement();
if (vcard != null) {
VCardManager.getInstance().setVCard(user.getUsername(), vcard);
}
} catch (UserNotFoundException e) {
result = IQ.createResultIQ(packet);
result.setChildElement(packet.getChildElement().createCopy());
result.setError(PacketError.Condition.item_not_found);
} catch (Exception e) {
Log.error(e.getMessage(), e);
result.setError(PacketError.Condition.internal_server_error);
}
} else if (type.equals(IQ.Type.get)) {
JID recipient = packet.getTo();
// If no TO was specified then get the vCard of the sender of the packet
if (recipient == null) {
recipient = packet.getFrom();
}
// By default return an empty vCard
result.setChildElement("vCard", "vcard-temp");
// Only try to get the vCard values of non-anonymous users
if (recipient != null) {
if (recipient.getNode() != null && server.isLocal(recipient)) {
VCardManager vManager = VCardManager.getInstance();
Element userVCard = vManager.getVCard(recipient.getNode());
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);
}
} else {
result = IQ.createResultIQ(packet);
result.setChildElement(packet.getChildElement().createCopy());
result.setError(PacketError.Condition.item_not_found);
}
} else {
result = IQ.createResultIQ(packet);
result.setChildElement(packet.getChildElement().createCopy());
result.setError(PacketError.Condition.item_not_found);
}
} else {
result.setChildElement(packet.getChildElement().createCopy());
result.setError(PacketError.Condition.not_acceptable);
}
return result;
}
use of org.jivesoftware.openfire.vcard.VCardManager in project Openfire by igniterealtime.
the class JustMarriedController method copyVCard.
/**
* Copy v card.
*
* @param currentUserName
* the current user name
* @param newUserName
* the new user name
* @throws ServiceException
* the service exception
*/
private static void copyVCard(String currentUserName, String newUserName) throws ServiceException {
VCardManager vcardManager = VCardManager.getInstance();
Element vcard = vcardManager.getVCard(currentUserName);
if (vcard != null) {
try {
vcardManager.setVCard(newUserName, vcard);
} catch (Exception e) {
throw new ServiceException("Could not copy vcard to new user", newUserName, ExceptionType.ILLEGAL_ARGUMENT_EXCEPTION, Response.Status.BAD_REQUEST, e);
}
}
}
use of org.jivesoftware.openfire.vcard.VCardManager in project Openfire by igniterealtime.
the class JustMarriedPlugin method copyVCard.
private static void copyVCard(String currentUserName, String newUserName) {
VCardManager vcardManager = VCardManager.getInstance();
Element vcard = vcardManager.getVCard(currentUserName);
if (vcard != null) {
try {
vcardManager.setVCard(newUserName, vcard);
} catch (Exception e) {
Log.error("Could not copy vcard to " + newUserName, e);
}
}
}
Aggregations