|
|
@ -11,7 +11,6 @@ object RssParserByRule { |
|
|
|
|
|
|
|
|
|
|
|
@Throws(Exception::class) |
|
|
|
@Throws(Exception::class) |
|
|
|
fun parseXML(response: Response<String>, rssSource: RssSource): MutableList<RssArticle> { |
|
|
|
fun parseXML(response: Response<String>, rssSource: RssSource): MutableList<RssArticle> { |
|
|
|
val articleList = mutableListOf<RssArticle>() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val xml = response.body() |
|
|
|
val xml = response.body() |
|
|
|
if (xml.isNullOrBlank()) { |
|
|
|
if (xml.isNullOrBlank()) { |
|
|
@ -22,12 +21,19 @@ object RssParserByRule { |
|
|
|
) |
|
|
|
) |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
var ruleArticles = rssSource.ruleArticles |
|
|
|
rssSource.ruleArticles?.let { ruleArticles -> |
|
|
|
if (ruleArticles.isNullOrBlank()) { |
|
|
|
|
|
|
|
return RssParser.parseXML(xml, rssSource.sourceUrl) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
val articleList = mutableListOf<RssArticle>() |
|
|
|
val analyzeRule = AnalyzeRule() |
|
|
|
val analyzeRule = AnalyzeRule() |
|
|
|
analyzeRule.setContent(xml) |
|
|
|
analyzeRule.setContent(xml) |
|
|
|
|
|
|
|
var reverse = false |
|
|
|
|
|
|
|
if (ruleArticles.startsWith("-")) { |
|
|
|
|
|
|
|
reverse = true |
|
|
|
|
|
|
|
ruleArticles = ruleArticles.substring(1) |
|
|
|
|
|
|
|
} |
|
|
|
val collections = analyzeRule.getElements(ruleArticles) |
|
|
|
val collections = analyzeRule.getElements(ruleArticles) |
|
|
|
val ruleGuid = analyzeRule.splitSourceRule(rssSource.ruleGuid ?: "") |
|
|
|
|
|
|
|
val ruleTitle = analyzeRule.splitSourceRule(rssSource.ruleTitle ?: "") |
|
|
|
val ruleTitle = analyzeRule.splitSourceRule(rssSource.ruleTitle ?: "") |
|
|
|
val ruleAuthor = analyzeRule.splitSourceRule(rssSource.ruleAuthor ?: "") |
|
|
|
val ruleAuthor = analyzeRule.splitSourceRule(rssSource.ruleAuthor ?: "") |
|
|
|
val rulePubDate = analyzeRule.splitSourceRule(rssSource.rulePubDate ?: "") |
|
|
|
val rulePubDate = analyzeRule.splitSourceRule(rssSource.rulePubDate ?: "") |
|
|
@ -41,7 +47,6 @@ object RssParserByRule { |
|
|
|
item, |
|
|
|
item, |
|
|
|
analyzeRule, |
|
|
|
analyzeRule, |
|
|
|
index == 0, |
|
|
|
index == 0, |
|
|
|
ruleGuid, |
|
|
|
|
|
|
|
ruleTitle, |
|
|
|
ruleTitle, |
|
|
|
ruleAuthor, |
|
|
|
ruleAuthor, |
|
|
|
rulePubDate, |
|
|
|
rulePubDate, |
|
|
@ -55,17 +60,20 @@ object RssParserByRule { |
|
|
|
articleList.add(it) |
|
|
|
articleList.add(it) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} ?: let { |
|
|
|
if (reverse) { |
|
|
|
return RssParser.parseXML(xml, rssSource.sourceUrl) |
|
|
|
articleList.reverse() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
for ((index: Int, item: RssArticle) in articleList.withIndex()) { |
|
|
|
|
|
|
|
item.order = System.currentTimeMillis() + index |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return articleList |
|
|
|
} |
|
|
|
} |
|
|
|
return articleList |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun getItem( |
|
|
|
private fun getItem( |
|
|
|
item: Any, |
|
|
|
item: Any, |
|
|
|
analyzeRule: AnalyzeRule, |
|
|
|
analyzeRule: AnalyzeRule, |
|
|
|
printLog: Boolean, |
|
|
|
printLog: Boolean, |
|
|
|
ruleGuid: List<AnalyzeRule.SourceRule>, |
|
|
|
|
|
|
|
ruleTitle: List<AnalyzeRule.SourceRule>, |
|
|
|
ruleTitle: List<AnalyzeRule.SourceRule>, |
|
|
|
ruleAuthor: List<AnalyzeRule.SourceRule>, |
|
|
|
ruleAuthor: List<AnalyzeRule.SourceRule>, |
|
|
|
rulePubDate: List<AnalyzeRule.SourceRule>, |
|
|
|
rulePubDate: List<AnalyzeRule.SourceRule>, |
|
|
@ -77,7 +85,6 @@ object RssParserByRule { |
|
|
|
): RssArticle? { |
|
|
|
): RssArticle? { |
|
|
|
val rssArticle = RssArticle() |
|
|
|
val rssArticle = RssArticle() |
|
|
|
analyzeRule.setContent(item) |
|
|
|
analyzeRule.setContent(item) |
|
|
|
rssArticle.guid = analyzeRule.getString(ruleGuid) |
|
|
|
|
|
|
|
rssArticle.title = analyzeRule.getString(ruleTitle) |
|
|
|
rssArticle.title = analyzeRule.getString(ruleTitle) |
|
|
|
rssArticle.author = analyzeRule.getString(ruleAuthor) |
|
|
|
rssArticle.author = analyzeRule.getString(ruleAuthor) |
|
|
|
rssArticle.pubDate = analyzeRule.getString(rulePubDate) |
|
|
|
rssArticle.pubDate = analyzeRule.getString(rulePubDate) |
|
|
|