us.codecraft.webmagic.handler.CompositePageProcessor Maven / Gradle / Ivy
The newest version!
package us.codecraft.webmagic.handler;
import us.codecraft.webmagic.Page;
import us.codecraft.webmagic.Site;
import us.codecraft.webmagic.processor.PageProcessor;
import java.util.ArrayList;
import java.util.List;
/**
* @author [email protected]
*/
public class CompositePageProcessor implements PageProcessor {
private Site site;
private List subPageProcessors = new ArrayList();
public CompositePageProcessor(Site site) {
this.site = site;
}
@Override
public void process(Page page) {
for (SubPageProcessor subPageProcessor : subPageProcessors) {
if (subPageProcessor.match(page.getRequest())) {
SubPageProcessor.MatchOther matchOtherProcessorProcessor = subPageProcessor.processPage(page);
if (matchOtherProcessorProcessor == null || matchOtherProcessorProcessor != SubPageProcessor.MatchOther.YES) {
return;
}
}
}
}
public CompositePageProcessor setSite(Site site) {
this.site = site;
return this;
}
public CompositePageProcessor addSubPageProcessor(SubPageProcessor subPageProcessor) {
this.subPageProcessors.add(subPageProcessor);
return this;
}
public CompositePageProcessor setSubPageProcessors(SubPageProcessor... subPageProcessors) {
this.subPageProcessors = new ArrayList();
for (SubPageProcessor subPageProcessor : subPageProcessors) {
this.subPageProcessors.add(subPageProcessor);
}
return this;
}
@Override
public Site getSite() {
return site;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy