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