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 */ 016 package org.opengion.plugin.io; 017 018 import java.io.PrintWriter; 019 020 import org.opengion.fukurou.util.StringUtil; 021 import org.opengion.hayabusa.db.DBTableModel; 022 023 /** 024 * ã€å»?¢äºˆå®šã?åŠ?·¥ãªã—カンマ区åˆ?‚Šãƒ?ƒ–ルクォートファイル(CSV)形弿›¸ãè¾¼ã¿ã‚¯ãƒ©ã‚¹ã§ã™ã? 025 * ã“ã?クラスã¯ã€å»?¢äºˆå®šã§ã™ã?代ã‚りã«ã€Data2 㮠セパレータをカンマ㫠026 * è¨å®šã—ã¦ä½¿ç”¨ã—ã¦ãã ã•ã„ã€? 027 * 028 * DefaultTableWriter を継承ã—ã¦ã?¾ã™ã?ã§?Œãƒ©ãƒ™ãƒ«?Œåå‰ï¼Œãƒ‡ãƒ¼ã‚¿ã®å‡ºåŠ›éƒ¨ã®ã¿ 029 * オーãƒã?ライドã—ã¦?Œå¯å¤‰é•·ã‚«ãƒ³ãƒžåŒºåˆ?‚Šæ–?—ファイルã®å‡ºåŠ›æ©Ÿè?を実ç¾ã—ã¦ã?¾ã™ã? 030 * 031 * ã“ã?クラスã¯ã€æ–‡å—åž‹ã®ãƒ??タ出力時ã®ã€å?é ãŒï¼ã?å ´åˆã?シングルコーãƒ??ションã‚? 032 * 出ã•ãªã?‚ˆã?«å¤‰æ›´ã—ãŸã‚¯ãƒ©ã‚¹ã§ã™ã?(専用特殊クラス) 033 * 034 * @og.formSample 035 * 036 * @og.rev 3.1.9.1 (2003/05/20) æ–°è¦ä½œæ? 037 * @og.group ファイル出åŠ? 038 * 039 * @version 4.0 040 * @author Kazuhiko Hasegawa 041 * @since JDK5.0, 042 */ 043 public class TableWriter_CSV2 extends TableWriter_Default { 044 //* ã“ã?プãƒã‚°ãƒ©ãƒ??VERSIONæ–?—å?ã‚’è¨å®šã—ã¾ã™ã? {@value} */ 045 private static final String VERSION = "5.2.1.0 (2010/10/01)" ; 046 047 // 4.3.4.4 (2009/01/01) 048 // /** 049 // * ãƒ?ƒ•ォルトコンストラクター 050 // * 051 // */ 052 // public TableWriter_CSV2() { 053 // super(); 054 // } 055 056 /** 057 * DBTableModel ã‹ã‚‰ ãƒ??タを作æ?ã—ã¦,PrintWriter ã«æ›¸ãå?ã—ã¾ã™ã? 058 * 059 * @og.rev 3.1.1.0 (2003/03/28) åŒæœŸãƒ¡ã‚½ãƒ?ƒ‰(synchronized付ã)ã‚’éžåŒæœŸã«å¤‰æ›´ã™ã‚‹ã€? 060 * @og.rev 3.5.4.3 (2004/01/05) 引数㫠PrintWriter ã‚’å—ã‘å–るよã?«å¤‰æ›´ã—ã¾ã™ã? 061 * 062 * @param writer PrintWriterオブジェクãƒ? 063 */ 064 @Override 065 public void writeDBTable( final PrintWriter writer ) { 066 super.setSeparator( CSV_SEPARATOR ); // 3.5.6.0 (2004/06/18) 067 super.writeDBTable( writer ); 068 } 069 070 /** 071 * PrintWriter ã« DBTableModelã®ãƒ??ブルæƒ??を書ãè¾¼ã¿ã¾ã™ã? 072 * ã“ã?クラスã§ã¯?Œãƒ‡ãƒ¼ã‚¿ã‚?ãƒ?ƒ–ルコーãƒ??ション(")ã§å›²ã¿ã¾ã™ã? 073 * PrintWriter ã« DBTableModelã®ãƒ??ブルæƒ??を書ãè¾¼ã¿ã¾ã™ã? 074 * 075 * @og.rev 2.0.0.1 (2002/09/20) å…ˆé?ã? ã§ã‹ã¤æ•°å—タイãƒ?S9)ã§ãªã??åˆã« ' ã‚’å?力ã™ã‚‹ã‚ˆã?«ä¿®æ£ 076 * @og.rev 2.0.0.5 (2002/09/30) å…ˆé?ã? ã§ã‹ã¤æ•°å—タイãƒ?S9 or R)ã§ãªã??åˆã« ' ã‚’å?力ã™ã‚‹ã‚ˆã?«ä¿®æ£ã€? 077 * @og.rev 2.3.1.2 (2003/01/28) ãƒ??タ出力時ã«ã€æ”¹è¡ŒãŒä½™å?ã«å‡ºã•れるç®?‰€ã‚’ä¿®æ£ã€? 078 * @og.rev 3.1.0.0 (2003/03/20) DBColumn ã‹ã‚‰ã€getDbType() ã‚ーを直接å–り出ã? 079 * @og.rev 3.1.1.0 (2003/03/28) åŒæœŸãƒ¡ã‚½ãƒ?ƒ‰(synchronized付ã)ã‚’éžåŒæœŸã«å¤‰æ›´ã™ã‚‹ã€? 080 * @og.rev 3.7.0.2 (2005/02/14) è¡Œç•ªå·æƒ??ã‚’ã?出力ã™ã‚?true)/ã—ãªã?false)を指å®? 081 * @og.rev 3.8.0.1 (2005/06/17) DBTypeã?NVAR ã®å ´åˆã?ã€å?ã®Unicodeã«æˆ»ã—ã¾ã™ã? 082 * @og.rev 5.1.6.0 (2010/05/01) DbType ã®åˆæœŸå€¤(dbType)を利用ã™ã‚‹ã€? 083 * @og.rev 5.2.1.0 (2010/10/01) useRenderer 対å¿? 084 * 085 * @param table DBTableModelオブジェクãƒ? 086 * @param writer PrintWriterオブジェクãƒ? 087 */ 088 @Override 089 protected void writeData( final DBTableModel table,final PrintWriter writer ) { 090 int numberOfRows = table.getRowCount(); 091 boolean useNumber = isUseNumber(); 092 boolean useRenderer = isUseRenderer(); // 5.2.1.0 (2010/10/01) 093 094 for( int row=0; row<numberOfRows; row++ ) { 095 if( useNumber ) { 096 writer.print( quotation( String.valueOf( row+1 ) ) ); 097 writer.print( CSV_SEPARATOR ); 098 } 099 100 for( int i=0; i<numberOfColumns; i++ ) { 101 if( i != 0 ) { writer.print( CSV_SEPARATOR ); } 102 int clm = clmNo[i]; 103 String val = table.getValue(row,clm); 104 // if( "NVAR".equals( dbColumn[clm].getDbType()) ) { 105 if( dbType[i] == NVAR ) { 106 val = StringUtil.getReplaceEscape( val ); 107 } 108 // 5.2.1.0 (2010/10/01) useRenderer 対å¿? 109 else if( useRenderer ) { 110 val = StringUtil.spanCut( dbColumn[clm].getRendererValue( val ) ); 111 } 112 113 // é–‹å§‹æ—¥ãªã©ã® 00000000 ã‚’æ–‡å—å?ã‚¿ã‚¤ãƒ—ã§æ¸¡ã? 114 writer.print( quotation( val ) ); 115 } 116 writer.println(); 117 } 118 } 119 120 /** 121 * ãƒ??タを書ãè¾¼ã‚??åˆã?,区åˆ?‚Šæ–?—ã‚’ã‚»ãƒ?ƒˆã—ã¾ã™ã? 122 * ã“ã?クラスã§ã¯?ŒCSV 固定ã?為,区åˆ?‚Šæ–?—ã?ã‚»ãƒ?ƒˆã¯ç„¡åйã«ãªã‚Šã¾ã™ã? 123 * 124 * @og.rev 3.1.1.0 (2003/03/28) åŒæœŸãƒ¡ã‚½ãƒ?ƒ‰(synchronized付ã)ã‚’éžåŒæœŸã«å¤‰æ›´ã™ã‚‹ã€? 125 * 126 * @param sprt 区åˆ?‚Šæ–?? 127 */ 128 @Override 129 public void setSeparator( final String sprt ) { 130 super.setSeparator( CSV_SEPARATOR ) ; // 3.5.6.0 (2004/06/18) 131 } 132 }