Integer top = Integer.MAX_VALUE;
Boolean sortAlpha = true;
Iterator<YMarkTag> tit = null;
TreeSet<YMarkTag> tags = null;
int count = 0;
YMarkTag t;
if (post != null && post.containsKey(TAG) && !post.get(TAG).isEmpty()) {
final String[] tagArray = YMarkUtil.cleanTagsString(post.get(TAG)).split(YMarkUtil.TAGS_SEPARATOR);
try {
tags = new TreeSet<YMarkTag>(sb.tables.bookmarks.getTags(sb.tables.bookmarks.getBookmarksByTag(bmk_user, tagArray)).values());
} catch (final IOException e) {
return prop;
}
} else {
try {
tags = new TreeSet<YMarkTag>(sb.tables.bookmarks.getTags(bmk_user).values());
} catch (final IOException e) {
return prop;
}
}
if (post != null && post.containsKey(TOP)) {
top = post.getInt(TOP, Integer.MAX_VALUE);
}
if (post != null && post.containsKey(SORT)) {
if (SIZE.equals(post.get(SORT))) {
sortAlpha = false;
}
}
if(sortAlpha) {
final TreeMap<CollationKey, YMarkTag> sort = new TreeMap<CollationKey, YMarkTag>();
final Collator collator = Collator.getInstance();
collator.setStrength(Collator.SECONDARY);
tit = tags.iterator();
while(tit.hasNext() && count < top) {
t = tit.next();
sort.put(collator.getCollationKey(t.name()), t);
count++;
}
tit = sort.values().iterator();
} else {
tit = tags.iterator();
}
count = 0;
while (tit.hasNext() && count < top) {
t = tit.next();
if(!t.name().equals(YMarkEntry.BOOKMARK.TAGS.deflt())) {
prop.putXML("tags_" + count + "_name", t.name());
prop.put("tags_" + count + "_count", t.size());
count++;
}
}
prop.put("tags", count);