}
}
}
private void processItem(JSONObject item, IFeed feed) throws JSONException, URISyntaxException {
IModelFactory factory = Owl.getModelFactory();
INews news = factory.createNews(null, feed, new Date());
news.setBase(feed.getBase());
/* GUID */
if (item.has(ID))
news.setGuid(factory.createGuid(news, item.getString(ID), true));
/* Origin */
if (item.has(ORIGIN)) {
JSONObject origin = item.getJSONObject(ORIGIN);
news.setInReplyTo(getString(origin, STREAM_ID));
}
/* Title */
news.setTitle(getString(item, TITLE));
/* Publish Date */
news.setPublishDate(getDate(item, UPDATED));
/* Description */
news.setDescription(getContent(item));
/* Link */
news.setLink(getAlternateLink(item, TEXT_HTML));
/* Comments */
URI commentsLink = getCommentsLink(item, TEXT_HTML);
if (commentsLink != null)
news.setComments(commentsLink.toString());
/* Author */
if (item.has(AUTHOR)) {
String author = getString(item, AUTHOR);
if (StringUtils.isSet(author)) {
IPerson person = factory.createPerson(null, news);
person.setName(author);
}
}
/* Attachments */
if (item.has(ENCLOSURE)) {
JSONArray attachments = item.getJSONArray(ENCLOSURE);
for (int i = 0; i < attachments.length(); i++) {
JSONObject attachment = attachments.getJSONObject(i);
if (attachment.has(HREF)) {
IAttachment att = factory.createAttachment(null, news);
att.setLink(new URI(attachment.getString(HREF)));
if (attachment.has(LENGTH)) {
try {
att.setLength(attachment.getInt(LENGTH));
} catch (JSONException e) {
// Can happen if the length is larger than Integer.MAX_VALUE, in that case just ignore
}
}
if (attachment.has(TYPE))
att.setType(attachment.getString(TYPE));
}
}
}
/* Categories / Labels / State */
Set<String> labels = new HashSet<String>(1);
if (item.has(CATEGORIES)) {
JSONArray categories = item.getJSONArray(CATEGORIES);
for (int i = 0; i < categories.length(); i++) {
if (categories.isNull(i))
continue;
String category = categories.getString(i);
if (!StringUtils.isSet(category))
continue;
/* Normal user chosen category */
if (!category.startsWith(GOOGLE_CATEGORY_PREFIX)) {
ICategory cat = factory.createCategory(null, news);
cat.setName(category);
}
/* News is marked read */
else if (category.endsWith(GOOGLE_STATE_READ)) {