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 * 027 * DefaultTableWriter を継承していますので,ラベル,名前,データの出力部のみ 028 * オーバーライドして,可変長カンマ区切り文字ファイルの出力機能を実現しています。 029 * 030 * @og.group ファイル出力 031 * 032 * @version 5.0 033 * @author Takahashi Masaskazu 034 * @og.rev 5.10.18.0 (2019/11/29) 035 * @since JDK5.0, 036 */ 037public class TableWriter_TEXT extends TableWriter_Default { 038 //* このプログラムのVERSION文字列を設定します。 {@value} */ 039 private static final String VERSION = "5.6.9.4 (2013/10/31)" ; 040 041 042 /** 043 * DBTableModel から データを作成して,PrintWriter に書き出します。 044 * 045 * 046 * @param writer PrintWriterオブジェクト 047 */ 048 @Override 049 public void writeDBTable( final PrintWriter writer ) { 050 super.setSeparator( CSV_SEPARATOR ); 051 super.writeDBTable( writer ); 052 } 053 054 /** 055 * PrintWriter に DBTableModelのテーブル情報を書き込みます。 056 * このクラスでは,データを ダブルコーテーション(")で囲みます。 057 * PrintWriter に DBTableModelのテーブル情報を書き込みます。 058 * 059 * 060 * @param table DBTableModelオブジェクト 061 * @param writer PrintWriterオブジェクト 062 */ 063 @Override 064 protected void writeData( final DBTableModel table,final PrintWriter writer ) { 065 int numberOfRows = table.getRowCount(); 066 boolean useNumber = isUseNumber(); 067 boolean useRenderer = isUseRenderer(); 068 069 for( int row=0; row<numberOfRows; row++ ) { 070 if( useNumber ) { 071 writer.print( quotation( String.valueOf( row+1 ) ) ); 072 writer.print( CSV_SEPARATOR ); 073 } 074 075 for( int i=0; i<numberOfColumns; i++ ) { 076 if( i != 0 ) { writer.print( CSV_SEPARATOR ); } 077 int clm = clmNo[i]; 078 String val = table.getValue(row,clm); 079// if( "NVAR".equals( dbColumn[clm].getDbType()) ) { 080 if( dbType[i] == NVAR ) { 081 val = StringUtil.getReplaceEscape( val ); 082 } 083 else if( useRenderer ) { 084 val = StringUtil.spanCut( dbColumn[clm].getRendererValue( val ) ); 085 } 086 087 writer.print( val ); 088 } 089 writer.println(); 090 } 091 } 092 093 /** 094 * データを書き込む場合の,区切り文字をセットします。 095 * このクラスでは,CSV 固定の為,区切り文字のセットは無効になります。 096 * 097 * @param sprt 区切り文字 098 */ 099 @Override 100 public void setSeparator( final String sprt ) { 101 super.setSeparator( CSV_SEPARATOR ) ; 102 } 103}