OSDN Git Service

impl parser
authorikemo <ikemo@56b19765-1e22-0410-a548-a0f45d66c51a>
Mon, 9 Jun 2003 13:53:09 +0000 (13:53 +0000)
committerikemo <ikemo@56b19765-1e22-0410-a548-a0f45d66c51a>
Mon, 9 Jun 2003 13:53:09 +0000 (13:53 +0000)
git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/kita/kita/trunk@333 56b19765-1e22-0410-a548-a0f45d66c51a

kita/src/libkita/favoritethreads.cpp
kita/src/libkita/favoritethreads.h

index ebb8150..e3f581b 100644 (file)
@@ -65,18 +65,79 @@ const QString FavoriteThreads::toXml() const
   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;
 }
 
index c47319e..9fdc315 100644 (file)
@@ -36,6 +36,8 @@ public:
   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
@@ -43,7 +45,9 @@ 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() {};