OSDN Git Service

取得した情報をNicoContentに詰めるよう変更.
authoryuki <yuki@bdf3b611-c98c-6041-8292-703d9c9adbe7>
Sat, 5 Jan 2008 13:12:22 +0000 (13:12 +0000)
committeryuki <yuki@bdf3b611-c98c-6041-8292-703d9c9adbe7>
Sat, 5 Jan 2008 13:12:22 +0000 (13:12 +0000)
git-svn-id: http://192.168.11.7/svn/repository/NicoBrowser@17 bdf3b611-c98c-6041-8292-703d9c9adbe7

src/nicobrowser/NicoContent.java [new file with mode: 0644]
src/nicobrowser/NicoHttpClient.java

diff --git a/src/nicobrowser/NicoContent.java b/src/nicobrowser/NicoContent.java
new file mode 100644 (file)
index 0000000..404ba11
--- /dev/null
@@ -0,0 +1,44 @@
+/*$Id$*/
+package nicobrowser;
+
+import java.util.Date;
+
+public class NicoContent {
+
+    private String pageLink;
+    private String imageLink;
+    private String title;
+    private Date publishedDate;
+
+    public String getPageLink() {
+        return pageLink;
+    }
+
+    public void setPageLink(String pageLink) {
+        this.pageLink = pageLink;
+    }
+
+    public String getImageLink() {
+        return imageLink;
+    }
+
+    public void setImageLink(String imageLink) {
+        this.imageLink = imageLink;
+    }
+
+    public String getTitle() {
+        return title;
+    }
+
+    public void setTitle(String title) {
+        this.title = title;
+    }
+
+    void setPublishedDate(Date publishedDate) {
+        this.publishedDate = publishedDate;
+    }
+
+    public Date getPublishedDate() {
+        return publishedDate;
+    }
+}
index af604b2..f009f34 100644 (file)
@@ -1,6 +1,7 @@
 /*$Id$*/
 package nicobrowser;
 
+import com.sun.syndication.feed.synd.SyndContentImpl;
 import com.sun.syndication.feed.synd.SyndEntryImpl;
 import com.sun.syndication.feed.synd.SyndFeed;
 import com.sun.syndication.io.FeedException;
@@ -9,9 +10,16 @@ import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.io.Reader;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.Enumeration;
 import java.util.List;
 import java.util.logging.Level;
 import java.util.logging.Logger;
+import javax.swing.text.MutableAttributeSet;
+import javax.swing.text.html.HTML;
+import javax.swing.text.html.HTMLEditorKit;
+import javax.swing.text.html.parser.ParserDelegator;
 import org.apache.commons.httpclient.HttpClient;
 import org.apache.commons.httpclient.HttpStatus;
 import org.apache.commons.httpclient.cookie.CookiePolicy;
@@ -101,7 +109,7 @@ public class NicoHttpClient extends HttpClient {
      * @param listNo マイリストNo.
      * @return 動画一覧.
      */
-    public List<SyndEntryImpl> loadMyList(String listNo) {
+    public List<NicoContent> loadMyList(String listNo) {
         List<SyndEntryImpl> list = null;
         String url = new String(MY_LIST_PAGE_HEADER + listNo + "?rss=atom");
         Logger.getLogger(NicoHttpClient.class.getName()).
@@ -126,6 +134,66 @@ public class NicoHttpClient extends HttpClient {
         } finally {
             get.releaseConnection();
         }
-        return list;
+        List<NicoContent> contList;
+        if (list == null) {
+            contList = new ArrayList<NicoContent>();
+        } else {
+            contList = createContentsList(list);
+        }
+        return contList;
+    }
+
+    private List<NicoContent> createContentsList(List<SyndEntryImpl> list) {
+        class CallBack extends HTMLEditorKit.ParserCallback {
+
+            private String imageLink;
+
+            @Override
+            public void handleSimpleTag(HTML.Tag t, MutableAttributeSet a, int pos) {
+//                System.out.println("--------<" + t.toString() + ">--------");
+//                printAttributes(a);
+                if (HTML.Tag.IMG.equals(t)) {
+                    imageLink = a.getAttribute(HTML.Attribute.SRC).toString();
+                }
+            }
+
+            // 属性を表示
+//            private void printAttributes(MutableAttributeSet a) {
+//                Enumeration e = a.getAttributeNames();
+//                while (e.hasMoreElements()) {
+//                    Object key = e.nextElement();
+//                    System.out.println("---- " + key.toString() + " : " + a.getAttribute(key));
+//                }
+//            }
+            public String getImageLink() {
+                return imageLink;
+            }
+        }
+
+        List contList = new ArrayList<NicoContent>();
+
+        for (SyndEntryImpl entry : list) {
+            NicoContent content = new NicoContent();
+
+            content.setTitle(entry.getTitle());
+            content.setPageLink(entry.getLink());
+            content.setPublishedDate(entry.getPublishedDate());
+
+            // サムネイル画像リンクの取得
+            CallBack callBack = new CallBack();
+            for (SyndContentImpl sc : (List<SyndContentImpl>) entry.getContents()) {
+                try {
+                    Reader reader = new StringReader(sc.getValue());
+                    new ParserDelegator().parse(reader, callBack, true);
+                } catch (IOException ex) {
+                    Logger.getLogger(NicoHttpClient.class.getName()).log(Level.SEVERE, null, ex);
+                }
+            }
+            content.setImageLink(callBack.getImageLink());
+
+            // リストへ追加.
+            contList.add(content);
+        }
+        return contList;
     }
 }