Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
gedoor committed Mar 10, 2019
1 parent 8162119 commit a86a1d9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -129,12 +129,12 @@ private AnalyzeByJSonPath getAnalyzeByJSonPath() {
return analyzeByJSonPath;
}

public List<String> getStringList(String rule) {
public List<String> getStringList(String rule) throws ScriptException {
return getStringList(rule, null);
}

@SuppressWarnings("unchecked")
public List<String> getStringList(String ruleStr, String baseUrl) {
public List<String> getStringList(String ruleStr, String baseUrl) throws ScriptException {
Object result = null;
List<SourceRule> ruleList = splitSourceRule(ruleStr);
for (SourceRule rule : ruleList) {
Expand Down Expand Up @@ -167,11 +167,11 @@ public List<String> getStringList(String ruleStr, String baseUrl) {
return (List<String>) 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;
}
Expand Down Expand Up @@ -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<SourceRule> ruleList = splitSourceRule(ruleStr);
Expand All @@ -228,7 +228,7 @@ public AnalyzeCollection getElements(String ruleStr) {
return collection;
}

private void analyzeVariable(Map<String, String> putVariable) {
private void analyzeVariable(Map<String, String> putVariable) throws ScriptException {
for (Map.Entry<String, String> entry : putVariable.entrySet()) {
if (book != null) {
book.putVariable(entry.getKey(), getString(entry.getValue()));
Expand Down Expand Up @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import java.util.List;
import java.util.Map;

import javax.script.ScriptException;

import io.reactivex.Observable;
import retrofit2.Response;

Expand Down Expand Up @@ -97,7 +99,7 @@ Observable<List<ChapterListBean>> analyzeChapterList(final String s, final BookS
});
}

private WebChapterBean<List<ChapterListBean>> analyzeChapterList(String s, String chapterUrl, String ruleChapterList) {
private WebChapterBean<List<ChapterListBean>> analyzeChapterList(String s, String chapterUrl, String ruleChapterList) throws ScriptException {
List<ChapterListBean> chapterBeans = new ArrayList<>();
List<String> nextUrlList = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import java.util.List;
import java.util.Map;

import javax.script.ScriptException;

import io.reactivex.Observable;
import retrofit2.Response;

Expand Down Expand Up @@ -96,7 +98,7 @@ Observable<BookContentBean> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import java.util.Collections;
import java.util.List;

import javax.script.ScriptException;

import io.reactivex.Observable;
import retrofit2.Response;

Expand Down Expand Up @@ -98,7 +100,7 @@ Observable<List<SearchBookBean>> analyzeSearchBook(final Response<String> 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());
Expand All @@ -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());
Expand Down

0 comments on commit a86a1d9

Please sign in to comment.