bool OEBBookReader::readBook(const std::string &fileName) { myFilePrefix = MiscUtil::htmlDirectoryPrefix(fileName); myIdToHref.clear(); myHtmlFileNames.clear(); myNCXTOCFileName.erase(); myTourTOC.clear(); myGuideTOC.clear(); myState = READ_NONE; if (!readDocument(fileName)) { return false; } myModelReader.setMainTextModel(); myModelReader.pushKind(REGULAR); XHTMLReader xhtmlReader(myModelReader); for (std::vector<std::string>::const_iterator it = myHtmlFileNames.begin(); it != myHtmlFileNames.end(); ++it) { if (it != myHtmlFileNames.begin()) { myModelReader.insertEndOfSectionParagraph(); } xhtmlReader.readFile(myFilePrefix + *it, *it); } generateTOC(); return true; }
bool OEBBookReader::readBook(const ZLFile &file) { myFilePrefix = MiscUtil::htmlDirectoryPrefix(file.path()); myIdToHref.clear(); myHtmlFileNames.clear(); myNCXTOCFileName.erase(); myCoverFileName.erase(); myCoverFileType.erase(); myCoverMimeType.erase(); myTourTOC.clear(); myGuideTOC.clear(); myState = READ_NONE; if (!readDocument(file)) { return false; } myModelReader.setMainTextModel(); myModelReader.pushKind(REGULAR); //ZLLogger::Instance().registerClass("oeb"); XHTMLReader xhtmlReader(myModelReader); for (std::vector<std::string>::const_iterator it = myHtmlFileNames.begin(); it != myHtmlFileNames.end(); ++it) { const ZLFile xhtmlFile(myFilePrefix + *it); if (it == myHtmlFileNames.begin()) { if (myCoverFileName == xhtmlFile.path()) { if (coverIsSingleImage()) { addCoverImage(); continue; } xhtmlReader.setMarkFirstImageAsCover(); } else { addCoverImage(); } } else { myModelReader.insertEndOfSectionParagraph(); } //ZLLogger::Instance().println("oeb", "start " + xhtmlFile.path()); xhtmlReader.readFile(xhtmlFile, *it); //ZLLogger::Instance().println("oeb", "end " + xhtmlFile.path()); //std::string debug = "para count = "; //ZLStringUtil::appendNumber(debug, myModelReader.model().bookTextModel()->paragraphsNumber()); //ZLLogger::Instance().println("oeb", debug); } generateTOC(xhtmlReader); return true; }
bool OEBBookReader::readBook(const ZLFile &file) { myFilePrefix = MiscUtil::htmlDirectoryPrefix(file.path()); myIdToHref.clear(); myHtmlFileNames.clear(); myNCXTOCFileName.erase(); myTourTOC.clear(); myGuideTOC.clear(); myState = READ_NONE; if (!readDocument(file)) { return false; } AppLog("OEBBookReader::readBook"); myModelReader.setMainTextModel(); myModelReader.pushKind(REGULAR); int n=0; AppLog("myFilePrefix %s", myFilePrefix.c_str()); std::string firstFile; firstFile = myFilePrefix + myHtmlFileNames[0]; AppLog("firstFile %s", firstFile.c_str()); //ZLFile tempFile = ZLFile(firstFile); //shared_ptr<ZLInputStream> tempStream = tempFile.inputStream(); // AppLog("tempStream created"); for (std::vector<std::string>::const_iterator it = myHtmlFileNames.begin(); it != myHtmlFileNames.end(); ++it) { if (it != myHtmlFileNames.begin()) { myModelReader.insertEndOfSectionParagraph(); } // AppLog("xhtmlReader.readFile "); XHTMLReader xhtmlReader(myModelReader); std::string fn; fn = *it; AppLog("it = %s", fn.c_str()); xhtmlReader.readFile(ZLFile(myFilePrefix + *it), *it); //if (++n>5) break; } generateTOC(); return true; }
bool OEBBookReader::readBook(const ZLFile &file) { const ZLFile epub = file.getContainerArchive(); epub.forceArchiveType(ZLFile::ZIP); shared_ptr<ZLDir> epubDir = epub.directory(); if (!epubDir.isNull()) { myEncryptionMap = new EncryptionMap(); const std::vector<shared_ptr<FileEncryptionInfo> > encodingInfos = OEBEncryptionReader().readEncryptionInfos(epub); for (std::vector<shared_ptr<FileEncryptionInfo> >::const_iterator it = encodingInfos.begin(); it != encodingInfos.end(); ++it) { myEncryptionMap->addInfo(*epubDir, *it); } } myFilePrefix = MiscUtil::htmlDirectoryPrefix(file.path()); myIdToHref.clear(); myHtmlFileNames.clear(); myNCXTOCFileName.erase(); myCoverFileName.erase(); myCoverFileType.erase(); myCoverMimeType.erase(); myTourTOC.clear(); myGuideTOC.clear(); myState = READ_NONE; if (!readDocument(file)) { return false; } myModelReader.setMainTextModel(); myModelReader.pushKind(REGULAR); //ZLLogger::Instance().registerClass("oeb"); XHTMLReader xhtmlReader(myModelReader, myEncryptionMap); for (std::vector<std::string>::const_iterator it = myHtmlFileNames.begin(); it != myHtmlFileNames.end(); ++it) { const ZLFile xhtmlFile(myFilePrefix + *it); if (it == myHtmlFileNames.begin()) { if (myCoverFileName == xhtmlFile.path()) { if (coverIsSingleImage()) { addCoverImage(); continue; } xhtmlReader.setMarkFirstImageAsCover(); } else { addCoverImage(); } } else { myModelReader.insertEndOfSectionParagraph(); } //ZLLogger::Instance().println("oeb", "start " + xhtmlFile.path()); if (!xhtmlReader.readFile(xhtmlFile, *it)) { if (file.exists() && !myEncryptionMap.isNull()) { myModelReader.insertEncryptedSectionParagraph(); } } //ZLLogger::Instance().println("oeb", "end " + xhtmlFile.path()); //std::string debug = "para count = "; //ZLStringUtil::appendNumber(debug, myModelReader.model().bookTextModel()->paragraphsNumber()); //ZLLogger::Instance().println("oeb", debug); } generateTOC(xhtmlReader); return true; }