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.0.1.2 (2014/08/08)" ; 042 043 /** 044 * PrintWriter に DBTableModelのテーブル情報を書き込みます。 045 * 046 * @og.rev 3.7.0.3 (2005/03/01) 新規作成 047 * @og.rev 3.8.0.1 (2005/06/17) DBTypeが NVAR の場合は、元のUnicodeに戻します。 048 * @og.rev 5.1.6.0 (2010/05/01) DbType の初期値(dbType)を利用する。 049 * @og.rev 5.2.1.0 (2010/10/01) useRenderer 対応 050 * @og.rev 6.0.1.2 (2014/08/08) カラム飛ばしできる機能を追加 051 * 052 * @param table DBTableModelオブジェクト 053 * @param writer PrintWriterオブジェクト 054 */ 055 @Override 056 protected void writeData( final DBTableModel table,final PrintWriter writer ) { 057 int numberOfRows = table.getRowCount(); 058 String separator = getSeparator(); 059 boolean useNumber = isUseNumber(); 060 boolean useRenderer = isUseRenderer(); // 5.2.1.0 (2010/10/01) 061 062 for( int row=0; row<numberOfRows; row++ ) { 063 if( useNumber ) { 064 writer.print( quotation( String.valueOf( row+1 ) ) ); 065 writer.print( separator ); 066 } 067 068 for( int i=0; i<numberOfColumns; i++ ) { 069 if( i != 0 ) { writer.print( separator ); } 070 int clm = clmNo[i]; 071 if( clm < 0 ) { continue; } // 6.0.1.2 (2014/08/08) カラム飛ばし 072 073 String val = table.getValue(row,clm); 074// if( "NVAR".equals( dbColumn[clm].getDbType()) ) { 075 if( dbType[i] == NVAR ) { 076 val = StringUtil.getReplaceEscape( val ); 077 } 078 // 5.2.1.0 (2010/10/01) useRenderer 対応 079 else if( useRenderer ) { 080 val = StringUtil.spanCut( dbColumn[clm].getRendererValue( val ) ); 081 } 082 083 writer.print( quotation( val ) ); 084 } 085 writer.println(); 086 } 087 } 088}