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.fukurou.util.StringUtil; 021import org.opengion.hayabusa.db.DBTableModel; 022 023/** 024 * 加工なしダブルクォート区切り文字指定データの書き出しクラスです。 025 * 026 * DefaultTableWriter を継承して,データの出力部のみオーバーライドして, 027 * データそのものを加工なしで、ダブルコーテーションで処理して出力します。 028 * 本来は、DefaultTableWriter の出力形態のはずですが、過去の互換性との関係で、 029 * なまデータを出力するクラスを、追加作成しました。 030 * 従来の CSV2 は、このクラスを使用してください。 031 * 032 * @og.rev 3.7.0.3 (2005/03/01) 新規作成 033 * @og.group ファイル出力 034 * 035 * @version 4.0 036 * @author Kazuhiko Hasegawa 037 * @since JDK5.0, 038 */ 039public class TableWriter_Data2 extends TableWriter_Default { 040 /** このプログラムのVERSION文字列を設定します。 {@value} */ 041 private static final String VERSION = "6.4.2.0 (2016/01/29)" ; 042 043 /** 044 * デフォルトコンストラクター 045 * 046 * @og.rev 6.4.2.0 (2016/01/29) PMD refactoring. Each class should declare at least one constructor. 047 */ 048 public TableWriter_Data2() { super(); } // これも、自動的に呼ばれるが、空のメソッドを作成すると警告されるので、明示的にしておきます。 049 050 /** 051 * PrintWriter に DBTableModelのテーブル情報を書き込みます。 052 * 053 * @og.rev 3.7.0.3 (2005/03/01) 新規作成 054 * @og.rev 3.8.0.1 (2005/06/17) DBTypeが NVAR の場合は、元のUnicodeに戻します。 055 * @og.rev 5.1.6.0 (2010/05/01) DbType の初期値(dbType)を利用する。 056 * @og.rev 5.2.1.0 (2010/10/01) useRenderer 対応 057 * @og.rev 6.0.1.2 (2014/08/08) カラム飛ばしできる機能を追加 058 * @og.rev 6.0.4.0 (2014/11/28) データ出力用のレンデラー 059 * 060 * @param table DBTableModelオブジェクト 061 * @param writer PrintWriterオブジェクト 062 */ 063 @Override 064 protected void writeData( final DBTableModel table,final PrintWriter writer ) { 065 final int numberOfRows = table.getRowCount(); 066 final String separator = getSeparator(); 067 final boolean useNumber = isUseNumber(); 068 final boolean useRenderer = isUseRenderer(); // 5.2.1.0 (2010/10/01) 069 070 for( int row=0; row<numberOfRows; row++ ) { 071 if( useNumber ) { 072 writer.print( quotation( String.valueOf( row+1 ) ) ); 073 writer.print( separator ); 074 } 075 076 for( int i=0; i<numberOfColumns; i++ ) { 077 if( i != 0 ) { writer.print( separator ); } 078 final int clm = clmNo[i]; 079 if( clm < 0 ) { continue; } // 6.0.1.2 (2014/08/08) カラム飛ばし 080 081 String val = table.getValue(row,clm); 082 if( dbType[i] == NVAR ) { 083 val = StringUtil.getReplaceEscape( val ); 084 } 085 // 5.2.1.0 (2010/10/01) useRenderer 対応 086 else if( useRenderer ) { 087 // 6.0.4.0 (2014/11/28) データ出力用のレンデラー 088 val = dbColumn[clm].getWriteValue( val ); 089 } 090 091 writer.print( quotation( val ) ); 092 } 093 writer.println(); 094 } 095 } 096}