@Override
protected Roster retrieveRosterInternal(Entity bareJid) {
final Node rosterNode = retrieveRosterNode(jcrStorage, bareJid);
MutableRoster roster = new MutableRoster();
NodeIterator nodes = null;
try {
nodes = rosterNode.getNodes();
} catch (RepositoryException e) {
return roster; // empty roster object
}
while (nodes != null && nodes.hasNext()) {
Node node = nodes.nextNode();
String contactJidString = null;
try {
contactJidString = node.getName();
} catch (RepositoryException e) {
logger.warn("when loading roster for user {} cannot read node name for node id = " + node.toString());
}
logger.warn("try now loading contact " + contactJidString + " from node " + node.toString());
EntityImpl contactJid = null;
if (contactJidString != null) {
try {
contactJid = EntityImpl.parse(contactJidString);
} catch (EntityFormatException e) {
logger.warn("when loading roster for user {} parsing contact jid {}", bareJid, contactJidString);
}
}
if (contactJid == null) {
logger.warn("when loading roster for user {}, skipping a contact due to missing or unparsable jid",
bareJid);
continue;
}
String name = readAttribute(node, "name");
String typeString = readAttribute(node, "type");
SubscriptionType subscriptionType = null;
try {
subscriptionType = SubscriptionType.valueOf(typeString == null ? "NONE" : typeString.toUpperCase());
} catch (IllegalArgumentException e) {
logger.warn("when loading roster for user " + bareJid + ", contact " + contactJid
+ " misses a subscription type", bareJid, contactJid);
}
String askTypeString = readAttribute(node, "askType");
AskSubscriptionType askSubscriptionType = AskSubscriptionType.NOT_SET;
try {
if (askTypeString != null)
askSubscriptionType = AskSubscriptionType.valueOf(askTypeString);
} catch (IllegalArgumentException e) {
logger.warn("when loading roster for user " + bareJid.getFullQualifiedName() + ", contact "
+ contactJid.getFullQualifiedName() + ", the ask subscription type is unparsable. skipping!");
continue; // don't return it, don't set a default!
}
List<RosterGroup> groups = new ArrayList<RosterGroup>();
// TODO read groups
RosterItem item = new RosterItem(contactJid, name, subscriptionType, askSubscriptionType, groups);
logger.info("item loaded for " + bareJid.getFullQualifiedName() + ": " + item.toString());
roster.addItem(item);
}
return roster;
}