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.column; 017 018import org.opengion.hayabusa.db.AbstractEditor; 019import org.opengion.hayabusa.db.CellEditor; 020import org.opengion.hayabusa.db.DBColumn; 021import org.opengion.fukurou.util.XHTMLTag; 022import org.opengion.hayabusa.common.HybsSystem; 023import org.opengion.fukurou.util.Attributes; 024import org.opengion.fukurou.util.StringUtil; 025import org.opengion.fukurou.util.TagBuffer; 026 027import static org.opengion.fukurou.util.StringUtil.isNull; // 6.1.1.0 (2015/01/17) 028 029/** 030 * TEXTAREA エディターは、カラムのデータをテキストエリアで編集する場合に 031 * 使用するクラスです。 032 * 033 * 従来との違いは、cols 属性の最大値を、検索時(query画面)では、HTML_COLUMNS_MAXSIZE を、 034 * 登録時(result画面)では、HTML_VIEW_COLUMNS_MAXSIZE を使用します。 035 * エリアの大きさは、デフォルト値を使用するか、編集パラメータに、x,y形式で 036 * 指定します。 037 * カラムの表示に必要な属性は、DBColumn オブジェクト より取り出します。 038 * このクラスは、DBColumn オブジェクト毎に1つ作成されます。 039 * 040 * @og.rev 4.0.0.0 (2005/01/31) 新規作成 041 * @og.group データ編集 042 * 043 * @version 4.0 044 * @author Kazuhiko Hasegawa 045 * @since JDK5.0, 046 */ 047public class Editor_TEXTAREA extends AbstractEditor { 048 /** このプログラムのVERSION文字列を設定します。 {@value} */ 049 private static final String VERSION = "8.0.0.0 (2021/08/20)" ; 050 051 // 6.9.6.0 (2018/05/07) protected に変更します。 052 /** 列1 */ protected String cols1 ; // 6.4.4.2 (2016/04/01) size1 を使わずに、cols1 を使用 053 /** 列2 */ protected String cols2 ; // 6.4.4.2 (2016/04/01) size2 を使わずに、cols2 を使用 054 /** 行1 */ protected String rows1 ; 055 /** 行2 */ protected String rows2 ; 056 057 /** 058 * デフォルトコンストラクター。 059 * このコンストラクターで、基本オブジェクトを作成します。 060 * 061 * @og.rev 3.1.1.1 (2003/04/03) 各オブジェクトから自分のインスタンスを返すファクトリメソッドを追加。 062 * 063 */ 064 public Editor_TEXTAREA() { super(); } // これも、自動的に呼ばれるが、空のメソッドを作成すると警告されるので、明示的にしておきます。 065 066 /** 067 * コンストラクター。 068 * 069 * @og.rev 3.1.1.1 (2003/04/03) 各オブジェクトから自分のインスタンスを返すファクトリメソッドを追加。 070 * @og.rev 3.2.4.0 (2003/06/12) パラメータより、行列(row,column)情報があれば、その値を利用する。 071 * @og.rev 3.3.1.1 (2003/07/03) name , attributes 属性を final にする。 072 * @og.rev 3.4.0.0 (2003/09/01) 表示パラメータ、編集パラメータ、文字パラメータの追加。 073 * @og.rev 3.5.5.0 (2004/03/12) 漢字入力(IMEモード)をONにするのを、"K" と、"KX" のみとします。 074 * @og.rev 3.5.6.0 (2004/06/18) XHTMLTag の 内部配列 TEXTAREA_KEY を隠蔽します。 075 * @og.rev 4.0.0.0 (2005/01/31) DBColumn の getClassName() を getDbType() に変更 076 * @og.rev 6.4.4.2 (2016/04/01) size1,size2 を使わずに、cols1,cols2 を使用。 077 * @og.rev 7.0.5.1 (2019/09/27) optionAttributes が二重に設定されていたため、削除 078 * @og.rev 8.0.0.0 (2021/08/20) rows,cols がattributes に設定されていた場合の処理。 079 * 080 * @param clm DBColumnオブジェクト 081 */ 082 protected Editor_TEXTAREA( final DBColumn clm ) { 083 super( clm ); 084 final String disabled = clm.isWritable() ? null : "disabled" ; 085 086 final int r1 = clm.getTotalSize()/Integer.parseInt(size1) + 1; // 4.0.0 (2005/01/31) メソッド名変更 087 if( r1 > 5 ) { rows1 = "5"; } 088 else { rows1 = String.valueOf( r1 ); } 089 090 final int r2 = clm.getTotalSize()/Integer.parseInt(size2) + 1; // 4.0.0 (2005/01/31) メソッド名変更 091 if( r2 > 5 ) { rows2 = "5"; } 092 else { rows2 = String.valueOf( r2 ); } 093 094 // 3.7.0.4 (2005/03/14) size に、"rows,cols" を指定できるように変更 095 final String param = StringUtil.nval( clm.getEditorParam(),clm.getViewLength() ); 096 if( param != null && param.length() != 0 ) { 097 final int st = param.indexOf( ',' ); 098 if( st > 0 ) { 099 rows1 = param.substring( 0,st ); 100 rows2 = rows1 ; 101 cols1 = param.substring( st+1 ); 102 cols2 = cols1; 103 } 104 } 105 106 // 6.4.4.2 (2016/04/01) size1,size2 を使わずに、cols1,cols2 を使用。 107 if( cols1 == null || cols2 == null ) { 108 cols1 = size1 ; 109 cols2 = size2 ; 110 } 111 112 // 8.0.0.0 (2021/08/20) rows,cols がattributes に設定されていた場合の処理。 113 // clm から取得したオブジェクトを remove しないと、反映されない。 114 final Attributes editAttri = clm.getEditorAttributes(); 115 final String attRows = editAttri.remove( "rows" ); 116 if( attRows != null ) { rows1 = attRows; rows2 = attRows; } 117 118 final String attCols = editAttri.remove( "cols" ); 119 if( attCols != null ) { cols1 = attCols; cols2 = attCols; } 120 121 // 6.1.1.0 (2015/01/17) Attributesの連結記述 122 attributes = new Attributes() 123 .set( "disabled" , disabled ) 124// .set( clm.getEditorAttributes() ) // #addAttributes( Attributes ) の代替え 125 .set( editAttri ) // #addAttributes( Attributes ) の代替え 126 .add( "class" , clm.getDbType() ); // 4.0.0 (2005/01/31) 127 128 // 6.1.1.0 (2015/01/17) TagBufferの連結記述 129 // 7.0.5.1 (2019/09/27) optionAttributes が二重に設定されていたため、削除 130 tagBuffer.add( XHTMLTag.textareaAttri( attributes ) ); 131// .add( attributes.get( "optionAttributes" ) ); // 6.0.4.0 (2014/11/28) 132 } 133 134 /** 135 * 各オブジェクトから自分のインスタンスを返します。 136 * 自分自身をキャッシュするのか、新たに作成するのかは、各サブクラスの実装に 137 * まかされます。 138 * 139 * @og.rev 3.1.1.1 (2003/04/03) 各オブジェクトから自分のインスタンスを返すファクトリメソッドを追加。 140 * @og.rev 3.1.2.1 (2003/04/10) synchronized を、削除します。 141 * 142 * @param clm DBColumnオブジェクト 143 * 144 * @return CellEditorオブジェクト 145 * @og.rtnNotNull 146 */ 147 public CellEditor newInstance( final DBColumn clm ) { 148 return new Editor_TEXTAREA( clm ); 149 } 150 151 /** 152 * データの編集用文字列を返します。 153 * 154 * @og.rev 4.3.7.2 (2009/06/15) 属性でidが出力される場合は、idを出力しない 155 * @og.rev 5.1.2.0 (2010/01/01) 先頭の'_'による書き込み制御を行わない。(他のクラスとの実装の共通化) 156 * @og.rev 5.1.7.0 (2010/06/01) 動的プルダウン実装見直し 157 * @og.rev 6.4.4.2 (2016/04/01) size1,size2 を使わずに、cols1,cols2 を使用。 158 * 159 * @param value 入力値 160 * 161 * @return データの編集用文字列 162 * @og.rtnNotNull 163 */ 164 @Override 165 public String getValue( final String value ) { 166 // 6.1.1.0 (2015/01/17) TagBufferの連結記述 167 return new TagBuffer( "textarea" ) 168 .add( "name" , name ) 169 .add( "id" , name , isNull( attributes.get( "id" ) ) ) // 4.3.7.2 (2009/06/15) 170 .add( "cols" , cols1 ) // 6.4.4.2 (2016/04/01) 171 .add( "rows" , rows1 ) 172 .add( tagBuffer.makeTag() ) 173 .addBody( value ) 174 .makeTag(); 175 } 176 177 /** 178 * name属性を変えた、データ表示/編集用のHTML文字列を作成します。 179 * テーブル上の name に 行番号を付加して、名前_行番号 で登録するキーを作成し、 180 * リクエスト情報を1つ毎のフィールドで処理できます。 181 * 182 * @og.rev 3.1.0.0 (2003/03/20) 名前と行番号の区切り記号を "^" から "__" に変更。 183 * @og.rev 3.5.5.0 (2004/03/12) 名前と行番号の区切り記号("__")を、HybsSystem.JOINT_STRING に変更。 184 * @og.rev 4.3.7.2 (2009/06/15) 属性でidが出力される場合は、idを出力しない 185 * @og.rev 5.1.2.0 (2010/01/01) 先頭の'_'による書き込み制御を行わない。(他のクラスとの実装の共通化) 186 * @og.rev 5.1.7.0 (2010/06/01) 動的プルダウン実装見直し 187 * @og.rev 6.4.4.2 (2016/04/01) size1,size2 を使わずに、cols1,cols2 を使用。 188 * 189 * @param row 行番号 190 * @param value 入力値 191 * 192 * @return データ表示/編集用の文字列 193 * @og.rtnNotNull 194 */ 195 @Override 196 public String getValue( final int row,final String value ) { 197 final String newName = name + HybsSystem.JOINT_STRING + row; 198 199 // 6.1.1.0 (2015/01/17) TagBufferの連結記述 200 return new TagBuffer( "textarea" ) 201 .add( "name" , newName ) 202 .add( "id" , newName , isNull( attributes.get( "id" ) ) ) // 4.3.7.2 (2009/06/15) 203 .add( "cols" , cols2 ) // 6.4.4.2 (2016/04/01) 204 .add( "rows" , rows2 ) 205 .add( tagBuffer.makeTag() ) 206 .addBody( value ) 207 .makeTag( row,value ); 208 } 209}