2 * Copyright (c) 2010 Mani Chandrasekar <maninc@gmail.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include "googledocumentlist.h"
22 #include "googledocument.h"
23 #include "googlecontenthandler.h"
25 GoogleContentHandler::GoogleContentHandler()
29 m_docList = new GoogleDocumentList();
32 bool GoogleContentHandler::characters(const QString & ch)
35 if(QString::compare(m_nodeStack.top(), "title", Qt::CaseInsensitive) == 0) {
36 if(m_nodeStack.count() == 2)
37 m_docList->setTitle(ch);
38 } else if(QString::compare(m_nodeStack.top(), "name", Qt::CaseInsensitive) == 0) {
39 if(m_nodeStack.count() == 3)
40 m_docList->setAuthor(ch);
41 } else if(QString::compare(m_nodeStack.top(), "email", Qt::CaseInsensitive) == 0) {
42 if(m_nodeStack.count() == 3)
43 m_docList->setEmail(ch);
49 if(QString::compare(m_nodeStack.top(), "title", Qt::CaseInsensitive) == 0) {
50 m_docEntry->setTitle(ch);
51 } else if(QString::compare(m_nodeStack.top(), "name", Qt::CaseInsensitive) == 0) {
52 m_docEntry->setAuthor(ch);
53 } else if(QString::compare(m_nodeStack.top(), "resourceId", Qt::CaseInsensitive) == 0) {
54 m_docEntry->setId(ch);
60 bool GoogleContentHandler::endDocument()
62 //qDebug() << "GoogleContentHandler::endDocument()";
66 bool GoogleContentHandler::endElement(const QString & namespaceURI, const QString & localName, const QString & qName)
68 //printName(localName);
69 QString element = m_nodeStack.pop();
70 if(QString::compare(element, "entry") == 0) {
72 m_docList->append(m_docEntry);
78 bool GoogleContentHandler::endPrefixMapping(const QString & prefix)
83 QString GoogleContentHandler::errorString() const
88 bool GoogleContentHandler::ignorableWhitespace(const QString & ch)
93 bool GoogleContentHandler::processingInstruction(const QString & target, const QString & data)
98 void GoogleContentHandler::setDocumentLocator(QXmlLocator * locator)
102 bool GoogleContentHandler::skippedEntity(const QString & name)
107 bool GoogleContentHandler::startDocument()
112 bool GoogleContentHandler::startElement(const QString & namespaceURI, const QString & localName,
113 const QString & qName, const QXmlAttributes & atts)
115 m_nodeStack.push(localName);
117 if((m_nodeStack.count() == 1) && (m_docList != 0)) { //Feed element
118 m_docList->setEtag(atts.value("gd:etag"));
121 if(QString::compare(localName, "entry", Qt::CaseInsensitive) == 0) {
122 m_docEntry = new GoogleDocument();
123 m_docEntry->setEtag(atts.value("gd:etag"));
126 if(insideEntry && (QString::compare(localName, "content", Qt::CaseInsensitive) == 0) && (m_docEntry != 0)) {
127 m_docEntry->setDocumentUrl(atts.value("src"));
130 //printName(localName);
135 bool GoogleContentHandler::startPrefixMapping(const QString & prefix, const QString & uri)
137 //qDebug() << "GoogleContentHandler::startPrefixMapping() " << prefix << uri;
141 void GoogleContentHandler::printName(const QString & name)
143 int count = m_nodeStack.count();
145 for(int i = 0; i < count; i++)
150 // qDebug() << indent;