OSDN Git Service

リファクタリング: フィールド名変更
authoryukihane <yukihane.feather@gmail.com>
Thu, 11 Aug 2011 04:23:39 +0000 (13:23 +0900)
committeryukihane <yukihane.feather@gmail.com>
Thu, 11 Aug 2011 04:23:39 +0000 (13:23 +0900)
src/nicobrowser/NicoHttpClient.java

index 53d7b98..a531a84 100644 (file)
@@ -74,7 +74,7 @@ import org.xml.sax.SAXException;
  */
 public class NicoHttpClient {
 
-    private static Log log = LogFactory.getLog(NicoHttpClient.class);
+    private static Log logger = LogFactory.getLog(NicoHttpClient.class);
     private final DefaultHttpClient http;
     private static final String LOGIN_PAGE =
             "https://secure.nicovideo.jp/secure/login?site=niconico";
@@ -127,7 +127,7 @@ public class NicoHttpClient {
 
             //post.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
             HttpResponse response = http.execute(post);
-            log.debug("ログインステータスコード: " + response.getStatusLine().getStatusCode());
+            logger.debug("ログインステータスコード: " + response.getStatusLine().getStatusCode());
 
             // ログイン可否の判定.
             HttpEntity entity = response.getEntity();
@@ -137,7 +137,7 @@ public class NicoHttpClient {
                 auth = true;
             }
         } catch (IOException ex) {
-            log.error("ログイン時に問題が発生", ex);
+            logger.error("ログイン時に問題が発生", ex);
         }
         return auth;
     }
@@ -151,14 +151,14 @@ public class NicoHttpClient {
         HttpGet method = new HttpGet(LOGOUT_PAGE);
         try {
             HttpResponse response = http.execute(method);
-            log.debug("ログアウトステータスコード: " + response.getStatusLine().getStatusCode());
+            logger.debug("ログアウトステータスコード: " + response.getStatusLine().getStatusCode());
 
             if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
                 result = true;
             }
             response.getEntity().consumeContent();
         } catch (IOException ex) {
-            log.error("ログアウト時に問題が発生", ex);
+            logger.error("ログアウト時に問題が発生", ex);
         }
         return result;
     }
