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.fukurou.util.StringUtil; 019import org.opengion.fukurou.util.TagBuffer; 020import org.opengion.hayabusa.common.HybsSystem; 021import org.opengion.hayabusa.db.AbstractRenderer; 022import org.opengion.hayabusa.db.CellRenderer; 023import org.opengion.hayabusa.db.DBColumn; 024 025/** 026 * TEXTAREA レンデラは、カラムのデータをテキストエリアで表示する場合に 027 * 使用するクラスです。 028 * readonlyのテキストエリアでclass=renderer-textareaとして出力し、 029 * name属性は付けません。(データは送信されません) 030 * エリアの縦、横サイズはエディタのテキストエリアと同様にして算出されます。 031 * 032 * カラムの表示に必要な属性は, DBColumn オブジェクト より取り出します。 033 * このクラスは、DBColumn オブジェクト毎に1つ作成されます。 034 * 035 * @og.rev 4.3.5.7 (2009/03/22) 新規作成 036 * @og.group データ編集 037 * 038 * @version 4.0 039 * @author Takahashi Masakazu 040 * @since JDK5.0, 041 */ 042public class Renderer_TEXTAREA extends AbstractRenderer { 043 /** このプログラムのVERSION文字列を設定します。 {@value} */ 044 private static final String VERSION = "6.2.0.0 (2015/02/27)" ; 045 046 private final int COLUMNS_MAXSIZE = HybsSystem.sysInt( "HTML_COLUMNS_MAXSIZE" ) ; // 表示フィールドの大きさ 047 // viewタグで表示する場合のカラムの大きさ 048 private final int VIEW_COLUMNS_MAXSIZE = HybsSystem.sysInt( "HTML_VIEW_COLUMNS_MAXSIZE" ) ; 049 050 private final TagBuffer tagBuffer = new TagBuffer(); 051 052 private String rows1; 053 private String rows2; 054 private String size1; 055 private String size2; 056 057 /** 058 * デフォルトコンストラクター。 059 * このコンストラクターで、基本オブジェクトを作成します。 060 * 061 */ 062 public Renderer_TEXTAREA() { super(); } // これも、自動的に呼ばれるが、空のメソッドを作成すると警告されるので、明示的にしておきます。 063 064 /** 065 * コンストラクター 066 * textareaのサイズを決めるため、sizeとrowを決定する 067 * editorの計算を移植。 068 * 069 * @og.rev 6.2.0.0 (2015/02/27) フィールドサイズ 追加(VIEW_LENGTHと分離して、役割を明確にする) 070 * 071 * @param clm DBColumnオブジェクト 072 */ 073 private Renderer_TEXTAREA( final DBColumn clm ) { 074 // 6.4.1.1 (2016/01/16) PMD refactoring. It is a good practice to call super() in a constructor 075 super(); 076 077 // 6.2.0.0 (2015/02/27) フィールドサイズ 追加(VIEW_LENGTHと分離して、役割を明確にする) 078 size1 = String.valueOf( clm.getFieldSize( COLUMNS_MAXSIZE ) ); 079 size2 = String.valueOf( clm.getFieldSize( VIEW_COLUMNS_MAXSIZE ) ); 080 081 final int r1 = clm.getTotalSize() / Integer.parseInt( size1 ) + 1; 082 if( r1 > 5 ) { 083 rows1 = "5"; 084 } 085 else { 086 rows1 = String.valueOf( r1 ); 087 } 088 089 final int r2 = clm.getTotalSize() / Integer.parseInt( size2 ) + 1; 090 if( r2 > 5 ) { 091 rows2 = "5"; 092 } 093 else { 094 rows2 = String.valueOf( r2 ); 095 } 096 097 final String param = StringUtil.nval( clm.getRendererParam(), clm.getViewLength() ); 098 if( param != null && param.length() != 0 ) { 099 final int st = param.indexOf( ',' ); 100 if( st > 0 ) { 101 rows1 = param.substring( 0, st ); 102 rows2 = rows1; 103 size1 = param.substring( st + 1 ); 104 size2 = size1; 105 } 106 } 107 } 108 109 /** 110 * 各オブジェクトから自分のインスタンスを返します。 111 * 自分自身をキャッシュするのか、新たに作成するのかは、各サブクラスの実装に 112 * まかされます。 113 * 114 * @param clm DBColumnオブジェクト 115 * 116 * @return CellEditorオブジェクト 117 * @og.rtnNotNull 118 */ 119 public CellRenderer newInstance( final DBColumn clm ) { 120 return new Renderer_TEXTAREA( clm ); 121 } 122 123 /** 124 * データの表示用文字列を返します。 125 * 126 * @og.rev 6.0.4.0 (2014/11/28) ロジックの共通化 127 * 128 * @param value 入力値 129 * 130 * @return データの表示用文字列 131 * @og.rtnNotNull 132 */ 133 @Override 134 public String getValue( final String value ) { 135 return getRowsColsValue( value==null ? "" : value,size1,rows1 ); 136 137 } 138 139 /** 140 * データの表示用文字列を返します。 141 * 142 * @og.rev 6.0.4.0 (2014/11/28) ロジックの共通化 143 * 144 * @param row 行番号 145 * @param value 入力値 146 * 147 * @return データ表示用の文字列 148 * @og.rtnNotNull 149 */ 150 @Override 151 public String getValue( final int row,final String value ) { 152 return getRowsColsValue( value==null ? "" : value,size2,rows2 ); 153 154 } 155 156 /** 157 * データ出力用の文字列を作成します。 158 * ファイル等に出力する形式を想定しますので、HTMLタグを含まない 159 * データを返します。 160 * 基本は、#getValue( String ) をそのまま返します。 161 * 162 * @og.rev 6.0.4.0 (2014/11/28) データ出力用のレンデラー 163 * 164 * @param value 入力値 165 * 166 * @return データ出力用の文字列 167 * @og.rtnNotNull 168 * @see #getValue( String ) 169 */ 170 @Override 171 public String getWriteValue( final String value ) { 172 return value == null ? "" : value; 173 } 174 175 /** 176 * データの表示用文字列を返します。 177 * 178 * @og.rev 6.0.4.0 (2014/11/28) ロジックの共通化 179 * 180 * @param value 入力値 表示文字列 181 * @param cols 最小カラム数 182 * @param rows 最小行数 183 * 184 * @return データ表示用の文字列 185 * @og.rtnNotNull 186 */ 187 private String getRowsColsValue( final String value,final String cols, final String rows ) { 188 // 6.1.1.0 (2015/01/17) TagBufferの連結記述 189 return new TagBuffer( "textarea" ) 190 .add( "cols" , cols ) 191 .add( "rows" , rows ) 192 .add( "readonly", "readonly" ) 193 .add( "class" , "renderer-textarea" ) 194 .add( tagBuffer.makeTag() ) 195 .addBody( value ) 196 .makeTag(); 197 198 } 199}