pull/32/head
Administrator 5 years ago
commit 8b0913b571
  1. 12
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByJSonPath.kt
  2. 40
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByJSoup.kt
  3. 45
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByXPath.kt

@ -83,15 +83,15 @@ class AnalyzeByJSonPath {
val elementsType: String val elementsType: String
when { when {
rule.contains("&&") -> { rule.contains("&&") -> {
rules = rule.split("&&".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() rules = rule.splitNotBlank("&&")
elementsType = "&" elementsType = "&"
} }
rule.contains("%%") -> { rule.contains("%%") -> {
rules = rule.split("%%".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() rules = rule.splitNotBlank("%%")
elementsType = "%" elementsType = "%"
} }
else -> { else -> {
rules = rule.split("\\|\\|".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() rules = rule.splitNotBlank("||")
elementsType = "|" elementsType = "|"
} }
} }
@ -160,15 +160,15 @@ class AnalyzeByJSonPath {
val rules: Array<String> val rules: Array<String>
when { when {
rule.contains("&&") -> { rule.contains("&&") -> {
rules = rule.split("&&".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() rules = rule.splitNotBlank("&&")
elementsType = "&" elementsType = "&"
} }
rule.contains("%%") -> { rule.contains("%%") -> {
rules = rule.split("%%".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() rules = rule.splitNotBlank("%%")
elementsType = "%" elementsType = "%"
} }
else -> { else -> {
rules = rule.split("\\|\\|".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() rules = rule.splitNotBlank("||")
elementsType = "|" elementsType = "|"
} }
} }

@ -79,23 +79,17 @@ class AnalyzeByJSoup {
val elementsType: String val elementsType: String
val ruleStrS: Array<String> val ruleStrS: Array<String>
when { when {
sourceRule.elementsRule.contains("&") -> { sourceRule.elementsRule.contains("&&") -> {
elementsType = "&" elementsType = "&"
ruleStrS = ruleStrS = sourceRule.elementsRule.split("&&").dropLastWhile { it.isEmpty() }.toTypedArray()
sourceRule.elementsRule.split("&+".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
} }
sourceRule.elementsRule.contains("%%") -> { sourceRule.elementsRule.contains("%%") -> {
elementsType = "%" elementsType = "%"
ruleStrS = ruleStrS = sourceRule.elementsRule.split("%%").dropLastWhile { it.isEmpty() }.toTypedArray()
sourceRule.elementsRule.split("%%".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
} }
else -> { else -> {
elementsType = "|" elementsType = "|"
ruleStrS = if (sourceRule.isCss) { ruleStrS = sourceRule.elementsRule.split("||").dropLastWhile { it.isEmpty() }.toTypedArray()
sourceRule.elementsRule.split("\\|\\|".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
} else {
sourceRule.elementsRule.split("\\|+".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
}
} }
} }
val results = ArrayList<List<String>>() val results = ArrayList<List<String>>()
@ -148,21 +142,17 @@ class AnalyzeByJSoup {
val elementsType: String val elementsType: String
val ruleStrS: Array<String> val ruleStrS: Array<String>
when { when {
sourceRule.elementsRule.contains("&") -> { sourceRule.elementsRule.contains("&&") -> {
elementsType = "&" elementsType = "&"
ruleStrS = sourceRule.elementsRule.split("&+".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() ruleStrS = sourceRule.elementsRule.split("&&").dropLastWhile { it.isEmpty() }.toTypedArray()
} }
sourceRule.elementsRule.contains("%") -> { sourceRule.elementsRule.contains("%%") -> {
elementsType = "%" elementsType = "%"
ruleStrS = sourceRule.elementsRule.split("%+".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() ruleStrS = sourceRule.elementsRule.split("%%").dropLastWhile { it.isEmpty() }.toTypedArray()
} }
else -> { else -> {
elementsType = "|" elementsType = "|"
ruleStrS = if (sourceRule.isCss) { ruleStrS = sourceRule.elementsRule.split("||").dropLastWhile { it.isEmpty() }.toTypedArray()
sourceRule.elementsRule.split("\\|\\|".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
} else {
sourceRule.elementsRule.split("\\|+".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
}
} }
} }
val elementsList = ArrayList<Elements>() val elementsList = ArrayList<Elements>()
@ -225,7 +215,7 @@ class AnalyzeByJSoup {
private fun getElementsSingle(temp: Element, rule: String): Elements { private fun getElementsSingle(temp: Element, rule: String): Elements {
val elements = Elements() val elements = Elements()
try { try {
val rs = rule.trim { it <= ' ' }.split("@".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() val rs = rule.trim { it <= ' ' }.split("@").dropLastWhile { it.isEmpty() }.toTypedArray()
if (rs.size > 1) { if (rs.size > 1) {
elements.add(temp) elements.add(temp)
for (rl in rs) { for (rl in rs) {
@ -237,15 +227,15 @@ class AnalyzeByJSoup {
elements.addAll(es) elements.addAll(es)
} }
} else { } else {
val rulePcx = rule.split("!".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() val rulePcx = rule.split("!").dropLastWhile { it.isEmpty() }.toTypedArray()
val rulePc = val rulePc =
rulePcx[0].trim { it <= ' ' }.split(">".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() rulePcx[0].trim { it <= ' ' }.split(">").dropLastWhile { it.isEmpty() }.toTypedArray()
val rules = val rules =
rulePc[0].trim { it <= ' ' }.split("\\.".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() rulePc[0].trim { it <= ' ' }.split(".").dropLastWhile { it.isEmpty() }.toTypedArray()
var filterRules: Array<String>? = null var filterRules: Array<String>? = null
var needFilterElements = rulePc.size > 1 && !isEmpty(rulePc[1].trim { it <= ' ' }) var needFilterElements = rulePc.size > 1 && !isEmpty(rulePc[1].trim { it <= ' ' })
if (needFilterElements) { if (needFilterElements) {
filterRules = rulePc[1].trim { it <= ' ' }.split("\\.".toRegex()).dropLastWhile { it.isEmpty() } filterRules = rulePc[1].trim { it <= ' ' }.split(".").dropLastWhile { it.isEmpty() }
.toTypedArray() .toTypedArray()
filterRules[0] = filterRules[0].trim { it <= ' ' } filterRules[0] = filterRules[0].trim { it <= ' ' }
val validKeys = listOf("class", "id", "tag", "text") val validKeys = listOf("class", "id", "tag", "text")
@ -344,7 +334,7 @@ class AnalyzeByJSoup {
} }
var elements = Elements() var elements = Elements()
elements.add(element) elements.add(element)
val rules = ruleStr.split("@".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() val rules = ruleStr.split("@").dropLastWhile { it.isEmpty() }.toTypedArray()
for (i in 0 until rules.size - 1) { for (i in 0 until rules.size - 1) {
val es = Elements() val es = Elements()
for (elt in elements) { for (elt in elements) {

@ -33,16 +33,20 @@ class AnalyzeByXPath {
val jxNodes = ArrayList<JXNode>() val jxNodes = ArrayList<JXNode>()
val elementsType: String val elementsType: String
val rules: Array<String> val rules: Array<String>
if (xPath.contains("&&")) { when {
rules = xPath.split("&&".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() xPath.contains("&&") -> {
rules = xPath.split("&&").dropLastWhile { it.isEmpty() }.toTypedArray()
elementsType = "&" elementsType = "&"
} else if (xPath.contains("%%")) { }
rules = xPath.split("%%".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() xPath.contains("%%") -> {
rules = xPath.split("%%").dropLastWhile { it.isEmpty() }.toTypedArray()
elementsType = "%" elementsType = "%"
} else { }
rules = xPath.split("\\|\\|".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() else -> {
rules = xPath.split("||").dropLastWhile { it.isEmpty() }.toTypedArray()
elementsType = "|" elementsType = "|"
} }
}
if (rules.size == 1) { if (rules.size == 1) {
return jxDocument!!.selN(rules[0]) return jxDocument!!.selN(rules[0])
} else { } else {
@ -79,16 +83,20 @@ class AnalyzeByXPath {
val result = ArrayList<String>() val result = ArrayList<String>()
val elementsType: String val elementsType: String
val rules: Array<String> val rules: Array<String>
if (xPath.contains("&&")) { when {
rules = xPath.split("&&".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() xPath.contains("&&") -> {
rules = xPath.split("&&").dropLastWhile { it.isEmpty() }.toTypedArray()
elementsType = "&" elementsType = "&"
} else if (xPath.contains("%%")) { }
rules = xPath.split("%%".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() xPath.contains("%%") -> {
rules = xPath.split("%%").dropLastWhile { it.isEmpty() }.toTypedArray()
elementsType = "%" elementsType = "%"
} else { }
rules = xPath.split("\\|\\|".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() else -> {
rules = xPath.split("||").dropLastWhile { it.isEmpty() }.toTypedArray()
elementsType = "|" elementsType = "|"
} }
}
if (rules.size == 1) { if (rules.size == 1) {
val jxNodes = jxDocument!!.selN(xPath) val jxNodes = jxDocument!!.selN(xPath)
for (jxNode in jxNodes) { for (jxNode in jxNodes) {
@ -132,17 +140,18 @@ class AnalyzeByXPath {
val rules: Array<String> val rules: Array<String>
val elementsType: String val elementsType: String
if (rule.contains("&&")) { if (rule.contains("&&")) {
rules = rule.split("&&".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() rules = rule.split("&&").dropLastWhile { it.isEmpty() }.toTypedArray()
elementsType = "&" elementsType = "&"
} else { } else {
rules = rule.split("\\|\\|".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() rules = rule.split("||").dropLastWhile { it.isEmpty() }.toTypedArray()
elementsType = "|" elementsType = "|"
} }
if (rules.size == 1) { if (rules.size == 1) {
/*Object object = jxDocument.selOne(rule); val jxNodes = jxDocument?.selN(rule)
result = object instanceof Element ? ((Element) object).html() : (String) object;*/ jxNodes?.let {
val jxNodes = jxDocument!!.selN(rule) ?: return null TextUtils.join(",", jxNodes)
return TextUtils.join(",", jxNodes) }
return null
} else { } else {
val sb = StringBuilder() val sb = StringBuilder()
for (rl in rules) { for (rl in rules) {

Loading…
Cancel
Save