OSDN Git Service

http://zio3.net/nicoRss/Handler.ashx
authoryuki <yuki@bdf3b611-c98c-6041-8292-703d9c9adbe7>
Fri, 22 Feb 2008 18:12:33 +0000 (18:12 +0000)
committeryuki <yuki@bdf3b611-c98c-6041-8292-703d9c9adbe7>
Fri, 22 Feb 2008 18:12:33 +0000 (18:12 +0000)
からランキングを取得するメソッドを追加。

git-svn-id: http://192.168.11.7/svn/repository/NicoBrowser@23 bdf3b611-c98c-6041-8292-703d9c9adbe7

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

index 9d848ee..bfc26b1 100644 (file)
@@ -1,5 +1,5 @@
 application.homepage=http://feather.cocolog-nifty.com/\r
-application.title=DEMO:\u30cb\u30b3\u30cb\u30b3\u52d5\u753bRSS\u30d6\u30e9\u30a6\u30b6\r
+application.title=DEMO:\u30cb\u30b3\u30cb\u30b3\u52d5\u753b\u30b3\u30f3\u30c6\u30f3\u30c4\u60c5\u5831\u30d6\u30e9\u30a6\u30b6\r
 application.vendor=yukihane\r
 build.classes.dir=${build.dir}/classes\r
 build.classes.excludes=\r
@@ -47,7 +47,7 @@ javadoc.use=true
 javadoc.version=false\r
 javadoc.windowtitle=\r
 jnlp.codebase.type=user\r
-jnlp.codebase.user=http://www.example.com\r
+jnlp.codebase.user=http://feather.cocolog-nifty.com/weblog/program/NicoBrowser\r
 jnlp.enabled=true\r
 jnlp.offline-allowed=true\r
 jnlp.signed=true\r
index e533133..170bae8 100644 (file)
               <Group type="103" groupAlignment="0" attributes="0">
                   <Component id="jScrollPane1" alignment="1" pref="755" max="32767" attributes="0"/>
                   <Component id="jPanel1" min="-2" max="-2" attributes="1"/>
-                  <Component id="jPanel2" min="-2" max="-2" attributes="2"/>
+                  <Group type="102" attributes="0">
+                      <Component id="jPanel2" min="-2" max="-2" attributes="2"/>
+                      <EmptySpace max="-2" attributes="0"/>
+                      <Component id="jPanel3" min="-2" max="-2" attributes="0"/>
+                  </Group>
               </Group>
               <EmptySpace min="-2" max="-2" attributes="0"/>
           </Group>
       <Group type="103" groupAlignment="0" attributes="0">
           <Group type="102" alignment="1" attributes="0">
               <EmptySpace min="-2" max="-2" attributes="0"/>
-              <Component id="jScrollPane1" pref="313" max="32767" attributes="0"/>
+              <Component id="jScrollPane1" pref="271" max="32767" attributes="0"/>
               <EmptySpace min="-2" max="-2" attributes="0"/>
               <Component id="jPanel1" min="-2" max="-2" attributes="0"/>
               <EmptySpace min="-2" max="-2" attributes="0"/>
-              <Component id="jPanel2" min="-2" max="-2" attributes="2"/>
+              <Group type="103" groupAlignment="0" attributes="0">
+                  <Component id="jPanel2" min="-2" max="-2" attributes="3"/>
+                  <Component id="jPanel3" min="-2" max="-2" attributes="1"/>
+              </Group>
               <EmptySpace max="-2" attributes="0"/>
           </Group>
       </Group>
                       <Component id="listNoField" alignment="0" pref="70" max="32767" attributes="1"/>
                   </Group>
                   <EmptySpace type="separate" max="-2" attributes="0"/>
-                  <Component id="clearButton" min="-2" max="-2" attributes="0"/>
-                  <EmptySpace pref="36" max="32767" attributes="0"/>
+                  <Component id="loadDailyListButton" min="-2" max="-2" attributes="1"/>
+                  <EmptySpace pref="20" max="32767" attributes="0"/>
               </Group>
           </Group>
         </DimensionLayout>
                       <Component id="listLoadButton" alignment="3" min="-2" max="-2" attributes="0"/>
                       <Component id="jLabel3" alignment="3" min="-2" max="-2" attributes="0"/>
                       <Component id="listNoField" alignment="3" min="-2" max="-2" attributes="0"/>