@@ -173,7 +173,7 @@ public class NicoHttpClient {
      */
     public SearchResult search(SearchKind kind, String word, SortKind sort, SortOrder order, int page) throws
             IOException {
-        log.debug("検索:" + word);
+        logger.debug("検索:" + word);
 
         InputStream is = null;
         ArrayList<NicoContent> conts = new ArrayList<NicoContent>();
@@ -198,7 +198,7 @@ public class NicoHttpClient {
             TreeMap<Integer, String> otherPages = Util.getOtherPages(is);
             return new SearchResult(conts, otherPages);
         } catch (IOException ex) {
-            log.error("検索結果処理時に例外発生", ex);
+            logger.error("検索結果処理時に例外発生", ex);
             throw ex;
         } finally {
             if (is != null) {
@@ -217,7 +217,7 @@ public class NicoHttpClient {
     public List<NicoContent> loadMyListDaily() throws URISyntaxException, HttpException, InterruptedException {
         List<NicoContent> list = new ArrayList<NicoContent>();
         String url = "http://www.nicovideo.jp/ranking/mylist/daily/all?rss=atom";
-        log.debug("全動画サイトのマイリスト登録数ランキング(本日)[全体] : " + url);
+        logger.debug("全動画サイトのマイリスト登録数ランキング(本日)[全体] : " + url);
 
         HttpGet get = new HttpGet(url);
 
@@ -231,15 +231,15 @@ public class NicoHttpClient {
             deleteRankString(list);
             response.getEntity().consumeContent();
         } catch (FeedException ex) {
-            log.error("", ex);
+            logger.error("", ex);
         } catch (IOException ex) {
-            log.error("", ex);
+            logger.error("", ex);
         } finally {
             if (reader != null) {
                 try {
                     reader.close();
                 } catch (IOException ex) {
-                    log.error("", ex);
+                    logger.error("", ex);
                 }
             }
         }
@@ -252,7 +252,7 @@ public class NicoHttpClient {
      * @return コンテンツリスト.
      */
     public List<NicoContent> getContentsFromRss(String url) {
-        log.debug("アクセスURL: " + url);
+        logger.debug("アクセスURL: " + url);
         List<NicoContent> list = accessRssUrl(url);
         if (url.contains("ranking")) {
             deleteRankString(list);
@@ -282,7 +282,7 @@ public class NicoHttpClient {
      */
     public List<NicoContent> loadMyList(String listNo) {
         String url = MY_LIST_PAGE_HEADER + listNo + "?rss=atom";
-        log.debug("マイリストURL: " + url);
+        logger.debug("マイリストURL: " + url);
         return accessRssUrl(url);
     }
 
@@ -294,7 +294,7 @@ public class NicoHttpClient {
      */
     public InputStream getThumbInfo(String movieNo) throws IOException {
         String url = MOVIE_THUMBNAIL_PAGE_HEADER + movieNo;
-        log.debug("動画サムネイルURL: " + url);
+        logger.debug("動画サムネイルURL: " + url);
 
         HttpGet get = new HttpGet(url);
         HttpResponse response = http.execute(get);
@@ -323,7 +323,7 @@ public class NicoHttpClient {
             Element root = doc.getDocumentElement();
 
             if ("fail".equals(root.getAttribute("status"))) {
-                log.warn("情報取得できません: " + movieNo);
+                logger.warn("情報取得できません: " + movieNo);
                 return null;
             }
 
@@ -345,18 +345,18 @@ public class NicoHttpClient {
 //        } catch (ParseException ex) {
 //            Logger.getLogger(NicoHttpClient.class.getName()).log(Level.SEVERE, null, ex);
         } catch (SAXException ex) {
-            log.error("", ex);
+            logger.error("", ex);
         } catch (IOException ex) {
-            log.error("", ex);
+            logger.error("", ex);
         } catch (ParserConfigurationException ex) {
-            log.error("", ex);
+            logger.error("", ex);
         } finally {
             try {
                 if (re != null) {
                     re.close();
                 }
             } catch (IOException ex) {
-                log.error("", ex);
+                logger.error("", ex);
             }
         }
         return cont;
@@ -369,29 +369,29 @@ public class NicoHttpClient {
         try {
             HttpResponse response = http.execute(get);
             reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
-            if (log.isTraceEnabled()) {
+            if (logger.isTraceEnabled()) {
                 reader.mark(1024 * 1024);
                 while (true) {
                     String str = reader.readLine();
                     if (str == null) {
                         break;
                     }
-                    log.trace(str);
+                    logger.trace(str);
                 }
                 reader.reset();
             }
             contList = getNicoContents(reader);
         } catch (FeedException ex) {
-            log.warn("アクセスできません: " + url);
-            log.debug("", ex);
+            logger.warn("アクセスできません: " + url);
+            logger.debug("", ex);
         } catch (IOException ex) {
-            log.error("", ex);
+            logger.error("", ex);
         } finally {
             if (reader != null) {
                 try {
                     reader.close();
                 } catch (IOException ex) {
-                    log.error("", ex);
+                    logger.error("", ex);
                 }
             }
         }
@@ -423,8 +423,8 @@ public class NicoHttpClient {
 
             @Override
             public void handleSimpleTag(HTML.Tag t, MutableAttributeSet a, int pos) {
-                log.debug("--------<" + t.toString() + ">--------");
-                log.debug(a);
+                logger.debug("--------<" + t.toString() + ">--------");
+                logger.debug(a);
                 if (HTML.Tag.IMG.equals(t)) {
                     imageLink = a.getAttribute(HTML.Attribute.SRC).toString();
                 }
@@ -438,8 +438,8 @@ public class NicoHttpClient {
                         descFlag = true;
                     }
                 }
-                log.debug("--------<" + t.toString() + ">--------");
-                log.debug(a);
+                logger.debug("--------<" + t.toString() + ">--------");
+                logger.debug(a);
             }
 
             @Override
@@ -447,7 +447,7 @@ public class NicoHttpClient {
                 if (HTML.Tag.P.equals(t)) {
                     descFlag = false;
                 }
-                log.debug("--------</" + t.toString() + ">--------");
+                logger.debug("--------</" + t.toString() + ">--------");
             }
 
             @Override
@@ -455,15 +455,15 @@ public class NicoHttpClient {
                 if (descFlag) {
                     description.append(data);
                 }
-                log.debug("--------TEXT--------");
-                log.debug(data);
+                logger.debug("--------TEXT--------");
+                logger.debug(data);
             }
 
             private void printAttributes(MutableAttributeSet a) {
                 Enumeration e = a.getAttributeNames();
                 while (e.hasMoreElements()) {
                     Object key = e.nextElement();
-                    log.debug("---- " + key.toString() + " : " + a.getAttribute(key));
+                    logger.debug("---- " + key.toString() + " : " + a.getAttribute(key));
                 }
             }
 
@@ -492,7 +492,7 @@ public class NicoHttpClient {
                     Reader reader = new StringReader(sc.getValue());
                     new ParserDelegator().parse(reader, callBack, true);
                 } catch (IOException ex) {
-                    log.error("RSSの読み込み失敗: " + content.getTitle());
+                    logger.error("RSSの読み込み失敗: " + content.getTitle());
                 }
             }
 
@@ -531,7 +531,7 @@ public class NicoHttpClient {
     }
 
     private LinkedHashMap<String, String> getParameterMap(String accessUrl) throws IOException, IllegalStateException {
-        log.debug("アクセス: " + accessUrl);
+        logger.debug("アクセス: " + accessUrl);
         HttpGet get = new HttpGet(accessUrl);
         String resultString;
         BufferedReader reader = null;
@@ -545,7 +545,7 @@ public class NicoHttpClient {
             }
             resultString = strBuilder.toString();
             response.getEntity().consumeContent();
-            log.debug(resultString);
+            logger.debug(resultString);
         } finally {
             if (reader != null) {
                 reader.close();
@@ -618,7 +618,7 @@ public class NicoHttpClient {
         String realId = videoId;
         String title;
         String watchUrl = WATCH_PAGE + videoId;
-        log.debug("アクセス: " + watchUrl);
+        logger.debug("アクセス: " + watchUrl);
         http.getParams().setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, false);
         try {
             HttpGet get = new HttpGet(watchUrl);
@@ -663,7 +663,7 @@ public class NicoHttpClient {
         final URL url = vi.getVideoUrl();
         if (nowStatus == Status.GET_LOW || !needLowFile) {
             if (url.toString().contains("low")) {
-                log.info("エコノミー動画のためスキップ: " + vi.getRealVideoId());
+                logger.info("エコノミー動画のためスキップ: " + vi.getRealVideoId());
                 return new GetFlvResult(null, nowStatus, userName);
             }
         }
@@ -674,10 +674,10 @@ public class NicoHttpClient {
         HttpGet get = new HttpGet(url.toURI());
         HttpResponse response = http.execute(get);
         String contentType = response.getEntity().getContentType().getValue();
-        log.debug(contentType);
-        log.debug(downloadFile.toString());
+        logger.debug(contentType);
+        logger.debug(downloadFile.toString());
         if ("text/plain".equals(contentType) || "text/html".equals(contentType)) {
-            log.error("取得できませんでした. サーバが混みあっている可能性があります: " + vi.getRealVideoId());
+            logger.error("取得できませんでした. サーバが混みあっている可能性があります: " + vi.getRealVideoId());
             response.getEntity().consumeContent();
             return new GetFlvResult(null, Status.GET_INFO, userName);
         }
@@ -688,7 +688,7 @@ public class NicoHttpClient {
         BufferedInputStream in = new BufferedInputStream(response.getEntity().getContent());
 
         File file = new File(downloadFile.toString() + "." + ext);
-        log.info("保存します(" + fileSize / 1024 + "KB): " + file.getPath());
+        logger.info("保存します(" + fileSize / 1024 + "KB): " + file.getPath());
         FileOutputStream fos = new FileOutputStream(file);
         BufferedOutputStream out = new BufferedOutputStream(fos);