}
public void generate(Book book, File directory) throws IOException {
ResourceManipulatorFactory htmlResourceManipulatorFactory = new HtmlResourceManipulatorFactory();
TubainaHtmlDir bookRoot = new TubainaHtmlIO(templateDir, htmlResourceManipulatorFactory)
.createTubainaDir(directory, book);
List<String> dirTree = createDirTree(book, directory);
StringBuffer toc = new BookToTOC().generateTOC(book, cfg, dirTree, parser);
bookRoot.writeIndex(fixPaths(toc));
int chapterIndex = 1;
int currentDir = 1;
for (Chapter chapter : book.getChapters()) {
int curdir = currentDir++;
StringBuffer chapterText = new ChapterToString(parser, cfg, dirTree, ifdefs).generateChapter(
book, chapter, chapterIndex, curdir);
bookRoot.cd(Utilities.toDirectoryName(null, chapter.getTitle())).writeIndex(
fixPaths(chapterText)).writeResources(chapter.getResources());
chapterIndex++;
}
if (shouldValidateXHTML) {
validateXHTML(directory, dirTree);
}
Map<String, Integer> indexes = new TreeMap<String, Integer>(String.CASE_INSENSITIVE_ORDER);
StringBuffer index = new IndexToString(dirTree, cfg).createFlatIndex(indexes, book);
List<Chapter> introductionChapters = book.getIntroductionChapters();
for (Chapter chapter : introductionChapters) {
bookRoot.cd(".").writeResources(chapter.getResources());
}
}