@Override
protected Stanza handleSet(IQStanza stanza, ServerRuntimeContext serverRuntimeContext, SessionContext sessionContext) {
Entity from = stanza.getFrom();
if (from == null) {
from = sessionContext.getInitiatingEntity();
}
XMLElement vCardElement = null;
try {
vCardElement = stanza.getSingleInnerElementsNamed("vCard");
} catch (XMLSemanticError xmlSemanticError) {
return ServerErrorResponses.getStanzaError(StanzaErrorCondition.BAD_REQUEST, stanza,
StanzaErrorType.MODIFY, "vCard element is missing", null, null);
}
String vcardContent = new Renderer(vCardElement).getComplete();
if (persistenceManager == null) {
return ServerErrorResponses.getStanzaError(StanzaErrorCondition.INTERNAL_SERVER_ERROR,
stanza, StanzaErrorType.WAIT, "internal storage inaccessible", null, null);
}
boolean success = persistenceManager.setVcard(from, vcardContent);
if (success) {
return StanzaBuilder.createIQStanza(null, from, IQStanzaType.RESULT, stanza.getID()).build();
} else {
return StanzaBuilder.createIQStanza(null, from, IQStanzaType.ERROR, stanza.getID()).build();
}
}