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.hayabusa.db; 017 018import org.opengion.hayabusa.common.HybsSystem; 019import org.opengion.fukurou.util.Attributes; 020import org.opengion.fukurou.util.TagBuffer; 021 022/** 023 * CellEditor の具象クラスで、カラムのデータを編集する場合に使用するクラスです。 024 * 025 * カラムの表示に必要な属性は, DBColumn オブジェクト より取り出します。 026 * このクラスは、DBColumn オブジェクト毎に1つ作成されます。 027 * 028 * @og.group データ編集 029 * 030 * @version 4.0 031 * @author Kazuhiko Hasegawa 032 * @since JDK5.0, 033 */ 034public abstract class AbstractEditor implements CellEditor { 035 private final int COLUMNS_MAXSIZE = HybsSystem.sysInt( "HTML_COLUMNS_MAXSIZE" ) ; // 表示フィールドの大きさ 036 // 3.5.4.7 (2004/02/06) viewタグで表示する場合のカラムの大きさ 037 private final int VIEW_COLUMNS_MAXSIZE = HybsSystem.sysInt( "HTML_VIEW_COLUMNS_MAXSIZE" ) ; 038 039 // 3.3.1.1 (2003/07/03) name , attributes 属性を final にする。 040 protected Attributes attributes ; // SubClass で誤って new することを防止 041 protected String name ; 042 protected String size1 ; 043 protected String size2 ; 044 protected String optAttr ; 045 protected TagBuffer tagBuffer = new TagBuffer() ; 046 047 /** 048 * デフォルトコンストラクター。 049 * このコンストラクターで、基本オブジェクトを作成します。 050 * 051 * @og.rev 3.1.1.1 (2003/04/03) 各オブジェクトから自分のインスタンスを返すファクトリメソッドを追加。 052 * 053 */ 054 public AbstractEditor() { 055 // ここでは処理を行いません。 056 } 057 058 /** 059 * コンストラクター。 060 * 061 * @og.rev 3.1.1.1 (2003/04/03) 各オブジェクトから自分のインスタンスを返すファクトリメソッドを追加。 062 * @og.rev 3.5.4.2 (2003/12/15) 漢字入力(IMEモード)をONにするのを、"K" のみとします。 063 * @og.rev 3.5.4.2 (2003/12/15) size が 1 の場合、CSSファイルでサイズ指定を行うクラスを出力します。 064 * @og.rev 3.5.4.6 (2004/01/30) 漢字入力(IMEモード)をONにするのを、"K" と、"KX" のみとします。 065 * @og.rev 3.5.5.5 (2004/04/23) maxlength の導入 066 * @og.rev 4.0.0.0 (2005/01/31) getFieldSize メソッドを XHTMLTag から DBColumn へ移動 067 * @og.rev 5.1.7.0 (2010/06/01) 動的プルダウン実装見直し 068 * 069 * @param clm DBColumnオブジェクト 070 */ 071 protected AbstractEditor( final DBColumn clm ) { 072 name = clm.getName(); 073 String disabled = clm.isWritable() ? null : "disabled" ; 074 075 int maxlength = clm.getTotalSize(); // 4.0.0 (2005/01/31) メソッド名変更 076 077 attributes = new Attributes(); 078 attributes.set( "type" ,"text" ); 079 attributes.set( "maxlength" ,String.valueOf( maxlength ) ); 080 attributes.set( "disabled" ,disabled ); 081 082 attributes.addAttributes( clm.getEditorAttributes() ); 083 084 String clazz = clm.getDbType(); 085 attributes.add( "class" ,clazz ); 086 if( maxlength <= 5 ) { 087 attributes.add( "class" ,"S0" + maxlength ); 088 } 089 090 optAttr = attributes.get( "optionAttributes" ); 091 092 // 3.5.5.5 (2004/04/23) size の導入、初期値は、一覧表のサイズにします。 093 String size = clm.getViewLength(); // 4.0.0 (2005/01/31) 094 if( size != null ) { 095 if( size.indexOf(',') >= 0 ) { 096 size = size.substring( 0,size.indexOf(',') ) ; 097 } 098 size1 = size ; 099 size2 = size ; 100 } 101 else { 102 // 4.0.0 (2005/01/31) getFieldSize メソッドを XHTMLTag から DBColumn へ移動 103 size1 = String.valueOf(clm.getFieldSize( maxlength,COLUMNS_MAXSIZE )) ; 104 size2 = String.valueOf(clm.getFieldSize( maxlength,VIEW_COLUMNS_MAXSIZE )) ; 105 } 106 } 107 108 /** 109 * データの編集用文字列を返します。 110 * 111 * @og.rev 3.5.5.5 (2004/04/23) viewSize の導入 112 * @og.rev 4.3.7.2 (2009/06/15) 属性でidが出力される場合は、idを出力しない 113 * @og.rev 5.1.7.0 (2010/06/01) 動的プルダウン実装見直し 114 * 115 * @param value 値 116 * 117 * @return データの編集用文字列 118 */ 119 public String getValue( final String value ) { 120 121 TagBuffer tag = new TagBuffer( "input" ); 122 tag.add( "name" , name ); 123 if( attributes.get( "id" ) == null || attributes.get( "id" ).length() == 0 ) { // 4.3.7.2 (2009/06/15) 124 tag.add( "id" , name ); // 4.3.6.0 (2009/04/01) 125 } 126 tag.add( "value" , value ); 127 tag.add( "size" , size1 ); 128 tag.add( tagBuffer.makeTag() ); 129 tag.add( optAttr ); // 3.5.5.8 (2004/05/20) 130 131 return tag.makeTag(); 132 } 133 134 /** 135 * name属性を変えた、データ表示/編集用のHTML文字列を作成します。 136 * テーブル上の name に 行番号を付加して、名前_行番号 で登録するキーを作成し, 137 * リクエスト情報を1つ毎のフィールドで処理できます。 138 * 139 * @og.rev 2.0.0.3 (2002/09/26) optionAttributes 属性に "$i" を使うとその行数に置き換る機能を追加。 140 * @og.rev 3.1.0.0 (2003/03/20) 名前と行番号の区切り記号を "^" から "__" に変更。 141 * @og.rev 3.5.4.2 (2003/12/15) getFieldSize を、XHTMLTag.getFieldSize に変更。 142 * @og.rev 3.5.4.7 (2004/02/06) viewタグで表示する場合のカラムの大きさ VIEW_COLUMNS_MAXSIZE 追加 143 * @og.rev 3.5.5.0 (2004/03/12) 名前と行番号の区切り記号("__")を、HybsSystem.JOINT_STRING に変更。 144 * @og.rev 3.5.5.5 (2004/04/23) viewSize の導入、初期値は、一覧表にあわせました。 145 * @og.rev 3.5.5.5 (2004/04/23) 新規に Attributes オブジェクトを作成する方式を止めます。 146 * @og.rev 4.3.7.2 (2009/06/15) 属性でidが出力される場合は、idを出力しない 147 * @og.rev 5.1.7.0 (2010/06/01) 動的プルダウン実装見直し 148 * 149 * @param row 行番号 150 * @param value 値 151 * 152 * @return データ表示/編集用の文字列 153 */ 154 public String getValue( final int row,final String value ) { 155 TagBuffer tag = new TagBuffer( "input" ); 156 String newName = name + HybsSystem.JOINT_STRING + row; 157 // tag.add( "name" , name + HybsSystem.JOINT_STRING + row ); 158 tag.add( "name" , newName ); // 4.3.6.0 (2009/04/01) 159 if( attributes.get( "id" ) == null || attributes.get( "id" ).length() == 0 ) { // 4.3.7.2 (2009/06/15) 160 tag.add( "id" , newName ); // 4.3.6.0 (2009/04/01) 161 } 162 tag.add( "value" , value ); 163 tag.add( "size" , size2 ); 164 tag.add( tagBuffer.makeTag() ); 165 tag.add( optAttr ); // 3.5.5.8 (2004/05/20) 166 167 return tag.makeTag( row,value ); 168 } 169}