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 = "7.0.5.1 (2019/09/27)" ;
050
051        // 6.9.6.0 (2018/05/07) protected に変更します。
052        protected  String       cols1            ;              // 6.4.4.2 (2016/04/01) size1 を使わずに、cols1 を使用
053        protected  String       cols2            ;              // 6.4.4.2 (2016/04/01) size2 を使わずに、cols2 を使用
054        protected  String       rows1            ;
055        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         *
079         * @param       clm     DBColumnオブジェクト
080         */
081        protected Editor_TEXTAREA( final DBColumn clm ) {
082                super( clm );
083                final String  disabled = clm.isWritable() ? null : "disabled" ;
084
085                final int r1 = clm.getTotalSize()/Integer.parseInt(size1) + 1;          // 4.0.0 (2005/01/31) メソッド名変更
086                if( r1 > 5 ) { rows1 = "5"; }
087                else { rows1 = String.valueOf( r1 ); }
088
089                final int r2 = clm.getTotalSize()/Integer.parseInt(size2) + 1;          // 4.0.0 (2005/01/31) メソッド名変更
090                if( r2 > 5 ) { rows2 = "5"; }
091                else { rows2 = String.valueOf( r2 ); }
092
093                // 3.7.0.4 (2005/03/14) size に、"rows,cols" を指定できるように変更
094                final String param = StringUtil.nval( clm.getEditorParam(),clm.getViewLength() );
095                if( param != null && param.length() != 0 ) {
096                        final int st = param.indexOf( ',' );
097                        if( st > 0 ) {
098                                rows1 = param.substring( 0,st );
099                                rows2 = rows1 ;
100                                cols1 = param.substring( st+1 );
101                                cols2 = cols1;
102                        }
103                }
104
105                // 6.4.4.2 (2016/04/01) size1,size2 を使わずに、cols1,cols2 を使用。
106                if( cols1 == null || cols2 == null ) {
107                        cols1   = size1  ;
108                        cols2   = size2  ;
109                }
110
111                // 6.1.1.0 (2015/01/17) Attributesの連結記述
112                attributes = new Attributes()
113                                        .set( "disabled"        , disabled )
114                                        .set( clm.getEditorAttributes() )                               // #addAttributes( Attributes ) の代替え
115                                        .add( "class"           , clm.getDbType() );            // 4.0.0 (2005/01/31)
116
117                // 6.1.1.0 (2015/01/17) TagBufferの連結記述
118                // 7.0.5.1 (2019/09/27) optionAttributes が二重に設定されていたため、削除
119                tagBuffer.add( XHTMLTag.textareaAttri( attributes ) );
120//                               .add( attributes.get( "optionAttributes" ) );          // 6.0.4.0 (2014/11/28)
121        }
122
123        /**
124         * 各オブジェクトから自分のインスタンスを返します。
125         * 自分自身をキャッシュするのか、新たに作成するのかは、各サブクラスの実装に
126         * まかされます。
127         *
128         * @og.rev 3.1.1.1 (2003/04/03) 各オブジェクトから自分のインスタンスを返すファクトリメソッドを追加。
129         * @og.rev 3.1.2.1 (2003/04/10) synchronized を、削除します。
130         *
131         * @param       clm     DBColumnオブジェクト
132         *
133         * @return      CellEditorオブジェクト
134         * @og.rtnNotNull
135         */
136        public CellEditor newInstance( final DBColumn clm ) {
137                return new Editor_TEXTAREA( clm );
138        }
139
140        /**
141         * データの編集用文字列を返します。
142         *
143         * @og.rev 4.3.7.2 (2009/06/15) 属性でidが出力される場合は、idを出力しない
144         * @og.rev 5.1.2.0 (2010/01/01) 先頭の'_'による書き込み制御を行わない。(他のクラスとの実装の共通化)
145         * @og.rev 5.1.7.0 (2010/06/01) 動的プルダウン実装見直し
146         * @og.rev 6.4.4.2 (2016/04/01) size1,size2 を使わずに、cols1,cols2 を使用。
147         *
148         * @param   value 入力値
149         *
150         * @return  データの編集用文字列
151         * @og.rtnNotNull
152         */
153        @Override
154        public String getValue( final String value ) {
155                // 6.1.1.0 (2015/01/17) TagBufferの連結記述
156                return new TagBuffer( "textarea" )
157                                                .add( "name"    , name )
158                                                .add( "id"              , name , isNull( attributes.get( "id" ) ) )             // 4.3.7.2 (2009/06/15)
159                                                .add( "cols"    , cols1 )                               // 6.4.4.2 (2016/04/01)
160                                                .add( "rows"    , rows1 )
161                                                .add( tagBuffer.makeTag() )
162                                                .addBody( value )
163                                                .makeTag();
164        }
165
166        /**
167         * name属性を変えた、データ表示/編集用のHTML文字列を作成します。
168         * テーブル上の name に 行番号を付加して、名前_行番号 で登録するキーを作成し,
169         * リクエスト情報を1つ毎のフィールドで処理できます。
170         *
171         * @og.rev 3.1.0.0 (2003/03/20) 名前と行番号の区切り記号を "^" から "__" に変更。
172         * @og.rev 3.5.5.0 (2004/03/12) 名前と行番号の区切り記号("__")を、HybsSystem.JOINT_STRING  に変更。
173         * @og.rev 4.3.7.2 (2009/06/15) 属性でidが出力される場合は、idを出力しない
174         * @og.rev 5.1.2.0 (2010/01/01) 先頭の'_'による書き込み制御を行わない。(他のクラスとの実装の共通化)
175         * @og.rev 5.1.7.0 (2010/06/01) 動的プルダウン実装見直し
176         * @og.rev 6.4.4.2 (2016/04/01) size1,size2 を使わずに、cols1,cols2 を使用。
177         *
178         * @param   row   行番号
179         * @param   value 入力値
180         *
181         * @return  データ表示/編集用の文字列
182         * @og.rtnNotNull
183         */
184        @Override
185        public String getValue( final int row,final String value ) {
186                final String newName = name + HybsSystem.JOINT_STRING + row;
187
188                // 6.1.1.0 (2015/01/17) TagBufferの連結記述
189                return new TagBuffer( "textarea" )
190                                                .add( "name"    , newName )
191                                                .add( "id"              , newName , isNull( attributes.get( "id" ) ) )          // 4.3.7.2 (2009/06/15)
192                                                .add( "cols"    , cols2 )                               // 6.4.4.2 (2016/04/01)
193                                                .add( "rows"    , rows2 )
194                                                .add( tagBuffer.makeTag() )
195                                                .addBody( value )
196                                                .makeTag( row,value );
197        }
198}