Browse Source

删除 'project/java-cli/src/main/java/com/example/datacollect/controller/CrawlerController.java'

main
LeiJuntao 3 weeks ago
parent
commit
5fc2fe3cb9
  1. 82
      project/java-cli/src/main/java/com/example/datacollect/controller/CrawlerController.java

82
project/java-cli/src/main/java/com/example/datacollect/controller/CrawlerController.java

@ -1,82 +0,0 @@
package com.example.datacollect.controller;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.example.datacollect.command.Command;
import com.example.datacollect.command.CrawlCommand;
import com.example.datacollect.command.ExitCommand;
import com.example.datacollect.command.HelpCommand;
import com.example.datacollect.command.HistoryCommand;
import com.example.datacollect.command.ListCommand;
import com.example.datacollect.command.LoadCommand;
import com.example.datacollect.command.SaveCommand;
import com.example.datacollect.repository.ArticleRepository;
import com.example.datacollect.strategy.StrategyFactory;
import com.example.datacollect.view.ConsoleView;
public class CrawlerController {
private static final Logger logger = LoggerFactory.getLogger(CrawlerController.class);
private final Map<String, Command> commands = new HashMap<>();
private final Map<String, String> aliases = new HashMap<>();
private final ConsoleView view;
private final ArticleRepository repository;
private final List<String> history = new ArrayList<>();
public CrawlerController(ConsoleView view, ArticleRepository repository, StrategyFactory strategyFactory) {
this.view = view;
this.repository = repository;
register(new HelpCommand(view));
register(new ListCommand(view));
register(new CrawlCommand(view, strategyFactory));
register(new SaveCommand(view));
register(new LoadCommand(view));
register(new ExitCommand(view));
register(new HistoryCommand(view, history));
registerAlias("c", "crawl");
logger.info("CrawlerController initialized with {} commands", commands.size());
}
private void register(Command command) {
commands.put(command.getName(), command);
logger.debug("Registered command: {}", command.getName());
}
private void registerAlias(String alias, String commandName) {
aliases.put(alias, commandName);
logger.debug("Registered alias: {} -> {}", alias, commandName);
}
public void handle(String input) {
String text = input == null ? "" : input.trim();
if (text.isEmpty()) {
return;
}
history.add(text);
logger.info("Received command: {}", text);
String[] args = text.split("\\s+");
String cmdName = args[0].toLowerCase();
if (aliases.containsKey(cmdName)) {
String originalCmd = cmdName;
cmdName = aliases.get(cmdName);
logger.debug("Resolved alias {} to command {}", originalCmd, cmdName);
}
Command command = commands.get(cmdName);
if (command == null) {
view.printError("Unknown command: " + cmdName);
logger.warn("Unknown command received: {}", cmdName);
return;
}
command.execute(args, repository);
}
}
Loading…
Cancel
Save