001/* 002 * Copyright (c) 2009 The openGion Project. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 013 * either express or implied. See the License for the specific language 014 * governing permissions and limitations under the License. 015 */ 016package org.opengion.plugin.io; 017 018import java.io.File; // 6.2.0.0 (2015/02/27) 019 020import org.opengion.fukurou.model.POIUtil; // 6.1.0.0 (2014/12/26) イベント方式 021import org.opengion.fukurou.model.TextConverter; // 6.3.1.0 (2015/06/28) 022 023import org.opengion.hayabusa.io.AbstractTableReader; // 6.2.0.0 (2015/02/27) 024 025/** 026 * POI による、Word,PoworPoint,Excel,Textのファイルを読み取る実装クラスです。 027 * 028 * ファイル名、シート名を指定して、データを読み取ることが可能です。 029 * 入力形式は、openXML形式にも対応しています。 030 * 031 * POIUtil#extractor(File)を使用して、行分割しますので、第一カラムが # で始まる行も 032 * 読み取り対象にします。 033 * カラム名は、TEXT 一つだけになります。 034 * 通常のTableReader の各種機能は、使用できませんので、ご注意ください。 035 * 036 * ※ 6.3.1.0 (2015/06/28) カラムに、CMNT属性も追加。これは、位置情報になる為、 037 * 対訳や、差分チェック時に使用する予定です。 038 * 039 * @og.rev 6.2.3.0 (2015/05/01) 新規作成 040 * @og.group ファイル入力 041 * 042 * @version 6.2 043 * @author Kazuhiko Hasegawa 044 * @since JDK8.0, 045 */ 046public class TableReader_POI extends AbstractTableReader { 047 /** このプログラムのVERSION文字列を設定します。 {@value} */ 048 private static final String VERSION = "6.4.2.0 (2016/01/29)" ; 049 050 /** 051 * デフォルトコンストラクター 052 * 053 * @og.rev 6.4.2.0 (2016/01/29) PMD refactoring. Each class should declare at least one constructor. 054 */ 055 public TableReader_POI() { super(); } // これも、自動的に呼ばれるが、空のメソッドを作成すると警告されるので、明示的にしておきます。 056 057 /** 058 * DBTableModel から 各形式のデータを作成して,BufferedReader より読み取ります。 059 * コメント/空行を除き、最初の行は、必ず項目名が必要です。 060 * それ以降は、コメント/空行を除き、データとして読み込んでいきます。 061 * このメソッドは、EXCEL 読み込み時に使用します。 062 * 063 * @og.rev 6.2.3.0 (2015/05/01) 新規作成 064 * @og.rev 6.2.4.2 (2015/05/29) POIUtil#extractor → textReader に変更 065 * @og.rev 6.3.1.0 (2015/06/28) TextConverterに、引数(cmnt)を追加 066 * @og.rev 6.3.9.1 (2015/11/27) 修飾子を、なし → private に変更。 067 * 068 * @param file 読み取り元ファイル 069 * @param enc ファイルのエンコード文字列 070 */ 071 @Override 072 public void readDBTable( final File file , final String enc ) { 073 // final boolean isNullSkip = "TEXT".equalsIgnoreCase( nullSkipClm ); // 6.2.4.2 (2015/05/29) 074 // final int skipCnt = getSkipRowCount() ; 075 final TextConverter<String,String> conv = new TextConverter<String,String>() { 076 private int cnt ; // 6.3.9.1 (2015/11/27) 修飾子を、なし → private に変更。 077 078 /** 079 * 入力文字列を、変換します。 080 * 081 * @param val 入力文字列 082 * @param cmnt コメント 083 * @return 変換文字列(変換されない場合は、null) 084 */ 085 @Override 086 public String change( final String val,final String cmnt ) { 087 if( val != null && !val.isEmpty() ) { 088 final String[] vals = new String[] { val , cmnt } ; 089 setTableColumnValues( vals,cnt++ ); 090 } 091 return null; // いづれにしても変換しない。 092 } 093 }; 094 095 setTableDBColumn( new String[] { "TEXT","CMNT" } ) ; // 6.3.1.0 (2015/06/28) 096 POIUtil.textReader( file , conv ); 097 } 098}