@SpecCompliant(spec="rfc3921bis-08", section = "2.1.1", status = FINISHED, coverage = COMPLETE),
@SpecCompliant(spec="rfc3921bis-08", section = "2.1.3", status = FINISHED,
coverage = PARTIAL, comment = "handles the conformance rules 1-3 when parseSubscriptionTypes is set to false")
})
private static RosterItem parseRosterItem(IQStanza stanza, boolean parseSubscriptionTypes) throws RosterBadRequestException, RosterNotAcceptableException {
XMLElement queryElement;
try {
queryElement = stanza.getSingleInnerElementsNamed("query");
if (queryElement == null) throw new XMLSemanticError("missing query node");
} catch (XMLSemanticError xmlSemanticError) {
throw new RosterBadRequestException("roster set needs a single query node.");
}
XMLElement itemElement;
try {
itemElement = queryElement.getSingleInnerElementsNamed("item");
if (itemElement == null) throw new XMLSemanticError("missing item node");
} catch (XMLSemanticError xmlSemanticError) {
throw new RosterBadRequestException("roster set needs a single item node.");
}
Attribute attributeJID = itemElement.getAttribute("jid");
if (attributeJID == null || attributeJID.getValue() == null) throw new RosterBadRequestException("missing 'jid' attribute on item node");
XMLElementVerifier verifier = itemElement.getVerifier();
String name = verifier.attributePresent("name") ? itemElement.getAttribute("name").getValue() : null;
if (name != null && name.length() > RosterConfiguration.ROSTER_ITEM_NAME_MAX_LENGTH) {
throw new RosterNotAcceptableException("roster name too long: " + name.length());
}
SubscriptionType subscription = verifier.attributePresent("subscription") ? SubscriptionType.valueOf(itemElement.getAttribute("subscription").getValue().toUpperCase()) : SubscriptionType.NONE;
if (!parseSubscriptionTypes && subscription != SubscriptionType.REMOVE) subscription = SubscriptionType.NONE; // roster remove is always tolerated
AskSubscriptionType askSubscriptionType = AskSubscriptionType.NOT_SET;
if (parseSubscriptionTypes) {
askSubscriptionType = verifier.attributePresent("ask") ? AskSubscriptionType.valueOf("ASK_" + itemElement.getAttribute("ask").getValue().toUpperCase()) : AskSubscriptionType.NOT_SET;
}
String contactJid = attributeJID.getValue();
Entity contact;
try {
contact = EntityImpl.parse(contactJid);
} catch (EntityFormatException e) {
throw new RosterNotAcceptableException("jid cannot be parsed: " + contactJid);
}
List<RosterGroup> groups = new ArrayList<RosterGroup>();
List<XMLElement> groupElements = itemElement.getInnerElementsNamed("group");
if (groupElements != null) {
for (XMLElement groupElement : groupElements) {
String groupName = null;
try {
groupName = groupElement.getSingleInnerText().getText();