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 018// import java.io.PrintWriter; 019 020// import org.opengion.fukurou.util.StringUtil; // 8.5.2.0 (2023/07/14) Delete 021// import org.opengion.hayabusa.db.DBTableModel; 022 023/** 024 * CSVå½¢å¼ï¾€ï¾žï¾Œï¾žï¾™ï½¸ï½«ï½°ï¾„ファイル(CSV)å½¢å¼æ›¸ãè¾¼ã¿ï½¸ï¾—ï½½ã§ã™ã€‚ 025 * 標準ã¨ç•°ãªã‚‹ã®ã¯ã€æ–‡å—列ã®ã¿ã€ï¾€ï¾žï¾Œï¾žï¾™ï½¸ï½µï½°ï¾„処ç†ã‚’è¡Œã„ã€æ•°å—åž‹ã¯ã€ï¾€ï¾žï¾Œï¾žï¾™ï½¸ï½µï½°ï¾„ã‚‚ 026 * ゼロカï¾ï¾ã‚‚付ã‘ã¾ã›ã‚“。 027 * 028 * DefaultTableWriter を継承ã—ã¦ã„ã¾ã™ã®ã§ã€ï¾—ï¾ï¾žï¾™ã€åå‰ã€ï¾ƒï¾žï½°ï¾€ã®å‡ºåŠ›éƒ¨ã®ã¿ 029 * オーバーライドã—ã¦ã€å¯å¤‰é•·CSVå½¢å¼ï¾Œï½§ï½²ï¾™ã®å‡ºåŠ›æ©Ÿèƒ½ã‚’実ç¾ã—ã¦ã„ã¾ã™ã€‚ 030 * 031 * [writeData] 032 * 区切り : CSV_SEPARATOR 固定 033 * è¡Œç•ªå· : ( è¡Œç•ªå· + 1 ) 034 * カラムデータ: æ•°å—åž‹ val 035 * : ãれ以外 quotation( val ) 036 * 037 * @og.rev 5.6.9.4 (2013/10/31) æ–°è¦ä½œæˆ 038 * @og.rev 8.5.6.1 (2024/03/29) TableWriter_CSV を継承ã—ã¾ã™ã€‚ 039 * @og.group ファイル出力 040 * 041 * @version 8.5 042 * @author Kazuhiko Hasegawa 043 * @since JDK21.0, 044 */ 045// public class TableWriter_CSV3 extends TableWriter_Default { 046public class TableWriter_CSV3 extends TableWriter_CSV { 047 /** ã“ã®ï¾Œï¾Ÿï¾›ï½¸ï¾žï¾—ムã®VERSIONæ–‡å—列をè¨å®šã—ã¾ã™ã€‚ {@value} */ 048 private static final String VERSION = "8.5.6.1 (2024/03/29)" ; 049 050 /** 051 * デフォルトコï¾ï½½ï¾„ラクター 052 * 053 * @og.rev 6.4.2.0 (2016/01/29) PMD refactoring. Each class should declare at least one constructor. 054 */ 055 public TableWriter_CSV3() { super(); } // ã“れもã€è‡ªå‹•çš„ã«å‘¼ã°ã‚Œã‚‹ãŒã€ç©ºã®ï¾’ソッドを作æˆã™ã‚‹ã¨è¦å‘Šã•ã‚Œã‚‹ã®ã§ã€æ˜Žç¤ºçš„ã«ã—ã¦ãŠãã¾ã™ã€‚ 056 057// /** 058// * DBTableModel ã‹ã‚‰ データを作æˆã—ã¦ã€PrintWriter ã«æ›¸ã出ã—ã¾ã™ã€‚ 059// * 060// * @og.rev 8.5.6.1 (2024/03/29) TableWriter_CSV を継承ã—ã¾ã™ã€‚ 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 6.0.1.2 (2014/08/08) カラム飛ã°ã—ã§ãã‚‹æ©Ÿèƒ½ã‚’è¿½åŠ 076// * @og.rev 6.0.4.0 (2014/11/28) データ出力用ã®ï¾šï¾ï¾ƒï¾žï¾—ï½° 077// * @og.rev 7.2.6.1 (2020/07/17) 行番å·ã«ï¾€ï¾žï¾Œï¾žï¾™ï½¸ï½µï½°ï¾„ã¯ä»˜ã‘ã¾ã›ã‚“。 078// * @og.rev 8.5.2.0 (2023/07/14) 一部ã®æ©Ÿèƒ½å»ƒæ¢ã«ã‚ˆã‚‹ä¿®æ£(å•åˆãƒ»ï¾„ラブル 0200010980) 079// * @og.rev 8.5.6.1 (2024/03/29) TableWriter_CSV を継承ã—ã¾ã™ã€‚ 080// * 081// * @param table DBTableModelオブジェクト 082// * @param writer PrintWriterオブジェクト 083// */ 084// @Override 085// protected void writeData( final DBTableModel table,final PrintWriter writer ) { 086// final int numberOfRows = table.getRowCount(); 087// final boolean useNumber = isUseNumber(); 088// final boolean useRenderer = isUseRenderer(); // 5.2.1.0 (2010/10/01) 089// 090// for( int row=0; row<numberOfRows; row++ ) { 091// if( useNumber ) { 092//// writer.print( quotation( String.valueOf( row+1 ) ) ); 093// writer.print( String.valueOf( row+1 ) ); // 7.2.6.1 (2020/07/17) 行番å·ã«ï¾€ï¾žï¾Œï¾žï¾™ï½¸ï½µï½°ï¾„ã¯ä»˜ã‘ã¾ã›ã‚“。 094// writer.print( CSV_SEPARATOR ); 095// } 096// 097// for( int i=0; i<numberOfColumns; i++ ) { 098// if( i != 0 ) { writer.print( CSV_SEPARATOR ); } 099// final int clm = clmNo[i]; 100// if( clm < 0 ) { continue; } // 6.0.1.2 (2014/08/08) カラム飛ã°ã— 101// 102// String val = table.getValue(row,clm); 103//// if( dbType[i] == NVAR ) { // 8.5.2.0 (2023/07/14) Delete 104//// val = StringUtil.getReplaceEscape( val ); // 8.5.2.0 (2023/07/14) Delete 105//// } // 8.5.2.0 (2023/07/14) Delete 106// // 5.2.1.0 (2010/10/01) useRenderer 対応 107//// else if( useRenderer ) { // 8.5.2.0 (2023/07/14) Modify 108// if( useRenderer ) { 109// // 6.0.4.0 (2014/11/28) データ出力用ã®ï¾šï¾ï¾ƒï¾žï¾—ï½° 110// val = dbColumn[clm].getWriteValue( val ); 111// } 112// 113// // æ•°å—åž‹ã«ã¯ã€ï¾€ï¾žï¾Œï¾žï¾™ï½¸ï½µï½°ï¾„ã¯ä»˜ã‘ã¾ã›ã‚“。 114// if( dbType[i] == NUMBER ) { 115// writer.print( val ); 116// } 117// else { 118// writer.print( quotation( val ) ); 119// } 120// } 121// writer.println(); 122// } 123// } 124 125 /** 126 * å…ˆé ã®è¡Œç•ªå·ã«å¯¾ã—ã¦ã®ï½¸ï½µï½°ï¾ƒï½°ï½¼ï½®ï¾å‡¦ç†ã‚’è¡Œã„ã¾ã™ã€‚ 127 * 128 * サブクラスã«ã‚ˆã£ã¦å‡¦ç†æ–¹æ³•ãŒç•°ãªã‚Šã¾ã™ã€‚ 129 * 130 * @og.rev 8.5.6.1 (2024/03/29) 継承ã§ä½¿ãˆã‚‹ã‚ˆã†ã«ã€ä¸€éƒ¨ä¿®æ£ã—ã¾ã™ã€‚ 131 * 132 * @param row è¡Œç•ªå· 133 * 134 * @return 変æ›å¾Œã®æ–‡å—列 135 */ 136 protected String numberQuotation( final int row ) { 137 return String.valueOf( row+1 ); // 7.2.6.1 (2020/07/17) 行番å·ã«ï¾€ï¾žï¾Œï¾žï¾™ï½¸ï½µï½°ï¾„ã¯ä»˜ã‘ã¾ã›ã‚“。 138 } 139 140 /** 141 * データを書ãè¾¼ã‚€å ´åˆã®åŒºåˆ‡ã‚Šæ–‡å—をセットã—ã¾ã™ã€‚ 142 * ã“ã®ï½¸ï¾—ï½½ã§ã¯ã€CSV 固定ã®ç‚ºã€åŒºåˆ‡ã‚Šæ–‡å—ã®ï½¾ï½¯ï¾„ã¯ç„¡åŠ¹ã«ãªã‚Šã¾ã™ã€‚ 143 * 144 * @og.rev 8.5.6.1 (2024/03/29) 継承ã§ä½¿ãˆã‚‹ã‚ˆã†ã«ã€ä¸€éƒ¨ä¿®æ£ã—ã¾ã™ã€‚ 145 * 146 * @param val 入力文å—列 147 * @param dtype DBタイプ(STRING/NUMBER) 148 * 149 * @return 変æ›å¾Œã®æ–‡å—列 150 */ 151 protected String dataQuotation( final String val, final int dtype ) { 152 // æ•°å—åž‹ã«ã¯ã€ï¾€ï¾žï¾Œï¾žï¾™ï½¸ï½µï½°ï¾„ã¯ä»˜ã‘ã¾ã›ã‚“。 153 return dtype == NUMBER ? val : quotation( val ); 154 } 155 156// /** 157// * データを書ãè¾¼ã‚€å ´åˆã®åŒºåˆ‡ã‚Šæ–‡å—をセットã—ã¾ã™ã€‚ 158// * ã“ã®ï½¸ï¾—ï½½ã§ã¯ã€CSV 固定ã®ç‚ºã€åŒºåˆ‡ã‚Šæ–‡å—ã®ï½¾ï½¯ï¾„ã¯ç„¡åŠ¹ã«ãªã‚Šã¾ã™ã€‚ 159// * 160// * @og.rev 8.5.6.1 (2024/03/29) setSeparator ã‚’csvInit()ã§è¡Œã„ã¾ã™ã€‚ 161// * 162// * @param sprt åŒºåˆ‡ã‚Šæ–‡å— 163// */ 164// @Override 165// public void setSeparator( final String sprt ) { 166// super.setSeparator( CSV_SEPARATOR ) ; // 3.5.6.0 (2004/06/18) 167// } 168}