You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
1.2 KiB
34 lines
1.2 KiB
package com.example.datacollect.strategy;
|
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
public class StrategyFactory {
|
|
private static final Logger logger = LoggerFactory.getLogger(StrategyFactory.class);
|
|
private final List<CrawlStrategy> strategies = new ArrayList<>();
|
|
|
|
public StrategyFactory() {
|
|
strategies.add(new HnuNewsStrategy());
|
|
strategies.add(new BlogStrategy());
|
|
strategies.add(new NewsStrategy());
|
|
logger.info("StrategyFactory initialized with {} strategies", strategies.size());
|
|
}
|
|
|
|
public CrawlStrategy getStrategy(String url) {
|
|
for (CrawlStrategy s : strategies) {
|
|
if (s.supports(url)) {
|
|
logger.debug("Found strategy for URL: {} -> {}", url, s.getClass().getSimpleName());
|
|
return s;
|
|
}
|
|
}
|
|
logger.warn("No strategy found for URL: {}", url);
|
|
return null;
|
|
}
|
|
|
|
public void register(CrawlStrategy strategy) {
|
|
strategies.add(strategy);
|
|
logger.info("Registered new strategy: {}", strategy.getClass().getSimpleName());
|
|
}
|
|
}
|
|
|