All Downloads are FREE. Search and download functionalities are using the official Maven repository.

nl.siegmann.epublib.epub.BookProcessorPipeline Maven / Gradle / Ivy

The newest version!
package nl.siegmann.epublib.epub;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import nl.siegmann.epublib.domain.Book;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * A book processor that combines several other bookprocessors
 * 
 * Fixes coverpage/coverimage.
 * Cleans up the XHTML.
 * 
 * @author paul.siegmann
 *
 */
public class BookProcessorPipeline implements BookProcessor {

	private Logger log = LoggerFactory.getLogger(BookProcessorPipeline.class);
	private List bookProcessors;

	public BookProcessorPipeline() {
		this(null);
	}
	
	public BookProcessorPipeline(List bookProcessingPipeline) {
		this.bookProcessors = bookProcessingPipeline;
	}

	
	@Override
	public Book processBook(Book book) {
		if (bookProcessors == null) {
			return book;
		}
		for(BookProcessor bookProcessor: bookProcessors) {
			try {
				book = bookProcessor.processBook(book);
			} catch(Exception e) {
				log.error(e.getMessage(), e);
			}
		}
		return book;
	}

	public void addBookProcessor(BookProcessor bookProcessor) {
		if (this.bookProcessors == null) {
			bookProcessors = new ArrayList();
		}
		this.bookProcessors.add(bookProcessor);
	}

	public void addBookProcessors(Collection bookProcessors) {
		if (this.bookProcessors == null) {
			this.bookProcessors = new ArrayList();
		}
		this.bookProcessors.addAll(bookProcessors);
	}
	
	
	public List getBookProcessors() {
		return bookProcessors;
	}


	public void setBookProcessingPipeline(List bookProcessingPipeline) {
		this.bookProcessors = bookProcessingPipeline;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy