|
|
@ -3,7 +3,6 @@ package io.legado.app.model.analyzeRule |
|
|
|
import androidx.annotation.Keep |
|
|
|
import androidx.annotation.Keep |
|
|
|
import com.jayway.jsonpath.JsonPath |
|
|
|
import com.jayway.jsonpath.JsonPath |
|
|
|
import com.jayway.jsonpath.ReadContext |
|
|
|
import com.jayway.jsonpath.ReadContext |
|
|
|
import io.legado.app.utils.printOnDebug |
|
|
|
|
|
|
|
import java.util.* |
|
|
|
import java.util.* |
|
|
|
|
|
|
|
|
|
|
|
@Suppress("RegExpRedundantEscape") |
|
|
|
@Suppress("RegExpRedundantEscape") |
|
|
@ -41,20 +40,14 @@ class AnalyzeByJSonPath(json: Any) { |
|
|
|
result = ruleAnalyzes.innerRule("{$.") { getString(it) } //替换所有{$.rule...} |
|
|
|
result = ruleAnalyzes.innerRule("{$.") { getString(it) } //替换所有{$.rule...} |
|
|
|
|
|
|
|
|
|
|
|
if (result.isEmpty()) { //st为空,表明无成功替换的内嵌规则 |
|
|
|
if (result.isEmpty()) { //st为空,表明无成功替换的内嵌规则 |
|
|
|
try { |
|
|
|
|
|
|
|
val ob = ctx.read<Any>(rule) |
|
|
|
val ob = ctx.read<Any>(rule) |
|
|
|
result = if (ob is List<*>) { |
|
|
|
result = if (ob is List<*>) { |
|
|
|
ob.joinToString("\n") |
|
|
|
ob.joinToString("\n") |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
ob.toString() |
|
|
|
ob.toString() |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (ignored: Exception) { |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return result |
|
|
|
return result |
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
val textList = arrayListOf<String>() |
|
|
|
val textList = arrayListOf<String>() |
|
|
|
for (rl in rules) { |
|
|
|
for (rl in rules) { |
|
|
@ -77,24 +70,19 @@ class AnalyzeByJSonPath(json: Any) { |
|
|
|
val rules = ruleAnalyzes.splitRule("&&", "||", "%%") |
|
|
|
val rules = ruleAnalyzes.splitRule("&&", "||", "%%") |
|
|
|
|
|
|
|
|
|
|
|
if (rules.size == 1) { |
|
|
|
if (rules.size == 1) { |
|
|
|
|
|
|
|
|
|
|
|
ruleAnalyzes.reSetPos() //将pos重置为0,复用解析器 |
|
|
|
ruleAnalyzes.reSetPos() //将pos重置为0,复用解析器 |
|
|
|
val st = ruleAnalyzes.innerRule("{$.") { getString(it) } //替换所有{$.rule...} |
|
|
|
val st = ruleAnalyzes.innerRule("{$.") { getString(it) } //替换所有{$.rule...} |
|
|
|
if (st.isEmpty()) { //st为空,表明无成功替换的内嵌规则 |
|
|
|
if (st.isEmpty()) { //st为空,表明无成功替换的内嵌规则 |
|
|
|
try { |
|
|
|
|
|
|
|
val obj = ctx.read<Any>(rule) //kotlin的Any型返回值不包含null ,删除赘余 ?: return result |
|
|
|
val obj = ctx.read<Any>(rule) //kotlin的Any型返回值不包含null ,删除赘余 ?: return result |
|
|
|
if (obj is List<*>) { |
|
|
|
if (obj is List<*>) { |
|
|
|
for (o in obj) result.add(o.toString()) |
|
|
|
for (o in obj) result.add(o.toString()) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
result.add(obj.toString()) |
|
|
|
result.add(obj.toString()) |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (ignored: Exception) { |
|
|
|
} else { |
|
|
|
|
|
|
|
result.add(st) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} else result.add(st) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return result |
|
|
|
return result |
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
val results = ArrayList<List<String>>() |
|
|
|
val results = ArrayList<List<String>>() |
|
|
|
for (rl in rules) { |
|
|
|
for (rl in rules) { |
|
|
@ -136,13 +124,8 @@ class AnalyzeByJSonPath(json: Any) { |
|
|
|
val rules = ruleAnalyzes.splitRule("&&", "||", "%%") |
|
|
|
val rules = ruleAnalyzes.splitRule("&&", "||", "%%") |
|
|
|
if (rules.size == 1) { |
|
|
|
if (rules.size == 1) { |
|
|
|
ctx.let { |
|
|
|
ctx.let { |
|
|
|
try { |
|
|
|
|
|
|
|
return it.read<ArrayList<Any>>(rules[0]) |
|
|
|
return it.read<ArrayList<Any>>(rules[0]) |
|
|
|
} catch (e: Exception) { |
|
|
|
|
|
|
|
e.printOnDebug() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return null |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
val results = ArrayList<ArrayList<*>>() |
|
|
|
val results = ArrayList<ArrayList<*>>() |
|
|
|
for (rl in rules) { |
|
|
|
for (rl in rules) { |
|
|
|