4 #include <QXmlContentHandler>
8 /** XML content handler for OPS format. */
9 class OpsHandler: public QXmlContentHandler
12 OpsHandler(Book &book): mBook(book) {}
13 bool endDocument() {return true;}
14 bool endPrefixMapping(const QString &) {return true;}
15 QString errorString() const {return "";}
16 bool ignorableWhitespace(const QString &) {return true;}
17 bool processingInstruction(const QString &, const QString &) {
20 void setDocumentLocator(QXmlLocator *) {}
21 bool skippedEntity(const QString &) {return true;}
22 bool startDocument() {return true;}
23 bool startPrefixMapping(const QString &, const QString &) {return true;}
25 bool characters(const QString &ch)
31 bool endElement(const QString &namespaceUri, const QString &name,
36 if (mCurrentText != "") {
37 if (name == "title") {
38 mBook.title = mCurrentText;
40 else if (name == "creator") {
41 mBook.creators.append(mCurrentText);
43 else if (name == "publisher") {
44 mBook.publisher = mCurrentText;
46 else if (name == "subject") {
47 mBook.subject = mCurrentText;
49 else if (name == "source") {
50 mBook.source = mCurrentText;
52 else if (name == "rights") {
53 mBook.rights = mCurrentText;
59 bool startElement(const QString &namespaceUri, const QString &name,
60 const QString &qName, const QXmlAttributes &attrs)
69 Book::ContentItem item;
70 item.href = mBook.rootPath() + "/" + attrs.value("href");
71 item.type = attrs.value("media-type");
72 QString key = attrs.value("id");
73 mBook.content[key] = item;
74 qDebug() << "OpsHandler::startElement: item" << key << "type"
75 << item.type << "href" << item.href;
77 else if (name == "itemref") {
78 mBook.toc.append(attrs.value("idref"));
79 qDebug() << "OpsHandler::startElement: itemref" << attrs.value("idref");
89 #endif // OPSHANDLER_H