// We fetch the profile of the target user
Profile profile = ProfileManager.getInstance().getProfile(sender.toBareJID(), target.toBareJID());
// Prepare the result packet
VCard4DomWriter writer = new DefaultVCard4DomWriter();
DOMDocument domDocument = new DOMDocument();
IQ result = IQ.createResultIQ(packet);
Element query = (Element) domDocument.appendChild(domDocument.createElementNS(NAMESPACE, NAME));
if (profile != null) {
writer.toElement(profile, query);
} else {
query.appendChild(domDocument.createElementNS(VCard4.NAMESPACE, VCard4.VCARD_ELEMENT));
}
result.setChildElement((org.dom4j.Element) query);