|
|
|
@ -33,75 +33,48 @@ object RssParser { |
|
|
|
|
// Start parsing the item |
|
|
|
|
if (eventType == XmlPullParser.START_TAG) { |
|
|
|
|
when { |
|
|
|
|
xmlPullParser.name.equals( |
|
|
|
|
RSSKeywords.RSS_ITEM, |
|
|
|
|
ignoreCase = true |
|
|
|
|
) -> insideItem = true |
|
|
|
|
xmlPullParser.name.equals( |
|
|
|
|
RSSKeywords.RSS_ITEM_TITLE, |
|
|
|
|
ignoreCase = true |
|
|
|
|
) -> if (insideItem) { |
|
|
|
|
currentArticle.title = xmlPullParser.nextText().trim() |
|
|
|
|
} |
|
|
|
|
xmlPullParser.name.equals( |
|
|
|
|
RSSKeywords.RSS_ITEM_LINK, |
|
|
|
|
ignoreCase = true |
|
|
|
|
) -> if (insideItem) { |
|
|
|
|
currentArticle.link = xmlPullParser.nextText().trim() |
|
|
|
|
} |
|
|
|
|
xmlPullParser.name.equals( |
|
|
|
|
RSSKeywords.RSS_ITEM_AUTHOR, |
|
|
|
|
ignoreCase = true |
|
|
|
|
) -> if (insideItem) { |
|
|
|
|
currentArticle.author = xmlPullParser.nextText().trim() |
|
|
|
|
} |
|
|
|
|
xmlPullParser.name.equals( |
|
|
|
|
RSSKeywords.RSS_ITEM_CATEGORY, |
|
|
|
|
ignoreCase = true |
|
|
|
|
) -> if (insideItem) { |
|
|
|
|
currentArticle.categories.add(xmlPullParser.nextText().trim()) |
|
|
|
|
} |
|
|
|
|
xmlPullParser.name.equals( |
|
|
|
|
RSSKeywords.RSS_ITEM_THUMBNAIL, |
|
|
|
|
ignoreCase = true |
|
|
|
|
) -> if (insideItem) { |
|
|
|
|
currentArticle.image = |
|
|
|
|
xmlPullParser.name |
|
|
|
|
.equals(RSSKeywords.RSS_ITEM, true) -> insideItem = true |
|
|
|
|
xmlPullParser.name.equals(RSSKeywords.RSS_ITEM_TITLE, true) -> |
|
|
|
|
if (insideItem) currentArticle.title = xmlPullParser.nextText().trim() |
|
|
|
|
xmlPullParser.name.equals(RSSKeywords.RSS_ITEM_LINK, true) -> |
|
|
|
|
if (insideItem) currentArticle.link = xmlPullParser.nextText().trim() |
|
|
|
|
xmlPullParser.name.equals(RSSKeywords.RSS_ITEM_AUTHOR, true) -> |
|
|
|
|
if (insideItem) currentArticle.author = xmlPullParser.nextText().trim() |
|
|
|
|
xmlPullParser.name.equals(RSSKeywords.RSS_ITEM_CATEGORY, true) -> |
|
|
|
|
if (insideItem) currentArticle.categories.add(xmlPullParser.nextText().trim()) |
|
|
|
|
xmlPullParser.name.equals(RSSKeywords.RSS_ITEM_THUMBNAIL, true) -> |
|
|
|
|
if (insideItem) currentArticle.image = |
|
|
|
|
xmlPullParser.getAttributeValue(null, RSSKeywords.RSS_ITEM_URL) |
|
|
|
|
} |
|
|
|
|
xmlPullParser.name.equals( |
|
|
|
|
RSSKeywords.RSS_ITEM_ENCLOSURE, |
|
|
|
|
ignoreCase = true |
|
|
|
|
) -> if (insideItem) { |
|
|
|
|
val type = xmlPullParser.getAttributeValue(null, RSSKeywords.RSS_ITEM_TYPE) |
|
|
|
|
xmlPullParser.name.equals(RSSKeywords.RSS_ITEM_ENCLOSURE, true) -> |
|
|
|
|
if (insideItem) { |
|
|
|
|
val type = |
|
|
|
|
xmlPullParser.getAttributeValue(null, RSSKeywords.RSS_ITEM_TYPE) |
|
|
|
|
if (type != null && type.contains("image/")) { |
|
|
|
|
currentArticle.image = |
|
|
|
|
xmlPullParser.getAttributeValue(null, RSSKeywords.RSS_ITEM_URL) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
xmlPullParser.name.equals( |
|
|
|
|
RSSKeywords.RSS_ITEM_DESCRIPTION, |
|
|
|
|
ignoreCase = true |
|
|
|
|
) -> if (insideItem) { |
|
|
|
|
xmlPullParser.name |
|
|
|
|
.equals(RSSKeywords.RSS_ITEM_DESCRIPTION, true) -> |
|
|
|
|
if (insideItem) { |
|
|
|
|
val description = xmlPullParser.nextText() |
|
|
|
|
currentArticle.description = description.trim() |
|
|
|
|
if (currentArticle.image == null) { |
|
|
|
|
currentArticle.image = getImageUrl(description) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
xmlPullParser.name.equals( |
|
|
|
|
RSSKeywords.RSS_ITEM_CONTENT, |
|
|
|
|
ignoreCase = true |
|
|
|
|
) -> if (insideItem) { |
|
|
|
|
xmlPullParser.name.equals(RSSKeywords.RSS_ITEM_CONTENT, true) -> |
|
|
|
|
if (insideItem) { |
|
|
|
|
val content = xmlPullParser.nextText().trim() |
|
|
|
|
currentArticle.content = content |
|
|
|
|
if (currentArticle.image == null) { |
|
|
|
|
currentArticle.image = getImageUrl(content) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
xmlPullParser.name.equals( |
|
|
|
|
RSSKeywords.RSS_ITEM_PUB_DATE, |
|
|
|
|
ignoreCase = true |
|
|
|
|
) -> if (insideItem) { |
|
|
|
|
xmlPullParser.name |
|
|
|
|
.equals(RSSKeywords.RSS_ITEM_PUB_DATE, true) -> |
|
|
|
|
if (insideItem) { |
|
|
|
|
val nextTokenType = xmlPullParser.next() |
|
|
|
|
if (nextTokenType == XmlPullParser.TEXT) { |
|
|
|
|
currentArticle.pubDate = xmlPullParser.text.trim() |
|
|
|
@ -109,23 +82,13 @@ object RssParser { |
|
|
|
|
// Skip to be able to find date inside 'tag' tag |
|
|
|
|
continue@loop |
|
|
|
|
} |
|
|
|
|
xmlPullParser.name.equals( |
|
|
|
|
RSSKeywords.RSS_ITEM_TIME, |
|
|
|
|
ignoreCase = true |
|
|
|
|
) -> if (insideItem) { |
|
|
|
|
currentArticle.pubDate = xmlPullParser.nextText() |
|
|
|
|
} |
|
|
|
|
xmlPullParser.name.equals( |
|
|
|
|
RSSKeywords.RSS_ITEM_GUID, |
|
|
|
|
ignoreCase = true |
|
|
|
|
) -> if (insideItem) { |
|
|
|
|
currentArticle.guid = xmlPullParser.nextText().trim() |
|
|
|
|
} |
|
|
|
|
xmlPullParser.name.equals(RSSKeywords.RSS_ITEM_TIME, true) -> |
|
|
|
|
if (insideItem) currentArticle.pubDate = xmlPullParser.nextText() |
|
|
|
|
xmlPullParser.name.equals(RSSKeywords.RSS_ITEM_GUID, true) -> |
|
|
|
|
if (insideItem) currentArticle.guid = xmlPullParser.nextText().trim() |
|
|
|
|
} |
|
|
|
|
} else if (eventType == XmlPullParser.END_TAG && xmlPullParser.name.equals( |
|
|
|
|
"item", |
|
|
|
|
ignoreCase = true |
|
|
|
|
) |
|
|
|
|
} else if (eventType == XmlPullParser.END_TAG |
|
|
|
|
&& xmlPullParser.name.equals("item", true) |
|
|
|
|
) { |
|
|
|
|
// The item is correctly parsed |
|
|
|
|
insideItem = false |
|
|
|
|