if(StringUtils.isBlank(inputLocation) || StringUtils.isBlank(outLocation)) {
usage();
}
BookProcessorPipeline epubCleaner = new DefaultBookProcessorPipeline();
epubCleaner.addBookProcessors(createBookProcessors(bookProcessorClassNames));
EpubWriter epubWriter = new EpubWriter(epubCleaner);
if(! StringUtils.isBlank(xslFile)) {
epubCleaner.addBookProcessor(new XslBookProcessor(xslFile));
}
if (StringUtils.isBlank(inputEncoding)) {
inputEncoding = Constants.CHARACTER_ENCODING;
}
Book book;
if("chm".equals(type)) {
book = ChmParser.parseChm(VFSUtil.resolveFileObject(inputLocation), inputEncoding);
} else if ("epub".equals(type)) {
book = new EpubReader().readEpub(VFSUtil.resolveInputStream(inputLocation), inputEncoding);
} else {
book = FilesetBookCreator.createBookFromDirectory(VFSUtil.resolveFileObject(inputLocation), inputEncoding);
}
if(StringUtils.isNotBlank(coverImage)) {
// book.getResourceByHref(book.getCoverImage());
book.setCoverImage(new Resource(VFSUtil.resolveInputStream(coverImage), coverImage));
epubCleaner.getBookProcessors().add(new CoverpageBookProcessor());
}
if(StringUtils.isNotBlank(title)) {
List<String> titles = new ArrayList<String>();
titles.add(title);
book.getMetadata().setTitles(titles);
}
if(StringUtils.isNotBlank(isbn)) {
book.getMetadata().addIdentifier(new Identifier(Identifier.Scheme.ISBN, isbn));
}
initAuthors(authorNames, book);
OutputStream result;
try {
result = VFS.getManager().resolveFile(outLocation).getContent().getOutputStream();
} catch(FileSystemException e) {
result = new FileOutputStream(outLocation);
}
epubWriter.write(book, result);
}