diff --git a/app/src/main/java/com/kunfei/bookshelf/model/analyzeRule/AnalyzeRule.java b/app/src/main/java/com/kunfei/bookshelf/model/analyzeRule/AnalyzeRule.java index da34bbdeac..8c86474b94 100644 --- a/app/src/main/java/com/kunfei/bookshelf/model/analyzeRule/AnalyzeRule.java +++ b/app/src/main/java/com/kunfei/bookshelf/model/analyzeRule/AnalyzeRule.java @@ -109,9 +109,9 @@ private AnalyzeByJSoup getAnalyzeByJSoup() { private AnalyzeByJSonPath getAnalyzeByJSonPath(Object o) { if (o != null) { if (o instanceof String) { - return new AnalyzeByJSonPath().parse(_object.toString()); + return new AnalyzeByJSonPath().parse(o.toString()); } - return new AnalyzeByJSonPath().parse(_object); + return new AnalyzeByJSonPath().parse(o); } return getAnalyzeByJSonPath(); } @@ -129,12 +129,12 @@ private AnalyzeByJSonPath getAnalyzeByJSonPath() { return analyzeByJSonPath; } - public List getStringList(String rule) { + public List getStringList(String rule) throws ScriptException { return getStringList(rule, null); } @SuppressWarnings("unchecked") - public List getStringList(String ruleStr, String baseUrl) { + public List getStringList(String ruleStr, String baseUrl) throws ScriptException { Object result = null; List ruleList = splitSourceRule(ruleStr); for (SourceRule rule : ruleList) { @@ -167,11 +167,11 @@ public List getStringList(String ruleStr, String baseUrl) { return (List) result; } - public String getString(String rule) { + public String getString(String rule) throws ScriptException { return getString(rule, null); } - public String getString(String ruleStr, String _baseUrl) { + public String getString(String ruleStr, String _baseUrl) throws ScriptException { if (StringUtils.isTrimEmpty(ruleStr)) { return null; } @@ -205,7 +205,7 @@ public String getString(String ruleStr, String _baseUrl) { return result; } - public AnalyzeCollection getElements(String ruleStr) { + public AnalyzeCollection getElements(String ruleStr) throws ScriptException { Object result = null; AnalyzeCollection collection = null; List ruleList = splitSourceRule(ruleStr); @@ -228,7 +228,7 @@ public AnalyzeCollection getElements(String ruleStr) { return collection; } - private void analyzeVariable(Map putVariable) { + private void analyzeVariable(Map putVariable) throws ScriptException { for (Map.Entry entry : putVariable.entrySet()) { if (book != null) { book.putVariable(entry.getKey(), getString(entry.getValue())); @@ -329,17 +329,12 @@ private static class EngineHelper { private static final ScriptEngine INSTANCE = new ScriptEngineManager().getEngineByName("rhino"); } - private Object evalJS(String jsStr, Object result, String baseUrl) { + private Object evalJS(String jsStr, Object result, String baseUrl) throws ScriptException { SimpleBindings bindings = new SimpleBindings(); bindings.put("java", this); bindings.put("result", result); bindings.put("baseUrl", baseUrl); - try { - result = EngineHelper.INSTANCE.eval(jsStr, bindings); - } catch (ScriptException e) { - return e.getLocalizedMessage(); - } - return result; + return EngineHelper.INSTANCE.eval(jsStr, bindings); } /** diff --git a/app/src/main/java/com/kunfei/bookshelf/model/content/BookChapter.java b/app/src/main/java/com/kunfei/bookshelf/model/content/BookChapter.java index 990b3077ed..85d42ee245 100644 --- a/app/src/main/java/com/kunfei/bookshelf/model/content/BookChapter.java +++ b/app/src/main/java/com/kunfei/bookshelf/model/content/BookChapter.java @@ -16,6 +16,8 @@ import java.util.List; import java.util.Map; +import javax.script.ScriptException; + import io.reactivex.Observable; import retrofit2.Response; @@ -97,7 +99,7 @@ Observable> analyzeChapterList(final String s, final BookS }); } - private WebChapterBean> analyzeChapterList(String s, String chapterUrl, String ruleChapterList) { + private WebChapterBean> analyzeChapterList(String s, String chapterUrl, String ruleChapterList) throws ScriptException { List chapterBeans = new ArrayList<>(); List nextUrlList = new ArrayList<>(); diff --git a/app/src/main/java/com/kunfei/bookshelf/model/content/BookContent.java b/app/src/main/java/com/kunfei/bookshelf/model/content/BookContent.java index 177f2ee91e..e62e993c49 100644 --- a/app/src/main/java/com/kunfei/bookshelf/model/content/BookContent.java +++ b/app/src/main/java/com/kunfei/bookshelf/model/content/BookContent.java @@ -19,6 +19,8 @@ import java.util.List; import java.util.Map; +import javax.script.ScriptException; + import io.reactivex.Observable; import retrofit2.Response; @@ -96,7 +98,7 @@ Observable analyzeBookContent(final String s, final BaseChapter }); } - private WebContentBean analyzeBookContent(final String s, final String chapterUrl) { + private WebContentBean analyzeBookContent(final String s, final String chapterUrl) throws ScriptException { WebContentBean webContentBean = new WebContentBean(); AnalyzeRule analyzer = new AnalyzeRule(null); diff --git a/app/src/main/java/com/kunfei/bookshelf/model/content/BookList.java b/app/src/main/java/com/kunfei/bookshelf/model/content/BookList.java index fc832ff16f..6addf7426d 100644 --- a/app/src/main/java/com/kunfei/bookshelf/model/content/BookList.java +++ b/app/src/main/java/com/kunfei/bookshelf/model/content/BookList.java @@ -13,6 +13,8 @@ import java.util.Collections; import java.util.List; +import javax.script.ScriptException; + import io.reactivex.Observable; import retrofit2.Response; @@ -98,7 +100,7 @@ Observable> analyzeSearchBook(final Response respon }); } - private SearchBookBean getItem(AnalyzeRule analyzer, String baseUrl) { + private SearchBookBean getItem(AnalyzeRule analyzer, String baseUrl) throws ScriptException { SearchBookBean item = new SearchBookBean(); analyzer.setBook(item); String bookName = analyzer.getString(bookSourceBean.getRuleBookName()); @@ -116,7 +118,7 @@ private SearchBookBean getItem(AnalyzeRule analyzer, String baseUrl) { return null; } - private SearchBookBean getItemInList(AnalyzeRule analyzer, String baseUrl) { + private SearchBookBean getItemInList(AnalyzeRule analyzer, String baseUrl) throws ScriptException { SearchBookBean item = new SearchBookBean(); analyzer.setBook(item); String bookName = analyzer.getString(bookSourceBean.getRuleSearchName());