├── .editorconfig
├── .github
├── ISSUE_TEMPLATE
│ ├── --elise---.md
│ ├── bug_report.md
│ └── feature_request.md
└── PULL_REQUEST_TEMPLATE.md
├── .gitignore
├── Elise-client
├── build.gradle
└── src
│ ├── main
│ └── java
│ │ └── site
│ │ └── zido
│ │ └── elise
│ │ └── client
│ │ ├── SpiderBuilder.java
│ │ └── scheduler
│ │ ├── MultiThreadTaskScheduler.java
│ │ └── SyncTaskScheduler.java
│ └── test
│ ├── java
│ └── site
│ │ └── zido
│ │ └── elise
│ │ └── client
│ │ └── SpiderTest.java
│ └── resources
│ └── log4j2.xml
├── Elise-core
├── build.gradle
└── src
│ ├── main
│ └── java
│ │ └── site
│ │ └── zido
│ │ └── elise
│ │ ├── E.java
│ │ ├── Operator.java
│ │ ├── Spider.java
│ │ ├── custom
│ │ ├── Config.java
│ │ ├── ConfigUtils.java
│ │ ├── GlobalConfig.java
│ │ ├── GlobalConfigBuilder.java
│ │ ├── HttpClientConfig.java
│ │ ├── MappedConfig.java
│ │ └── SiteConfig.java
│ │ ├── downloader
│ │ ├── AbstractDownloaderFactory.java
│ │ ├── DefaultDownloaderFactory.java
│ │ ├── DownloadException.java
│ │ ├── Downloader.java
│ │ ├── DownloaderFactory.java
│ │ ├── HtmlUnitDownloader.java
│ │ ├── HtmlUnitDownloaderFacotory.java
│ │ ├── HttpClientDownloader.java
│ │ ├── HttpClientDownloaderFactory.java
│ │ ├── ProxiableDownloader.java
│ │ └── httpclient
│ │ │ ├── CustomRedirectStrategy.java
│ │ │ └── HttpClientHeaderWrapper.java
│ │ ├── events
│ │ ├── EventListener.java
│ │ ├── EventSupport.java
│ │ ├── SingleEventListener.java
│ │ ├── SingleListenerContainer.java
│ │ ├── SingleProcessorEventListener.java
│ │ └── TaskEventListener.java
│ │ ├── http
│ │ ├── Body.java
│ │ ├── Cookie.java
│ │ ├── Header.java
│ │ ├── Http.java
│ │ ├── HttpModel.java
│ │ ├── Pair.java
│ │ ├── Request.java
│ │ ├── RequestBuilder.java
│ │ ├── Response.java
│ │ ├── SimpleHttpClient.java
│ │ └── impl
│ │ │ ├── DefaultBody.java
│ │ │ ├── DefaultCookie.java
│ │ │ ├── DefaultHeader.java
│ │ │ ├── DefaultRequest.java
│ │ │ ├── DefaultResponse.java
│ │ │ └── HttpClientBodyWrapper.java
│ │ ├── processor
│ │ ├── BlankSaver.java
│ │ ├── DefaultResponseProcessor.java
│ │ ├── ListenableResponseProcessor.java
│ │ ├── MemorySaver.java
│ │ ├── ProcessorEventListener.java
│ │ ├── ResponseContextHolder.java
│ │ ├── ResponseHolder.java
│ │ ├── ResponseProcessor.java
│ │ ├── ResultItem.java
│ │ ├── Saver.java
│ │ └── SaverHandler.java
│ │ ├── proxy
│ │ ├── Proxy.java
│ │ ├── ProxyProvider.java
│ │ └── SimpleProxyProvider.java
│ │ ├── scheduler
│ │ ├── AbstractScheduler.java
│ │ ├── CountManager.java
│ │ ├── DefaultMemoryCountManager.java
│ │ ├── DefaultOperator.java
│ │ ├── DuplicationProcessor.java
│ │ ├── HashSetDeduplicationProcessor.java
│ │ ├── MonitorableScheduler.java
│ │ ├── NoDepuplicationProcessor.java
│ │ ├── OperationalTaskScheduler.java
│ │ ├── Seed.java
│ │ └── TaskScheduler.java
│ │ ├── select
│ │ ├── CssSelectHandler.java
│ │ ├── CssSelector.java
│ │ ├── ElementSelector.java
│ │ ├── FieldType.java
│ │ ├── Fragment.java
│ │ ├── HtmlLinkSelector.java
│ │ ├── LinkSelectHandler.java
│ │ ├── ModelExtractor.java
│ │ ├── NumberMatcherSelectHandler.java
│ │ ├── OriginSelectorHandler.java
│ │ ├── Paragraph.java
│ │ ├── RegexSelectHandler.java
│ │ ├── RichType.java
│ │ ├── SelectHandler.java
│ │ ├── SelectorMatchException.java
│ │ ├── SiteMatcherSelectHandler.java
│ │ ├── XpathSelectHandler.java
│ │ └── XpathSelector.java
│ │ ├── task
│ │ ├── DefaultTask.java
│ │ ├── Task.java
│ │ ├── annotations
│ │ │ ├── EliseHelper.java
│ │ │ ├── EliseModel.java
│ │ │ ├── ElisePartition.java
│ │ │ └── EliseTarget.java
│ │ ├── api
│ │ │ ├── DataDescriptor.java
│ │ │ ├── DefaultSelectableResponse.java
│ │ │ ├── ElementSelectable.java
│ │ │ ├── ElementValue.java
│ │ │ ├── HelpDescriptor.java
│ │ │ ├── PartitionDescriptor.java
│ │ │ ├── RepeatMatchException.java
│ │ │ ├── ResponseHandler.java
│ │ │ ├── SelectableResponse.java
│ │ │ ├── Source.java
│ │ │ ├── TargetDescriptor.java
│ │ │ └── Value.java
│ │ └── model
│ │ │ ├── Action.java
│ │ │ ├── Model.java
│ │ │ ├── ModelField.java
│ │ │ └── Partition.java
│ │ └── utils
│ │ ├── ActionUtils.java
│ │ ├── Asserts.java
│ │ ├── EventUtils.java
│ │ ├── HtmlUtils.java
│ │ ├── IdWorker.java
│ │ ├── ModuleNamedDefaultThreadFactory.java
│ │ ├── Safe.java
│ │ ├── StringUtils.java
│ │ ├── SystemClock.java
│ │ ├── UrlUtils.java
│ │ └── ValidateUtils.java
│ └── test
│ ├── java
│ └── site
│ │ └── zido
│ │ └── elise
│ │ ├── task
│ │ └── api
│ │ │ └── DefaultSelectableResponseTest.java
│ │ └── utils
│ │ └── HtmlUtilsTest.java
│ └── resources
│ ├── db.properties
│ ├── log4j2.xml
│ └── task
│ └── api
│ └── model1.json
├── Elise-distributed
├── build.gradle
└── src
│ ├── main
│ └── java
│ │ └── site
│ │ └── zido
│ │ └── elise
│ │ └── distributed
│ │ └── AbstractQueueScheduler.java
│ └── test
│ └── resources
│ └── log4j2.xml
├── Elise-jedis-support
└── build.gradle
├── Elise-kafka-support
├── build.gradle
└── src
│ ├── main
│ ├── java
│ │ └── site
│ │ │ └── zido
│ │ │ └── elise
│ │ │ └── kafka
│ │ │ ├── SpringKafkaTaskScheduler.java
│ │ │ └── pojo
│ │ │ └── Seed.java
│ └── resources
│ │ └── .gitkeep
│ └── test
│ └── java
│ └── .gitkeep
├── Elise-redis-support
├── build.gradle
└── src
│ └── main
│ └── java
│ └── site
│ └── zido
│ └── elise
│ └── support
│ └── redis
│ └── scheduler
│ └── RedisTaskScheduler.java
├── Elise-test-server
├── build.gradle
└── src
│ ├── main
│ ├── java
│ │ └── site
│ │ │ └── zido
│ │ │ └── elise
│ │ │ └── test
│ │ │ ├── Server.java
│ │ │ ├── StaticHandler.java
│ │ │ ├── handlers
│ │ │ └── OneHandler.java
│ │ │ └── utils
│ │ │ ├── ResourcesUtils.java
│ │ │ └── TemplateUtils.java
│ └── resources
│ │ └── log4j2.xml
│ └── test
│ └── java
│ └── site
│ └── zido
│ └── elise
│ └── test
│ └── TestServer.java
├── LICENSE
├── build.gradle
├── docs
├── CNAME
├── CODE_OF_CONDUCT.md
├── CODE_REQUIREMENTS.md
├── CONTRIBUTING.md
├── README.md
├── ROADMAP.md
├── TUTORIAL.md
├── _config.yml
└── elise.png
└── settings.gradle
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 | [*]
3 | charset = utf-8
4 | indent_style = space
5 | indent_size = 4
6 | trim_trailing_whitespace = true
7 | insert_final_newline = true
8 | end_of_line = lf
9 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/--elise---.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: 关于Elise的疑问
3 | about: 提出任何你使用或开发的问题
4 | title: ''
5 | labels: question
6 | assignees: zidoshare
7 |
8 | ---
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: 缺陷反馈
3 | about: 报告缺陷以帮助我们改进
4 | title: ''
5 | labels: bug
6 | assignees: zidoshare
7 |
8 | ---
9 |
10 | ### 描述问题
11 |
12 | 请尽量清晰精准地描述你碰到的问题。
13 |
14 | ### 重现步骤
15 |
16 | 请描述如何重现这个问题:
17 |
18 | 1. Go to '...'
19 | 2. use '...'
20 | 3. See error
21 |
22 | ### 期待的结果
23 |
24 | 请尽量清晰精准地描述你所期待的结果。
25 |
26 | ### 截屏或录像
27 |
28 | 如果可能,请尽量附加截图或录像来描述你遇到的问题。
29 |
30 | ### 其他信息
31 |
32 | 请提供其他附加信息帮助我们诊断问题。
33 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/feature_request.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: 意见或建议
3 | about: 提出你期待的功能特性或者对已有功能的意见或者建议
4 | title: ''
5 | labels: help wanted
6 | assignees: zidoshare
7 |
8 | ---
9 |
10 | ### 你在什么场景下需要该功能?
11 |
12 | 请尽量清晰精准地描述你碰到的问题。
13 |
14 | ### 描述可能的解决方案
15 |
16 | 请尽量清晰精准地描述你期待我们要做的,描述你想到的实现方案。
17 |
18 | ### 描述你认为的候选方案
19 |
20 | 请尽量清晰精准地描述你能接受的候选解决方案。
21 |
22 | ### 其他信息
23 |
24 | 请提供关于该功能建议的其他附加信息。
25 |
--------------------------------------------------------------------------------
/.github/PULL_REQUEST_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | 首先,非常感谢您的贡献!:smile:
2 |
3 | 请确保在提交拉取请求之前检查这些复选框,谢谢!
4 |
5 | * [ ] 请确保提交pull request的分支为`master`分支
6 | * [ ] 请确保已经阅读过[关于代码](../CODE_REQUIREMENTS.md)的所有约定
7 | * [ ] 请确保代码已经经过格式化,与已有代码持有一致的代码风格
8 | * [ ] 在创建拉取请求之前使用`rebase`以保持提交历史记录清除
9 | * [ ] 添加一些描述并为您拉取请求引用相关问题。
10 |
11 | 额外清单:
12 |
13 | **if** *bug处理* **:**
14 |
15 | * [ ] 确保为已修复的错误添加至少一个单元测试
16 |
17 | **elif** *新功能添加* **:**
18 |
19 | * [ ] 文档更新
20 | * [ ] 更新/添加演示以演示新功能。
21 | * [ ] 添加功能的单元测试。
22 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | **/target/
2 |
3 | **/.gitignore
4 | # IntelliJ project files
5 | .idea
6 | *.iml
7 | **/out
8 | html
9 | *.ipr
10 | *.iws
11 |
12 | # Eclipse project files
13 | **/.classpath
14 | **/.project
15 | **/.settings/
16 | **/bin/
17 |
18 | # gradle
19 | .gradle
20 | **/build
21 |
22 | # MacOS
23 | .DS_Store
24 | /repo/
25 | gradle/
26 | gradlew
27 | gradlew.bat
--------------------------------------------------------------------------------
/Elise-client/build.gradle:
--------------------------------------------------------------------------------
1 | description = 'Elise client'
2 | dependencies {
3 | implementation project(':Elise-core')
4 | testImplementation project(':Elise-test-server')
5 | }
6 |
--------------------------------------------------------------------------------
/Elise-client/src/main/java/site/zido/elise/client/scheduler/SyncTaskScheduler.java:
--------------------------------------------------------------------------------
1 | package site.zido.elise.client.scheduler;
2 |
3 | import site.zido.elise.http.Request;
4 | import site.zido.elise.http.Response;
5 | import site.zido.elise.scheduler.AbstractScheduler;
6 | import site.zido.elise.task.Task;
7 |
8 | /**
9 | * 同步任务调度器简单实现
10 | *
11 | * @author zido
12 | */
13 | public class SyncTaskScheduler extends AbstractScheduler {
14 | private boolean start = true;
15 |
16 | @Override
17 | protected void pushWhenNoDuplicate(Task task, Request request) {
18 | if (!start) {
19 | return;
20 | }
21 | Response response = super.onDownload(task, request);
22 | super.onProcess(task, request, response);
23 | }
24 |
25 | @Override
26 | public void cancel(boolean ifRunning) {
27 | start = false;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/Elise-client/src/test/resources/log4j2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] [%level] %logger{36} - %msg%n
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/Elise-core/build.gradle:
--------------------------------------------------------------------------------
1 | description = 'Elise-core'
2 | dependencies {
3 | compile(group: 'com.virjar', name: 'sipsoup', version: '1.6') {
4 | exclude(module: 'logback-core')
5 | exclude(module: 'logback-classic')
6 | exclude(module: 'log4j')
7 | exclude(module: 'slf4j-log4j12')
8 | }
9 | compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.3'
10 | compile group: 'org.jsoup', name: 'jsoup', version: '1.10.3'
11 | compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
12 | compile group: 'net.sourceforge.htmlunit', name: 'htmlunit', version: '2.30'
13 | compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.9.8'
14 | compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.9.10.4'
15 | testCompile group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: '2.11.0'
16 | testCompile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.11.0'
17 | testCompile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.11.0'
18 | testCompile group: 'junit', name: 'junit', version: '4.12'
19 | }
20 |
--------------------------------------------------------------------------------
/Elise-core/src/main/java/site/zido/elise/E.java:
--------------------------------------------------------------------------------
1 | package site.zido.elise;
2 |
3 | import java.nio.charset.Charset;
4 |
5 | /**
6 | * this class provide some constants
7 | *
8 | * @author zido
9 | */
10 | public class E {
11 | /**
12 | * The constant UTF_8.
13 | */
14 | public static final Charset UTF_8 = Charset.forName("utf-8");
15 | /**
16 | * The constant ASCII.
17 | */
18 | public static final Charset ASCII = Charset.forName("US-ASCII");
19 | /**
20 | * The constant ISO_8859_1.
21 | */
22 | public static final Charset ISO_8859_1 = Charset.forName("ISO-8859-1");
23 |
24 | /**
25 | * The type Status code.
26 | *
27 | * @author zido
28 | */
29 | public static class StatusCode {
30 | /**
31 | * The constant CODE_DOWNLOAD_ERROR.
32 | */
33 | public static final int CODE_DOWNLOAD_ERROR = -1;
34 | /**
35 | * The constant CODE_200.
36 | */
37 | public static final int CODE_200 = 200;
38 | }
39 |
40 | public static class Action {
41 | public static final String MATCH_LINK = "match_link";
42 | public static final String MATCH_NUMBER = "match_number";
43 | public static final String LINK_SELECTOR = "select_link";
44 | public static final String SELECT_URL = "select_url";
45 | public static final String SELECT_ORIGIN = "select_origin";
46 | public static final String CSS_SELECTOR = "css_selector";
47 | public static final String XPATH_SELECTOR = "xpath_selector";
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/Elise-core/src/main/java/site/zido/elise/Operator.java:
--------------------------------------------------------------------------------
1 | package site.zido.elise;
2 |
3 | import site.zido.elise.events.SingleEventListener;
4 | import site.zido.elise.http.Request;
5 |
6 | /**
7 | * The interface Operator.
8 | *
9 | * @author zido
10 | */
11 | public interface Operator {
12 | /**
13 | * Cancel task of the operator.The Spider will no longer accept any new requests of the task.
14 | *
15 | * @param ifRunning If true,the task will wait until the existing request is completed before ending the crawler. and else,will end all request immediately.
16 | * @return the operator
17 | */
18 | Operator cancel(boolean ifRunning);
19 |
20 | /**
21 | * Pause task of the operator.And Spider will no long accept any new requests of the task.
22 | *
23 | * @return the boolean
24 | */
25 | Operator pause();
26 |
27 | /**
28 | * recover task of the operator.And the spider will re-accept the new request of the task.
29 | *
30 | * @return the operator
31 | */
32 | Operator recover();
33 |
34 | /**
35 | * waiting until the task success or cancel
36 | *
37 | * @return this operator
38 | * @throws InterruptedException thread interrupted
39 | */
40 | Operator block() throws InterruptedException;
41 |
42 | /**
43 | * Add url operator.
44 | *
45 | * @param url the url
46 | * @return the operator
47 | */
48 | Operator execute(String... url);
49 |
50 | /**
51 | * Execute operator.
52 | *
53 | * @param request the request
54 | * @return the operator
55 | */
56 | Operator execute(Request request);
57 |
58 | /**
59 | * Add event listener.
60 | *
61 | * @param listener the listener
62 | * @return the operator
63 | */
64 | Operator addEventListener(SingleEventListener listener);
65 | }
66 |
--------------------------------------------------------------------------------
/Elise-core/src/main/java/site/zido/elise/Spider.java:
--------------------------------------------------------------------------------
1 | package site.zido.elise;
2 |
3 | import site.zido.elise.custom.Config;
4 | import site.zido.elise.events.EventSupport;
5 | import site.zido.elise.task.api.ResponseHandler;
6 |
7 | /**
8 | * The Spider Interface.
9 | *
10 | * Is the core of the operation of the entire crawler.
11 | *
12 | * @author zido
13 | */
14 | public interface Spider extends EventSupport {
15 |
16 | /**
17 | * create a new task by response handler api.
18 | *
19 | * @param handler the handler
20 | * @param config the config
21 | * @return the operator
22 | */
23 | Operator of(ResponseHandler handler, Config config);
24 |
25 | /**
26 | * create a new task by response handler api.
27 | *
28 | * @param handler the handler
29 | * @return the operator
30 | */
31 | default Operator of(ResponseHandler handler) {
32 | return of(handler, null);
33 | }
34 |
35 | /**
36 | * create a new task by model class
37 | *
38 | * @param modelClass the model class
39 | * @return the operator
40 | */
41 | default Operator of(Class> modelClass) {
42 | return of(modelClass, null);
43 | }
44 |
45 | /**
46 | * create a new task by model class and config
47 | *
48 | * @param modelClass the model class
49 | * @param config the config
50 | * @return the operator
51 | */
52 | Operator of(Class> modelClass, Config config);
53 |
54 |
55 | /**
56 | * Cancel the spider.The Spider will no longer accept any new tasks/requests.
57 | *
58 | * @param ifRunning If true,the Spider will wait until the existing task is completed before ending the crawler. and else,will end all tasks immediately.
59 | */
60 | void cancel(boolean ifRunning);
61 |
62 | /**
63 | * Pause the spider.
64 | *
65 | * @return the boolean
66 | */
67 | boolean pause();
68 |
69 | /**
70 | * Recover the spider.
71 | */
72 | void recover();
73 | }
74 |
--------------------------------------------------------------------------------
/Elise-core/src/main/java/site/zido/elise/custom/Config.java:
--------------------------------------------------------------------------------
1 | package site.zido.elise.custom;
2 |
3 | import java.io.IOException;
4 | import java.io.InputStream;
5 | import java.io.Reader;
6 | import java.util.Map;
7 |
8 | /**
9 | * the config interface
10 | *
11 | * @author zido
12 | */
13 | public interface Config extends Map {
14 |
15 | /**
16 | * parse from reader.
17 | *
18 | * @param reader the reader
19 | * @throws IOException the io exception
20 | */
21 | void from(Reader reader) throws IOException;
22 |
23 | /**
24 | * parse from input stream
25 | *
26 | * @param in the in
27 | * @throws IOException the io exception
28 | */
29 | void from(InputStream in) throws IOException;
30 |
31 | /**
32 | * set the key value pair
33 | *
34 | * @param key the key
35 | * @param value the value
36 | */
37 | void set(String key, Object value);
38 |
39 | /**
40 | * get the value by key
41 | *
42 | * @param the type parameter
43 | * @param key the key
44 | * @return the t
45 | */
46 | T get(String key);
47 | }
48 |
--------------------------------------------------------------------------------
/Elise-core/src/main/java/site/zido/elise/custom/ConfigUtils.java:
--------------------------------------------------------------------------------
1 | package site.zido.elise.custom;
2 |
3 | import java.util.HashMap;
4 | import java.util.Map;
5 |
6 | /**
7 | * The type Config utils.
8 | *
9 | * @author zido
10 | */
11 | public class ConfigUtils {
12 | private ConfigUtils() {
13 | }
14 |
15 | /**
16 | * Merge config t.
17 | *
18 | * @param the type parameter
19 | * @param key the key
20 | * @param config the config
21 | * @return the t
22 | */
23 | public static T mergeConfig(String key, Config... config) {
24 | T result = null;
25 | for (Config c : config) {
26 | final T o = c.get(key);
27 | if (o != null) {
28 | result = o;
29 | }
30 | }
31 | return result;
32 | }
33 |
34 | /**
35 | * Merge config config.
36 | *
37 | * @param config the config
38 | * @return the config
39 | */
40 | public static Config mergeConfig(Config... config) {
41 | Map result = new HashMap<>();
42 | for (Config c : config) {
43 | if (c != null) {
44 | for (String s : c.keySet()) {
45 | final Object value = c.get(s);
46 | if (value != null) {
47 | result.put(s, value);
48 | }
49 | }
50 | }
51 | }
52 | return new MappedConfig(result);
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/Elise-core/src/main/java/site/zido/elise/custom/GlobalConfig.java:
--------------------------------------------------------------------------------
1 | package site.zido.elise.custom;
2 |
3 | import site.zido.elise.http.Header;
4 | import site.zido.elise.proxy.Proxy;
5 |
6 | import java.util.LinkedList;
7 | import java.util.List;
8 | import java.util.Map;
9 | import java.util.Objects;
10 |
11 | /**
12 | * The type Global config.
13 | *
14 | * @author zido
15 | */
16 | public class GlobalConfig extends MappedConfig {
17 | /**
18 | * The constant KEY_USER_AGENT.
19 | */
20 | public static final String KEY_USER_AGENT = "userAgent";
21 | /**
22 | * The constant KEY_COOKIE.
23 | */
24 | public static final String KEY_COOKIE = "cookie";
25 | /**
26 | * The constant KEY_CHARSET.
27 | */
28 | public static final String KEY_CHARSET = "charset";
29 | /**
30 | * The constant KEY_SLEEP_TIME.
31 | */
32 | public static final String KEY_SLEEP_TIME = "sleepTime";
33 | /**
34 | * The number of times the request was retried when the download failed
35 | */
36 | public static final String KEY_RETRY_TIMES = "retryTimes";
37 | /**
38 | * The constant KEY_TIME_OUT.
39 | */
40 | public static final String KEY_TIME_OUT = "outTime";
41 | /**
42 | * The constant KEY_DOWNLOAD_MODE.
43 | */
44 | public static final String KEY_DOWNLOAD_MODE = "downloadMode";
45 | /**
46 | * The constant KEY_SUCCESS_CODE.
47 | */
48 | public static final String KEY_SUCCESS_CODE = "successCode";
49 | /**
50 | * The constant KEY_DISABLE_COOKIE.
51 | */
52 | public static final String KEY_DISABLE_COOKIE = "disableCookie";
53 | /**
54 | * The constant KEY_HEADERS.
55 | */
56 | public static final String KEY_HEADERS = "headers";
57 | /**
58 | * The number of retries that were added to the task scheduler when the download failed
59 | */
60 | public static final String KEY_SCHEDULE_RETRY_TIMES = "scheduleRetryTimes";
61 | /**
62 | * The constant KEY_POOL_SIZE.
63 | */
64 | public static final String KEY_POOL_SIZE = "poolSize";
65 | /**
66 | * The constant KEY_USE_GZIP.
67 | */
68 | public static final String KEY_USE_GZIP = "useGzip";
69 | /**
70 | * The constant KEY_PROXY.
71 | */
72 | public static final String KEY_PROXY = "proxy";
73 | private static final List EMPTY_HEADERS = new LinkedList<>();
74 | private static final long serialVersionUID = -6234664119002484979L;
75 |
76 | /**
77 | * Instantiates a new Global config.
78 | */
79 | public GlobalConfig() {
80 | }
81 |
82 | /**
83 | * Instantiates a new Global config.
84 | *
85 | * @param config the config
86 | */
87 | public GlobalConfig(Map config) {
88 | super(config);
89 | }
90 |
91 | /**
92 | * Gets user agent.
93 | *
94 | * @return the user agent
95 | */
96 | public String getUserAgent() {
97 | return get(KEY_USER_AGENT);
98 | }
99 |
100 | /**
101 | * Gets cookies.
102 | *
103 | * @return the cookies
104 | */
105 | public Map getCookies() {
106 | return get(KEY_COOKIE);
107 | }
108 |
109 | /**
110 | * Gets charset.
111 | *
112 | * @return the charset
113 | */
114 | public String getCharset() {
115 | return get(KEY_CHARSET);
116 | }
117 |
118 | /**
119 | * Gets disable cookie.
120 | *
121 | * @return the disable cookie
122 | */
123 | public boolean getDisableCookie() {
124 | return (boolean) get(KEY_DISABLE_COOKIE);
125 | }
126 |
127 | @Override
128 | public boolean equals(Object o) {
129 | if (!(o instanceof Map)) {
130 | return false;
131 | }
132 | Object otherValue;
133 | for (String s : this.keySet()) {
134 | otherValue = ((Map) o).get(s);
135 | if (!Objects.equals(get(s), otherValue)) {
136 | return false;
137 | }
138 | }
139 | return true;
140 | }
141 |
142 | /**
143 | * Gets headers.
144 | *
145 | * @return the headers
146 | */
147 | public List getHeaders() {
148 | return get(KEY_HEADERS);
149 | }
150 |
151 | /**
152 | * Gets use gzip.
153 | *
154 | * @return the use gzip
155 | */
156 | public boolean getUseGzip() {
157 | return (boolean) get(KEY_USE_GZIP);
158 | }
159 |
160 | /**
161 | * Gets timeout.
162 | *
163 | * @return the timeout
164 | */
165 | public int getTimeout() {
166 | return (int) get(KEY_TIME_OUT);
167 | }
168 |
169 | /**
170 | * Gets retry times.
171 | *
172 | * @return the retry times
173 | */
174 | public int getRetryTimes() {
175 | return (int) get(KEY_RETRY_TIMES);
176 | }
177 |
178 | /**
179 | * Gets proxy.
180 | *
181 | * @return the proxy
182 | */
183 | public Proxy getProxy() {
184 | return get(KEY_PROXY);
185 | }
186 |
187 | }
188 |
--------------------------------------------------------------------------------
/Elise-core/src/main/java/site/zido/elise/custom/HttpClientConfig.java:
--------------------------------------------------------------------------------
1 | package site.zido.elise.custom;
2 |
3 | import java.util.Map;
4 |
5 | /**
6 | * The type Http client config.
7 | *
8 | * @author zido
9 | */
10 | public class HttpClientConfig extends GlobalConfig {
11 | private static final long serialVersionUID = -7610251519485407931L;
12 |
13 | /**
14 | * Instantiates a new Http client config.
15 | */
16 | public HttpClientConfig() {
17 | }
18 |
19 | /**
20 | * Instantiates a new Http client config.
21 | *
22 | * @param config the config
23 | */
24 | public HttpClientConfig(Map config) {
25 | super(config);
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/Elise-core/src/main/java/site/zido/elise/custom/MappedConfig.java:
--------------------------------------------------------------------------------
1 | package site.zido.elise.custom;
2 |
3 | import site.zido.elise.utils.Asserts;
4 |
5 | import java.io.IOException;
6 | import java.io.InputStream;
7 | import java.io.Reader;
8 | import java.util.HashMap;
9 | import java.util.Map;
10 | import java.util.Properties;
11 |
12 | /**
13 | * The type Mapped config.
14 | *
15 | * @author zido
16 | */
17 | public class MappedConfig extends HashMap implements Config {
18 | private static final long serialVersionUID = 8315976702547630336L;
19 |
20 | /**
21 | * Instantiates a new Mapped config.
22 | */
23 | public MappedConfig() {
24 | }
25 |
26 | /**
27 | * Instantiates a new Mapped config.
28 | *
29 | * @param map the map
30 | */
31 | public MappedConfig(Map map) {
32 | super(map);
33 | }
34 |
35 | @Override
36 | public void from(Reader reader) throws IOException {
37 | Asserts.notNull(reader, "can't read config from a null reader");
38 | final Properties props = new Properties();
39 | try {
40 | props.load(reader);
41 | } finally {
42 | reader.close();
43 | }
44 | for (Entry