-                      <Component id="clearButton" alignment="3" min="-2" max="-2" attributes="0"/>
+                      <Component id="loadDailyListButton" alignment="3" min="-2" max="-2" attributes="0"/>
                   </Group>
                   <EmptySpace max="-2" attributes="0"/>
                   <Group type="103" groupAlignment="2" attributes="0">
             <Property name="text" type="java.lang.String" value="sm9"/>
           </Properties>
         </Component>
-        <Component class="javax.swing.JButton" name="clearButton">
+        <Component class="javax.swing.JButton" name="loadDailyListButton">
           <Properties>
-            <Property name="text" type="java.lang.String" value="Clear"/>
+            <Property name="text" type="java.lang.String" value="Daily"/>
           </Properties>
           <Events>
-            <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="clearButtonActionPerformed"/>
+            <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="loadDailyListButtonActionPerformed"/>
           </Events>
         </Component>
       </SubComponents>
         </Component>
       </SubComponents>
     </Container>
+    <Container class="javax.swing.JPanel" name="jPanel3">
+      <Properties>
+        <Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
+          <Border info="org.netbeans.modules.form.compat2.border.EtchedBorderInfo">
+            <EtchetBorder/>
+          </Border>
+        </Property>
+      </Properties>
+
+      <Layout>
+        <DimensionLayout dim="0">
+          <Group type="103" groupAlignment="0" attributes="0">
+              <Group type="102" alignment="0" attributes="0">
+                  <EmptySpace max="-2" attributes="0"/>
+                  <Component id="clearButton" max="32767" attributes="1"/>
+                  <EmptySpace min="-2" max="-2" attributes="0"/>
+              </Group>
+          </Group>
+        </DimensionLayout>
+        <DimensionLayout dim="1">
+          <Group type="103" groupAlignment="0" attributes="0">
+              <Group type="102" alignment="0" attributes="0">
+                  <EmptySpace max="-2" attributes="0"/>
+                  <Component id="clearButton" min="-2" max="-2" attributes="0"/>
+                  <EmptySpace max="32767" attributes="0"/>
+              </Group>
+          </Group>
+        </DimensionLayout>
+      </Layout>
+      <SubComponents>
+        <Component class="javax.swing.JButton" name="clearButton">
+          <Properties>
+            <Property name="text" type="java.lang.String" value="Clear"/>
+          </Properties>
+          <Events>
+            <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="clearButtonActionPerformed"/>
+          </Events>
+        </Component>
+      </SubComponents>
+    </Container>
   </SubComponents>
 </Form>
