コード例 #1
0
void OEBBookReader::endElementHandler(const char *tag) {
	std::string tagString = ZLUnicodeUtil::toLower(tag);

	switch (myState) {
		case READ_MANIFEST:
			if (isOPFTag(MANIFEST, tagString)) {
				myState = READ_NONE;
			}
			break;
		case READ_SPINE:
			if (isOPFTag(SPINE, tagString)) {
				myState = READ_NONE;
			}
			break;
		case READ_GUIDE:
			if (isOPFTag(GUIDE, tagString)) {
				myState = READ_NONE;
			}
			break;
		case READ_TOUR:
			if (isOPFTag(TOUR, tagString)) {
				myState = READ_NONE;
			}
			break;
		case READ_NONE:
			break;
	}
}
コード例 #2
0
void OEBBookReader::startElementHandler(const char *tag, const char **xmlattributes) {
	std::string tagString = ZLUnicodeUtil::toLower(tag);

	switch (myState) {
		case READ_NONE:
			if (isOPFTag(MANIFEST, tagString)) {
				myState = READ_MANIFEST;
			} else if (isOPFTag(SPINE, tagString)) {
				const char *toc = attributeValue(xmlattributes, "toc");
				if (toc != 0) {
					myNCXTOCFileName = myIdToHref[toc];
				}
				myState = READ_SPINE;
			} else if (isOPFTag(GUIDE, tagString)) {
				myState = READ_GUIDE;
			} else if (isOPFTag(TOUR, tagString)) {
				myState = READ_TOUR;
			}
			break;
		case READ_MANIFEST:
			if (isOPFTag(ITEM, tagString)) {
				const char *href = attributeValue(xmlattributes, "href");
				if (href != 0) {
					const std::string sHref = MiscUtil::decodeHtmlURL(href);
					const char *id = attributeValue(xmlattributes, "id");
					const char *mediaType = attributeValue(xmlattributes, "media-type");
					if (id != 0) {
						myIdToHref[id] = sHref;
					}
					if (mediaType != 0) {
						myHrefToMediatype[sHref] = mediaType;
					}
				}
			}
			break;
		case READ_SPINE:
			if (isOPFTag(ITEMREF, tagString)) {
				const char *id = attributeValue(xmlattributes, "idref");
				if (id != 0) {
					const std::string &fileName = myIdToHref[id];
					if (!fileName.empty()) {
						myHtmlFileNames.push_back(fileName);
					}
				}
			}
			break;
		case READ_GUIDE:
			if (isOPFTag(REFERENCE, tagString)) {
				const char *type = attributeValue(xmlattributes, "type");
				const char *title = attributeValue(xmlattributes, "title");
				const char *href = attributeValue(xmlattributes, "href");
				if (href != 0) {
					const std::string reference = MiscUtil::decodeHtmlURL(href);
					if (title != 0) {
						myGuideTOC.push_back(std::make_pair(std::string(title), reference));
					}
					if (type != 0 && (COVER == type || COVER_IMAGE == type)) {
						ZLFile imageFile(myFilePrefix + reference);
						myCoverFileName = imageFile.path();
						myCoverFileType = type;
						const std::map<std::string,std::string>::const_iterator it =
							myHrefToMediatype.find(reference);
						myCoverMimeType =
							it != myHrefToMediatype.end() ? it->second : std::string();
					}
				}
			}
			break;
		case READ_TOUR:
			if (isOPFTag(SITE, tagString)) {
				const char *title = attributeValue(xmlattributes, "title");
				const char *href = attributeValue(xmlattributes, "href");
				if ((title != 0) && (href != 0)) {
					myTourTOC.push_back(std::make_pair(title, MiscUtil::decodeHtmlURL(href)));
				}
			}
			break;
	}
}
コード例 #3
0
void OEBBookReader::startElementHandler(const char *tag, const char **xmlattributes) {
	std::string tagString = ZLUnicodeUtil::toLower(tag);

	switch (myState) {
		case READ_NONE:
			if (isOPFTag(MANIFEST, tagString)) {
				myState = READ_MANIFEST;
			} else if (isOPFTag(SPINE, tagString)) {
				const char *toc = attributeValue(xmlattributes, "toc");
				if (toc != 0) {
					myNCXTOCFileName = myIdToHref[toc];
				}
				myState = READ_SPINE;
			} else if (isOPFTag(GUIDE, tagString)) {
				myState = READ_GUIDE;
			} else if (isOPFTag(TOUR, tagString)) {
				myState = READ_TOUR;
			}
			break;
		case READ_MANIFEST:
			if (isOPFTag(ITEM, tagString)) {
				const char *href = attributeValue(xmlattributes, "href");
				if (href != 0) {
					const std::string sHref = MiscUtil::decodeHtmlURL(href);
					const char *id = attributeValue(xmlattributes, "id");
					const char *mediaType = attributeValue(xmlattributes, "media-type");
					if (id != 0) {
						myIdToHref[id] = sHref;
					}
					if (mediaType != 0) {
						myHrefToMediatype[sHref] = mediaType;
					}
				}
			}
			break;
		case READ_SPINE:
			if (isOPFTag(ITEMREF, tagString)) {
				const char *id = attributeValue(xmlattributes, "idref");
				if (id != 0) {
					const std::string &fileName = myIdToHref[id];
					if (!fileName.empty()) {
						myHtmlFileNames.push_back(fileName);
					}
				}
			}
			break;
		case READ_GUIDE:
			if (isOPFTag(REFERENCE, tagString)) {
				const char *type = attributeValue(xmlattributes, "type");
				const char *title = attributeValue(xmlattributes, "title");
				const char *href = attributeValue(xmlattributes, "href");
				if (href != 0) {
					const std::string reference = MiscUtil::decodeHtmlURL(href);
					if (title != 0) {
						myGuideTOC.push_back(std::make_pair(std::string(title), reference));
					}
					if (type != 0) {
						if (COVER == type) {
							ZLFile imageFile(myFilePrefix + reference);
							myCoverFileName = imageFile.path();
							const std::map<std::string,std::string>::const_iterator it =
								myHrefToMediatype.find(reference);
							const std::string mimeType =
								it != myHrefToMediatype.end() ? it->second : std::string();
							shared_ptr<const ZLImage> image;
							if (ZLStringUtil::stringStartsWith(mimeType, "image/")) {
								image = new ZLFileImage(imageFile, 0);
							} else {
								image = XHTMLImageFinder().readImage(imageFile);
							}
							if (!image.isNull()) {
								const std::string imageName = imageFile.name(false);
								myModelReader.setMainTextModel();
								myModelReader.addImageReference(imageName, 0);
								myModelReader.addImage(imageName, image);
								myModelReader.insertEndOfSectionParagraph();
							} else {
								myCoverFileName.erase();
							}
						} else if (COVER_IMAGE == type) {
							ZLFile imageFile(myFilePrefix + reference);
							myCoverFileName = imageFile.path();
							const std::string imageName = imageFile.name(false);
							myModelReader.setMainTextModel();
							myModelReader.addImageReference(imageName, 0);
							myModelReader.addImage(imageName, new ZLFileImage(imageFile, 0));
							myModelReader.insertEndOfSectionParagraph();
						}
					}
				}
			}
			break;
		case READ_TOUR:
			if (isOPFTag(SITE, tagString)) {
				const char *title = attributeValue(xmlattributes, "title");
				const char *href = attributeValue(xmlattributes, "href");
				if ((title != 0) && (href != 0)) {
					myTourTOC.push_back(std::make_pair(title, MiscUtil::decodeHtmlURL(href)));
				}
			}
			break;
	}
}