Browse Source

上传文件至 'project/controller'

main
HuangZhikai 3 weeks ago
parent
commit
5d012ad0ef
  1. 45
      project/controller/CrawlerController.java

45
project/controller/CrawlerController.java

@ -0,0 +1,45 @@
package com.crawler.controller;
import com.crawler.crawler.Crawler;
import com.crawler.exception.handler.ExceptionHandlerFactory;
import com.crawler.model.CrawlerConfig;
import com.crawler.model.CrawlerData;
import com.crawler.view.CrawlerView;
import java.util.List;
public class CrawlerController {
private Crawler crawler;
private CrawlerView view;
private ExceptionHandlerFactory exceptionHandlerFactory;
public CrawlerController(Crawler crawler) {
this.crawler = crawler;
this.view = new CrawlerView();
this.exceptionHandlerFactory = ExceptionHandlerFactory.getInstance();
}
public void setConfig(CrawlerConfig config) {
crawler.setConfig(config);
}
public void execute() {
view.showStartMessage(crawler.getCrawlerName());
try {
List<CrawlerData> dataList = crawler.crawl();
view.showData(dataList);
view.showSuccessMessage(dataList.size());
if (!dataList.isEmpty()) {
com.crawler.command.CacheCommand.saveDataWithPrompt(dataList, crawler.getCrawlerName());
}
} catch (Exception e) {
exceptionHandlerFactory.handleException(e, view);
}
}
public List<CrawlerData> crawl() {
return crawler.crawl();
}
}
Loading…
Cancel
Save