|
|
@ -17,8 +17,7 @@ import javax.script.SimpleBindings |
|
|
|
import kotlin.collections.HashMap |
|
|
|
import kotlin.collections.HashMap |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Created by REFGD. |
|
|
|
* 解析规则获取结果 |
|
|
|
* 统一解析接口 |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Keep |
|
|
|
@Keep |
|
|
|
@Suppress("unused", "RegExpRedundantEscape") |
|
|
|
@Suppress("unused", "RegExpRedundantEscape") |
|
|
@ -38,11 +37,11 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions { |
|
|
|
private var objectChangedJS = false |
|
|
|
private var objectChangedJS = false |
|
|
|
private var objectChangedJP = false |
|
|
|
private var objectChangedJP = false |
|
|
|
|
|
|
|
|
|
|
|
@Throws(Exception::class) |
|
|
|
fun setContent(content: Any?, baseUrl: String? = null): AnalyzeRule { |
|
|
|
fun setContent(content: Any?): AnalyzeRule { |
|
|
|
|
|
|
|
if (content == null) throw AssertionError("Content cannot be null") |
|
|
|
if (content == null) throw AssertionError("Content cannot be null") |
|
|
|
isJSON = content.toString().isJson() |
|
|
|
|
|
|
|
this.content = content |
|
|
|
this.content = content |
|
|
|
|
|
|
|
setBaseUrl(baseUrl) |
|
|
|
|
|
|
|
isJSON = content.toString().isJson() |
|
|
|
objectChangedXP = true |
|
|
|
objectChangedXP = true |
|
|
|
objectChangedJS = true |
|
|
|
objectChangedJS = true |
|
|
|
objectChangedJP = true |
|
|
|
objectChangedJP = true |
|
|
@ -50,8 +49,8 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun setBaseUrl(baseUrl: String?): AnalyzeRule { |
|
|
|
fun setBaseUrl(baseUrl: String?): AnalyzeRule { |
|
|
|
this.baseUrl = baseUrl |
|
|
|
|
|
|
|
baseUrl?.let { |
|
|
|
baseUrl?.let { |
|
|
|
|
|
|
|
this.baseUrl = baseUrl |
|
|
|
try { |
|
|
|
try { |
|
|
|
baseURL = URL(baseUrl.substringBefore(",")) |
|
|
|
baseURL = URL(baseUrl.substringBefore(",")) |
|
|
|
} catch (e: Exception) { |
|
|
|
} catch (e: Exception) { |
|
|
@ -118,7 +117,6 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* 获取文本列表 |
|
|
|
* 获取文本列表 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Throws(Exception::class) |
|
|
|
|
|
|
|
@JvmOverloads |
|
|
|
@JvmOverloads |
|
|
|
fun getStringList(rule: String?, isUrl: Boolean = false): List<String>? { |
|
|
|
fun getStringList(rule: String?, isUrl: Boolean = false): List<String>? { |
|
|
|
if (rule.isNullOrEmpty()) return null |
|
|
|
if (rule.isNullOrEmpty()) return null |
|
|
@ -126,7 +124,6 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions { |
|
|
|
return getStringList(ruleList, isUrl) |
|
|
|
return getStringList(ruleList, isUrl) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Throws(Exception::class) |
|
|
|
|
|
|
|
fun getStringList(ruleList: List<SourceRule>, isUrl: Boolean = false): List<String>? { |
|
|
|
fun getStringList(ruleList: List<SourceRule>, isUrl: Boolean = false): List<String>? { |
|
|
|
var result: Any? = null |
|
|
|
var result: Any? = null |
|
|
|
val content = this.content |
|
|
|
val content = this.content |
|
|
@ -184,14 +181,12 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* 获取文本 |
|
|
|
* 获取文本 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Throws(Exception::class) |
|
|
|
|
|
|
|
fun getString(ruleStr: String?, isUrl: Boolean = false): String { |
|
|
|
fun getString(ruleStr: String?, isUrl: Boolean = false): String { |
|
|
|
if (TextUtils.isEmpty(ruleStr)) return "" |
|
|
|
if (TextUtils.isEmpty(ruleStr)) return "" |
|
|
|
val ruleList = splitSourceRule(ruleStr) |
|
|
|
val ruleList = splitSourceRule(ruleStr) |
|
|
|
return getString(ruleList, isUrl) |
|
|
|
return getString(ruleList, isUrl) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Throws(Exception::class) |
|
|
|
|
|
|
|
@JvmOverloads |
|
|
|
@JvmOverloads |
|
|
|
fun getString(ruleList: List<SourceRule>, isUrl: Boolean = false): String { |
|
|
|
fun getString(ruleList: List<SourceRule>, isUrl: Boolean = false): String { |
|
|
|
var result: Any? = null |
|
|
|
var result: Any? = null |
|
|
@ -244,7 +239,6 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* 获取Element |
|
|
|
* 获取Element |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Throws(Exception::class) |
|
|
|
|
|
|
|
fun getElement(ruleStr: String): Any? { |
|
|
|
fun getElement(ruleStr: String): Any? { |
|
|
|
if (TextUtils.isEmpty(ruleStr)) return null |
|
|
|
if (TextUtils.isEmpty(ruleStr)) return null |
|
|
|
var result: Any? = null |
|
|
|
var result: Any? = null |
|
|
@ -278,7 +272,6 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions { |
|
|
|
* 获取列表 |
|
|
|
* 获取列表 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Suppress("UNCHECKED_CAST") |
|
|
|
@Suppress("UNCHECKED_CAST") |
|
|
|
@Throws(Exception::class) |
|
|
|
|
|
|
|
fun getElements(ruleStr: String): List<Any> { |
|
|
|
fun getElements(ruleStr: String): List<Any> { |
|
|
|
var result: Any? = null |
|
|
|
var result: Any? = null |
|
|
|
val ruleList = splitSourceRule(ruleStr) |
|
|
|
val ruleList = splitSourceRule(ruleStr) |
|
|
@ -313,7 +306,6 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* 保存变量 |
|
|
|
* 保存变量 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Throws(Exception::class) |
|
|
|
|
|
|
|
private fun putRule(map: Map<String, String>) { |
|
|
|
private fun putRule(map: Map<String, String>) { |
|
|
|
for ((key, value) in map) { |
|
|
|
for ((key, value) in map) { |
|
|
|
put(key, getString(value)) |
|
|
|
put(key, getString(value)) |
|
|
@ -323,7 +315,6 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* 分离put规则 |
|
|
|
* 分离put规则 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Throws(Exception::class) |
|
|
|
|
|
|
|
private fun splitPutRule(ruleStr: String, putMap: HashMap<String, String>): String { |
|
|
|
private fun splitPutRule(ruleStr: String, putMap: HashMap<String, String>): String { |
|
|
|
var vRuleStr = ruleStr |
|
|
|
var vRuleStr = ruleStr |
|
|
|
val putMatcher = putPattern.matcher(vRuleStr) |
|
|
|
val putMatcher = putPattern.matcher(vRuleStr) |
|
|
@ -359,7 +350,6 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* 分解规则生成规则列表 |
|
|
|
* 分解规则生成规则列表 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Throws(Exception::class) |
|
|
|
|
|
|
|
fun splitSourceRule(ruleStr: String?, mode: Mode = Mode.Default): List<SourceRule> { |
|
|
|
fun splitSourceRule(ruleStr: String?, mode: Mode = Mode.Default): List<SourceRule> { |
|
|
|
var vRuleStr = ruleStr |
|
|
|
var vRuleStr = ruleStr |
|
|
|
val ruleList = ArrayList<SourceRule>() |
|
|
|
val ruleList = ArrayList<SourceRule>() |
|
|
|