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
027/**
028 * HTMLAREA エディターは、カラムのデータをテキストエリアで編集し、
029 * HTML文字をエスケープして登録する場合に使用するクラスです。
030 *
031 * エスケープする以外はTEXTAREAと同様です
032 *
033 * @og.rev 5.5.8.0 (2012/11/01) 新規作成
034 * @og.group データ編集
035 *
036 * @version  5.0
037 * @author   Takahashi Masakazu
038 * @since    JDK5.0,
039 */
040public class Editor_HTMLAREA extends AbstractEditor {
041        //* このプログラムのVERSION文字列を設定します。   {@value} */
042        private static final String VERSION = "5.5.8.0 (2012/11/01)" ;
043
044        private  String           rows1          ;
045        private  String           rows2          ;
046
047        /**
048         * デフォルトコンストラクター。
049         * このコンストラクターで、基本オブジェクトを作成します。
050         *
051         */
052        public Editor_HTMLAREA() {}
053
054        /**
055         * コンストラクター。
056         *
057         *
058         * @param       clm     DBColumnオブジェクト
059         */
060        private Editor_HTMLAREA( final DBColumn clm ) {
061                super( clm );
062                String  disabled = clm.isWritable() ? null : "disabled" ;
063
064                int r1 = clm.getTotalSize()/Integer.parseInt(size1) + 1;        // // 4.0.0 (2005/01/31) メソッド名変更
065                if( r1 > 5 ) { rows1 = "5"; }
066                else { rows1 = String.valueOf( r1 ); }
067
068                int r2 = clm.getTotalSize()/Integer.parseInt(size2) + 1;        // // 4.0.0 (2005/01/31) メソッド名変更
069                if( r2 > 5 ) { rows2 = "5"; }
070                else { rows2 = String.valueOf( r2 ); }
071
072                // 3.7.0.4 (2005/03/14) size に、"rows,cols" を指定できるように変更
073                String param = StringUtil.nval( clm.getEditorParam(),clm.getViewLength() );
074                if( param != null && param.length() != 0 ) {
075                        int st = param.indexOf( ',' );
076                        if( st > 0 ) {
077                                rows1 = param.substring( 0,st );
078                                rows2 = rows1 ;
079                                size1 = param.substring( st+1 );
080                                size2 = size1;
081                        }
082                }
083
084                attributes = new Attributes();
085                attributes.set( "disabled" ,disabled );
086
087                attributes.addAttributes( clm.getEditorAttributes() );
088                attributes.add( "class" ,clm.getDbType() );             // 4.0.0 (2005/01/31)
089
090                optAttr = attributes.get( "optionAttributes" );
091                tagBuffer.add( XHTMLTag.textareaAttri( attributes ) );
092        }
093
094        /**
095         * 各オブジェクトから自分のインスタンスを返します。
096         * 自分自身をキャッシュするのか、新たに作成するのかは、各サブクラスの実装に
097         * まかされます。
098         *
099         *
100         * @param       clm     DBColumnオブジェクト
101         *
102         * @return      CellEditorオブジェクト
103         */
104        public CellEditor newInstance( final DBColumn clm ) {
105                return new Editor_HTMLAREA( clm );
106        }
107
108        /**
109         * データの編集用文字列を返します。
110         *
111         * @param   value 入力値
112         *
113         * @return  データの編集用文字列
114         */
115        @Override
116        public String getValue( final String value ) {
117
118                TagBuffer tag = new TagBuffer( "textarea" );
119                tag.add( "name"    , name );
120                if( attributes.get( "id" ) == null || attributes.get( "id" ).length() == 0 ) { // 4.3.7.2 (2009/06/15)
121                        tag.add( "id"      , name ); // 4.3.6.0 (2009/04/01)
122                }
123                tag.add( "cols"    , size1 );
124                tag.add( "rows"    , rows1 );
125                tag.add( tagBuffer.makeTag() );
126                tag.add( optAttr );             // 3.5.5.8 (2004/05/20)
127                tag.setBody( StringUtil.htmlFilter(value) );
128
129                return tag.makeTag();
130        }
131
132        /**
133         * name属性を変えた、データ表示/編集用のHTML文字列を作成します。
134         * テーブル上の name に 行番号を付加して、名前_行番号 で登録するキーを作成し,
135         * リクエスト情報を1つ毎のフィールドで処理できます。
136         *
137         * @og.rev 3.1.0.0 (2003/03/20) 名前と行番号の区切り記号を "^" から "__" に変更。
138         * @og.rev 3.5.5.0 (2004/03/12) 名前と行番号の区切り記号("__")を、HybsSystem.JOINT_STRING  に変更。
139         * @og.rev 4.3.7.2 (2009/06/15) 属性でidが出力される場合は、idを出力しない
140         * @og.rev 5.1.2.0 (2010/01/01) 先頭の'_'による書き込み制御を行わない。(他のクラスとの実装の共通化)
141         * @og.rev 5.1.7.0 (2010/06/01) 動的プルダウン実装見直し
142         *
143         * @param   row   行番号
144         * @param   value 入力値
145         *
146         * @return  データ表示/編集用の文字列
147         */
148        @Override
149        public String getValue( final int row,final String value ) {
150
151                TagBuffer tag = new TagBuffer( "textarea" );
152                String newName = name + HybsSystem.JOINT_STRING + row;
153                // tag.add( "name"    , name + HybsSystem.JOINT_STRING + row );
154                tag.add( "name"    , newName );
155                if( attributes.get( "id" ) == null || attributes.get( "id" ).length() == 0 ) { // 4.3.7.2 (2009/06/15)
156                        tag.add( "id"      , newName );
157                }
158                tag.add( "cols"    , size2 );
159                tag.add( "rows"    , rows2 );
160                tag.add( tagBuffer.makeTag() );
161                tag.add( optAttr );             // 3.5.5.8 (2004/05/20)
162                tag.setBody( StringUtil.htmlFilter(value) );
163
164                return tag.makeTag( row,StringUtil.htmlFilter(value) );
165        }
166}