index 37dfa85..477566d 100644 (file)
@@ -117,13 +117,15 @@ public class MainWindow extends javax.swing.JFrame {
         unitLoadButton = new javax.swing.JButton();
         jLabel4 = new javax.swing.JLabel();
         unitNoField = new javax.swing.JTextField();
-        clearButton = new javax.swing.JButton();
+        loadDailyListButton = new javax.swing.JButton();
         jPanel1 = new javax.swing.JPanel();
         jLabel1 = new javax.swing.JLabel();
         jLabel2 = new javax.swing.JLabel();
         mailField = new javax.swing.JTextField();
         passwordField = new javax.swing.JTextField();
         loginButton = new javax.swing.JButton();
+        jPanel3 = new javax.swing.JPanel();
+        clearButton = new javax.swing.JButton();
 
         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
 
@@ -156,10 +158,10 @@ public class MainWindow extends javax.swing.JFrame {
 
         unitNoField.setText("sm9");
 
-        clearButton.setText("Clear");
-        clearButton.addActionListener(new java.awt.event.ActionListener() {
+        loadDailyListButton.setText("Daily");
+        loadDailyListButton.addActionListener(new java.awt.event.ActionListener() {
             public void actionPerformed(java.awt.event.ActionEvent evt) {
-                clearButtonActionPerformed(evt);
+                loadDailyListButtonActionPerformed(evt);
             }
         });
 
@@ -181,8 +183,8 @@ public class MainWindow extends javax.swing.JFrame {
                     .addComponent(unitNoField)
                     .addComponent(listNoField, javax.swing.GroupLayout.DEFAULT_SIZE, 70, Short.MAX_VALUE))
                 .addGap(18, 18, 18)
-                .addComponent(clearButton)
-                .addContainerGap(36, Short.MAX_VALUE))
+                .addComponent(loadDailyListButton)
+                .addContainerGap(20, Short.MAX_VALUE))
         );
         jPanel2Layout.setVerticalGroup(
             jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
@@ -192,7 +194,7 @@ public class MainWindow extends javax.swing.JFrame {
                     .addComponent(listLoadButton)
                     .addComponent(jLabel3)
                     .addComponent(listNoField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
-                    .addComponent(clearButton))
+                    .addComponent(loadDailyListButton))
                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                     .addComponent(jLabel4)
@@ -252,6 +254,32 @@ public class MainWindow extends javax.swing.JFrame {
                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
         );
 
+        jPanel3.setBorder(javax.swing.BorderFactory.createEtchedBorder());
+
+        clearButton.setText("Clear");
+        clearButton.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
+                clearButtonActionPerformed(evt);
+            }
+        });
+
+        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
+        jPanel3.setLayout(jPanel3Layout);
+        jPanel3Layout.setHorizontalGroup(
+            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+            .addGroup(jPanel3Layout.createSequentialGroup()
+                .addContainerGap()
+                .addComponent(clearButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+                .addContainerGap())
+        );
+        jPanel3Layout.setVerticalGroup(
+            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+            .addGroup(jPanel3Layout.createSequentialGroup()
+                .addContainerGap()
+                .addComponent(clearButton)
+                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
+        );
+
         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
         getContentPane().setLayout(layout);
         layout.setHorizontalGroup(
@@ -261,18 +289,23 @@ public class MainWindow extends javax.swing.JFrame {
                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 755, Short.MAX_VALUE)
                     .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
-                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
+                    .addGroup(layout.createSequentialGroup()
+                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                 .addContainerGap())
         );
         layout.setVerticalGroup(
             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                 .addContainerGap()
-                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 313, Short.MAX_VALUE)
+                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 271, Short.MAX_VALUE)
                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                 .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
-                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+                    .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                 .addContainerGap())
         );
 
@@ -348,6 +381,30 @@ public class MainWindow extends javax.swing.JFrame {
 
 }//GEN-LAST:event_unitLoadButtonActionPerformed
 
+    private void loadDailyListButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loadDailyListButtonActionPerformed
+        List<NicoContent> contList = NicoHttpClient.getInstance().loadMyListDaily();
+        int rowHeight = -1;
+        for (NicoContent cont : contList) {
+            Vector<Object> v = new Vector<Object>();
+            ImageIcon icon = new ImageIcon();
+            try {
+                icon = new ImageIcon(new URL(cont.getImageLink()));
+                if (rowHeight < 0) {
+                    rowHeight = icon.getIconHeight();
+                }
+            } catch (MalformedURLException ex) {
+                Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
+            }
+            v.add(icon);
+            v.add(cont.getTitle());
+            v.add(cont.getDescription());
+            v.add(cont.getPageLink());
+            tableModel.addRow(v);
+        }
+        jTable1.setRowHeight(rowHeight);
+
+}//GEN-LAST:event_loadDailyListButtonActionPerformed
+
     /**
      * @param args the command line arguments
      */
