OSDN Git Service

loadMyListメソッドの追加.
authoryuki <yuki@bdf3b611-c98c-6041-8292-703d9c9adbe7>
Sat, 5 Jan 2008 11:47:59 +0000 (11:47 +0000)
committeryuki <yuki@bdf3b611-c98c-6041-8292-703d9c9adbe7>
Sat, 5 Jan 2008 11:47:59 +0000 (11:47 +0000)
git-svn-id: http://192.168.11.7/svn/repository/NicoBrowser@16 bdf3b611-c98c-6041-8292-703d9c9adbe7

nbproject/project.properties
src/nicobrowser/NicoHttpClient.java
test/nicobrowser/NicoHttpClientTest.java

index 0130c53..d8879aa 100644 (file)
@@ -21,7 +21,8 @@ jar.compress=false
 javac.classpath=\\r
     ${libs.HttpClient3.classpath}:\\r
     ${libs.Log4J.classpath}:\\r
-    ${libs.Codec.classpath}\r
+    ${libs.Codec.classpath}:\\r
+    ${libs.Rome.classpath}\r
 # Space-separated list of extra javac options\r
 javac.compilerargs=\r
 javac.deprecation=false\r
@@ -51,6 +52,9 @@ libs.HttpClient3.classpath=../../../java/commons/commons-httpclient-3.1/commons-
 # Property libs.Log4J.classpath is set here just to make sharing of project simpler.\r
 # The library definition has always preference over this property.\r
 libs.Log4J.classpath=../../../java/commons/commons-logging-1.1/commons-logging-adapters-1.1.jar;../../../java/commons/commons-logging-1.1/commons-logging-api-1.1.jar\r
+# Property libs.Rome.classpath is set here just to make sharing of project simpler.\r
+# The library definition has always preference over this property.\r
+libs.Rome.classpath=../../../java/commons/rome-0.9/rome-0.9.jar;../../../java/commons/jdom-1.1/build/jdom.jar\r
 main.class=nicobrowser.MainWindow\r
 manifest.file=manifest.mf\r
 meta.inf.dir=${src.dir}/META-INF\r
index f5bd1ed..af604b2 100644 (file)
@@ -1,7 +1,15 @@
 /*$Id$*/
 package nicobrowser;
 
+import com.sun.syndication.feed.synd.SyndEntryImpl;
+import com.sun.syndication.feed.synd.SyndFeed;
+import com.sun.syndication.io.FeedException;
+import com.sun.syndication.io.SyndFeedInput;
+import java.io.BufferedReader;
 import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.util.List;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 import org.apache.commons.httpclient.HttpClient;
@@ -21,6 +29,8 @@ public class NicoHttpClient extends HttpClient {
             "https://secure.nicovideo.jp/secure/login?site=niconico";
     private static final String LOGOUT_PAGE =
             "https://secure.nicovideo.jp/secure/logout";
+    private static final String MY_LIST_PAGE_HEADER =
+            "http://www.nicovideo.jp/mylist/";
 
     private NicoHttpClient() {
         super();
@@ -65,15 +75,14 @@ public class NicoHttpClient extends HttpClient {
         return auth;
     }
 
-    public void loadMyList(String listNo) {
-
-    }
-
     public boolean logout() {
         boolean result = false;
         GetMethod method = new GetMethod(LOGOUT_PAGE);
         try {
             int statusCode = executeMethod(method);
+            Logger.getLogger(NicoHttpClient.class.getName()).
+                    log(Level.INFO, "ログアウトステータスコード: " + statusCode);
+
             if (statusCode == HttpStatus.SC_OK) {
                 result = true;
             }
@@ -84,4 +93,39 @@ public class NicoHttpClient extends HttpClient {
         }
         return result;
     }
+
+    /**
+     * マイリストに登録した動画一覧の取得.
+     * 「公開」設定にしていないリストからは取得できない.
+     * ログインしていなくても取得可能.
+     * @param listNo マイリストNo.
+     * @return 動画一覧.
+     */
+    public List<SyndEntryImpl> loadMyList(String listNo) {
+        List<SyndEntryImpl> list = null;
+        String url = new String(MY_LIST_PAGE_HEADER + listNo + "?rss=atom");
+        Logger.getLogger(NicoHttpClient.class.getName()).
+                log(Level.INFO, "マイリストURL: " + url);
+
+        GetMethod get = new GetMethod(url);
+
+        try {
+            int statusCode = executeMethod(get);
+            Reader reader = new BufferedReader(new InputStreamReader(get.getResponseBodyAsStream(), "UTF-8"));
+            SyndFeedInput input = new SyndFeedInput();
+            SyndFeed feed = input.build(reader);
+
+            list = (List<SyndEntryImpl>) feed.getEntries();
+
+        } catch (IllegalArgumentException ex) {
+            Logger.getLogger(NicoHttpClient.class.getName()).log(Level.SEVERE, null, ex);
+        } catch (FeedException ex) {
+            Logger.getLogger(NicoHttpClient.class.getName()).log(Level.SEVERE, null, ex);
+        } catch (IOException ex) {
+            Logger.getLogger(NicoHttpClient.class.getName()).log(Level.SEVERE, null, ex);
+        } finally {
+            get.releaseConnection();
+        }
+        return list;
+    }
 }
index 1406f5c..cfc86eb 100644 (file)
@@ -1,6 +1,7 @@
 /*$Id$*/
 package nicobrowser;
 
+import java.util.List;
 import org.junit.After;
 import org.junit.AfterClass;
 import org.junit.Before;
@@ -14,6 +15,10 @@ import static org.junit.Assert.*;
  */
 public class NicoHttpClientTest {
 
+    static final String OK_MAIL = "niconico.senyou@live.jp";
+    static final String OK_PASS = "piyopiyo";
+    static final String OK_LIST_NO = "4315046";
+
     public NicoHttpClientTest() {
     }
 
@@ -63,8 +68,8 @@ public class NicoHttpClientTest {
         assertEquals(false, result);
 
         // ログイン成功ケース
-        mail = "niconico.senyou@live.jp";
-        password = "piyopiyo";
+        mail = OK_MAIL;
+        password = OK_PASS;
         result = instance.login(mail, password);
         assertEquals(true, result);
     }
@@ -84,11 +89,16 @@ public class NicoHttpClientTest {
     @Test
     public void loadMyList() {
         System.out.println("loadMyList");
-        
+
         NicoHttpClient instance = NicoHttpClient.getInstance();
-        
-        instance.logout();
+        List list;
 
+        list = instance.loadMyList(OK_LIST_NO);
+        assertNotNull(list);
+        assertNotSame(0, list.size());
 
+        list = instance.loadMyList("XXXX");
+        assertNotNull(list);
+        assertSame(0, list.size());
     }
 }