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.PrintWriter;
019
020import org.opengion.hayabusa.db.DBTableModel;
021
022/**
023 * 固定長文字ファイルの書き出しクラスです。
024 * DefaultTableWriter を継承していますので,ラベル,名前,サイズ,データの
025 * 出力部のみオーバーライドして,固定長文字ファイルの出力機能を実現しています。
026 *
027 * なお,固定長出力されるのは,データ部のみで,ラベル,名前,サイズは,
028 * separator で指定された区切り記号で連結されて出力されます。
029 *
030 * @og.group ファイル出力
031 *
032 * @version  4.0
033 * @author   Kazuhiko Hasegawa
034 * @since    JDK5.0,
035 */
036public class TableWriter_Fixed extends TableWriter_Default {
037        //* このプログラムのVERSION文字列を設定します。   {@value} */
038        private static final String VERSION = "6.0.1.2 (2014/08/08)" ;
039
040        /**
041         * PrintWriter に DBTableModelのテーブル情報を書き込みます。
042         *
043         * @og.rev 2.3.1.2 (2003/01/28) データ出力時に、改行が余分に出される箇所を修正。
044         * @og.rev 3.1.1.0 (2003/03/28) 同期メソッド(synchronized付き)を非同期に変更する。
045         * @og.rev 3.5.4.5 (2004/01/23) 文字列のエンコード指定(桁数判定)
046         * @og.rev 6.0.1.2 (2014/08/08) カラム飛ばしできる機能を追加
047         *
048         * @param       table  DBTableModelオブジェクト
049         * @param       writer PrintWriterオブジェクト
050         */
051        @Override
052        protected void writeData( final DBTableModel table,final PrintWriter writer ) {
053                int numberOfRows    =  table.getRowCount();
054                String encode = getEncode();
055
056                for( int row=0; row<numberOfRows; row++ ) {
057                        for( int i=0; i<numberOfColumns; i++ ) {
058                                int clm = clmNo[i];
059                                if( clm < 0 ) { continue; }                     // 6.0.1.2 (2014/08/08) カラム飛ばし
060                                writer.print( dbColumn[clm].getWriterValue( table.getValue(row,clm),encode ) );
061                        }
062                        writer.println();
063                }
064        }
065}