@@ -367,10 +424,12 @@ public class MainWindow extends javax.swing.JFrame {
     private javax.swing.JLabel jLabel4;
     private javax.swing.JPanel jPanel1;
     private javax.swing.JPanel jPanel2;
+    private javax.swing.JPanel jPanel3;
     private javax.swing.JScrollPane jScrollPane1;
     private javax.swing.JTable jTable1;
     private javax.swing.JButton listLoadButton;
     private javax.swing.JTextField listNoField;
+    private javax.swing.JButton loadDailyListButton;
     private javax.swing.JButton loginButton;
     private javax.swing.JTextField mailField;
     private javax.swing.JTextField passwordField;
index 6e1433e..c65bc46 100644 (file)
@@ -5,6 +5,7 @@ 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;
+import com.sun.syndication.io.ParsingFeedException;
 import com.sun.syndication.io.SyndFeedInput;
 import java.io.BufferedReader;
 import java.io.IOException;
@@ -12,10 +13,7 @@ import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.Reader;
 import java.io.StringReader;
-import java.text.DateFormat;
-import java.text.ParseException;
 import java.util.ArrayList;
-import java.util.Date;
 import java.util.Enumeration;
 import java.util.List;
 import java.util.logging.Level;
@@ -186,7 +184,7 @@ public class NicoHttpClient extends HttpClient {
             NodeList list2 = root.getElementsByTagName("thumb");
             cont = new NicoContent();
             Element element = (Element) list2.item(0);
-            
+
             String watch_url = ((Element) element.getElementsByTagName("watch_url").item(0)).getFirstChild().getNodeValue();
             cont.setPageLink(watch_url);
 
@@ -199,7 +197,7 @@ public class NicoHttpClient extends HttpClient {
             String description = ((Element) element.getElementsByTagName("description").item(0)).getFirstChild().getNodeValue();
             cont.setDescription(description);
 
-            // TODO 投稿日の設定
+        // TODO 投稿日の設定
 //            String first_retrieve = ((Element) element.getElementsByTagName("first_retrieve").item(0)).getFirstChild().getNodeValue();
 //            cont.setPublishedDate(DateFormat.getInstance().parse(first_retrieve));
 //
@@ -222,6 +220,46 @@ public class NicoHttpClient extends HttpClient {
 
     }
 
+    List<NicoContent> loadMyListDaily() {
+        List<SyndEntryImpl> list = null;
+        String url = new String("http://zio3.net/nicoRss/Handler.ashx");
+        Logger.getLogger(NicoHttpClient.class.getName()).
+                log(Level.INFO, "全動画サイトのマイリスト登録数ランキング(本日)[全体] : " + url);
+
+        GetMethod get = new GetMethod(url);
+
+        try {
+            int statusCode = executeMethod(get);
+            BufferedReader reader = new BufferedReader(new InputStreamReader(get.getResponseBodyAsStream(), "UTF-8"));
+            //TODO 本来ならInputStreamに対して3byte読み捨てるべきだろう
+            reader.skip(1);
+            SyndFeedInput input = new SyndFeedInput();
+            SyndFeed feed = input.build(reader);
+
+            list = (List<SyndEntryImpl>) feed.getEntries();
+
+        } catch (ParsingFeedException ex) {
+            Logger.getLogger(NicoHttpClient.class.getName()).log(Level.SEVERE, null, ex);
+            Logger.getLogger(NicoHttpClient.class.getName()).log(Level.SEVERE, null, ex.getColumnNumber());
+            Logger.getLogger(NicoHttpClient.class.getName()).log(Level.SEVERE, null, ex.getLineNumber());
+        } 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();
+        }
+        List<NicoContent> contList = null;
+        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 {
 
index c12d5b3..294bc94 100644 (file)
@@ -95,12 +95,26 @@ public class NicoHttpClientTest {
         list = instance.loadMyList(OK_LIST_NO);
         assertNotNull(list);
         assertNotSame(0, list.size());
-        for(Object o:list){
-            System.out.println(o.toString());
-        }
+//        for (Object o : list) {
+//            System.out.println(o.toString());
+//        }
 
         list = instance.loadMyList("XXXX");
         assertNotNull(list);
         assertSame(0, list.size());
     }
+
+    @Test
+    public void loadMyListDaily() {
+        System.out.println("loadMyListDaily");
+        NicoHttpClient instance = NicoHttpClient.getInstance();
+        instance.login(OK_MAIL, OK_PASS);
+        List<NicoContent> list = instance.loadMyListDaily();
+        assertNotNull(list);
+        assertNotSame(0, list.size());
+//        System.out.println(list.size());
+//        for (Object o : list) {
+//            System.out.println(o.toString());
+//        }
+    }
 }