return ret;
}
+bool FavoriteThreads::test()
+{
+ QString xml = "<favorites xmlns=\"http://kita.sourceforge.jp/ns/favorites\">\n"
+ "<thread xmlns=\"http://kita.sourceforge.jp/ns/thread\">\n"
+ "<daturl>http://pc.2ch.net/test/read.cgi/linux/1022744633/</daturl>\n"
+ "<name>2ch browser thread</name>\n"
+ "<board xmlns=\"http://kita.sourceforge.jp/ns/board\">\n"
+ "<url>http://pc.2ch.net/linux/</url>\n"
+ "<name>Linux</name>"
+ "</board>
+ "</thread>\n"
+ "<thread xmlns=\"http://kita.sourceforge.jp/ns/thread\">\n"
+ "<daturl>http://pc.2ch.net/test/read.cgi/unix/956134538/</daturl>\n"
+ "<name>NeXT</name>\n"
+ "<board xmlns=\"http://kita.sourceforge.jp/ns/board\">\n"
+ "<url>http://pc.2ch.net/unix/</url>\n"
+ "<name>Unix</name>"
+ "</board>
+ "</thread>\n"
+ "</favorites>\n";
+}
+
bool FavoritesXmlParser::startElement( const QString& namespaceURI, const QString& localName, const QString& qName, const QXmlAttributes& atts )
{
+ if( m_inThread ) {
+ m_threadParser->startElement( namespaceURI, localName, qName, atts );
+ } else if( m_inFavorites ) {
+ if( localName == "thread" ) {
+ m_inThread = true;
+ m_threadParser = new Kita::ThreadXmlParser();
+ m_threadParser->startElement( namespaceURI, localName, qName, atts );
+ } else {
+ // error
+ return false;
+ }
+ } else {
+ if( localName == "favorites" ) {
+ m_inFavorites = true;
+ } else {
+ // error
+ return false;
+ }
+ }
return true;
}
bool FavoritesXmlParser::endElement( const QString& namespaceURI, const QString& localName, const QString& qName )
{
+ if( localName == "thread" ) {
+ m_inThread = false;
+ m_threadParser->endElement( namespaceURI, localName, qName );
+ Kita::Thread thread = m_threadParser->getThread();
+ // XXX: add thread
+
+ delete m_threadParser;
+ m_threadParser = 0;
+ } else if( localName == "favorites" ) {
+ m_inFavorites = false;
+ m_isValid = true;
+ } else {
+ // error
+ return false;
+ }
return true;
}
bool FavoritesXmlParser::characters( const QString& ch )
{
+ if( m_inFavorites ) {
+ m_threadParser->characters( ch );
+ } else {
+ m_characters = ch;
+ }
return true;
}
const QMap<QString, Kita::Thread>& threads() const { return m_threadMap; };
static FavoriteThreads* fromXml( const QString& xml );
const QString toXml() const;
+
+ static bool test();
};
class FavoritesXmlParser : public QXmlDefaultHandler
bool m_inFavorites;
bool m_inThread;
bool m_isValid;
+ QString m_characters;
QPtrList<Kita::Thread> m_threadList;
+ Kita::ThreadXmlParser* m_threadParser;
public:
FavoritesXmlParser() : m_inFavorites(false), m_inThread(false), m_isValid(false) {};
~FavoritesXmlParser() {};