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 */
016 package org.opengion.plugin.column;
017
018 import org.opengion.hayabusa.db.AbstractEditor;
019 import org.opengion.hayabusa.db.CellEditor;
020 import org.opengion.hayabusa.db.DBColumn;
021 import org.opengion.fukurou.util.XHTMLTag;
022 import org.opengion.hayabusa.common.HybsSystem;
023 import org.opengion.fukurou.util.Attributes;
024 import org.opengion.fukurou.util.StringUtil;
025 import 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 */
040 public 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 }