001package csv2html; 002 003import java.io.File; 004import java.util.List; 005import utility.StringUtility; 006 007/** 008 * リーダ:情報を記したCSVファイルを読み込んでテーブルに仕立て上げる。 009 */ 010public class Reader extends IO 011{ 012 /** 013 * リーダのコンストラクタ。 014 * @param aTable テーブル 015 */ 016 public Reader(Table aTable) 017 { 018 super(aTable); 019 020 return; 021 } 022 023 /** 024 * ダウンロードしたCSVファイルを読み込む。 025 */ 026 public void perform() 027 { 028 String csvUrl = this.attributes().csvUrl(); 029 String basename = csvUrl.substring(csvUrl.lastIndexOf('/') + 1); 030 File aFile = new File(this.attributes().baseDirectory() + basename); 031 List<List<String>> aCollection = StringUtility.readRowsFromFile(aFile); 032 033 boolean firstTime = true; 034 for (List<String> aRow : aCollection) 035 { 036 if (firstTime) 037 { 038 this.attributes().names(aRow); 039 firstTime = false; 040 } 041 else 042 { 043 Tuple aTuple = new Tuple(this.attributes(), aRow); 044 this.table().add(aTuple); 045 } 046 } 047 048 return; 049 } 050}