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 java.util.UUID; 019 020import org.opengion.fukurou.util.TagBuffer; 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のテキストエリアでname属性は付けません。(データは送信されません) 029 * エリアの縦、横サイズはエディタのリッチテキストと同様にして算出されます。 030 * 031 * カラムの表示に必要な属性は, DBColumn オブジェクト より取り出します。 032 * このクラスは、DBColumn オブジェクト毎に1つ作成されます。 033 * 034 * @og.rev 5.9.32.0 (2018/05/02) 新規作成 035 * @og.rev 5.10.1.0 (2018/06/29) size指定の処理を変更。 036 * @og.group データ編集 037 * 038 * @version 4.0 039 * @author Takahashi Masakazu 040 * @since JDK5.0, 041 */ 042public class Renderer_RICHTEXT extends AbstractRenderer { 043 //* このプログラムのVERSION文字列を設定します。 {@value} */ 044 private static final String VERSION = "4.3.5.7 (2009/03/22)" ; 045 046 private final TagBuffer tagBuffer = new TagBuffer(); 047 048 private String size1; 049 private String size2; 050 051 /** 052 * デフォルトコンストラクター。 053 * このコンストラクターで、基本オブジェクトを作成します。 054 * 055 */ 056 public Renderer_RICHTEXT() { 057 // 何もありません。(super を呼び出しません) 058 } 059 060 // デフォルトの値設定 061 private void defaultSet() { 062 size1 = "150"; 063 size2 = "300"; 064 } 065 066 /** 067 * コンストラクター 068 * textareaのサイズを決めるため、sizeとrowを決定する 069 * editorの計算を移植。 070 * 071 * @param clm DBColumnオブジェクト 072 */ 073 private Renderer_RICHTEXT( final DBColumn clm ) { 074 // 2018/06/21 MODIFY size(ViewLength)のみ取得するように変更 075 // String param = StringUtil.nval( clm.getEditorParam(),clm.getViewLength() ); 076 String param = clm.getViewLength(); 077 if( param != null && param.length() != 0 ) { 078 int st = param.indexOf( ',' ); 079 if( st > 0 ) { 080 size1 = param.substring( 0, st ); 081 size2 = param.substring( st + 1); 082 }else { 083 defaultSet(); 084 } 085 }else { 086 defaultSet(); 087 } 088 } 089 090 /** 091 * 各オブジェクトから自分のインスタンスを返します。 092 * 自分自身をキャッシュするのか、新たに作成するのかは、各サブクラスの実装に 093 * まかされます。 094 * 095 * @param clm DBColumnオブジェクト 096 * 097 * @return CellEditorオブジェクト 098 */ 099 public CellRenderer newInstance( final DBColumn clm ) { 100 return new Renderer_RICHTEXT( clm ); 101 } 102 103 /** 104 * データの表示用文字列を返します。 105 * 106 * @param value 入力値 107 * 108 * @return データの表示用文字列 109 */ 110 @Override 111 public String getValue( final String value ) { 112 // uuidをidとして使用する 113 String uuid = UUID.randomUUID().toString(); 114 115 TagBuffer tag = new TagBuffer( "textarea" ); 116 tag.add( "id" , uuid); 117 tag.add( tagBuffer.makeTag() ); 118 tag.setBody( value ); 119 120 return tag.makeTag() + createCLEditorSc(uuid); 121 } 122 123 /** 124 * データの表示用文字列を返します。 125 * 126 * @param row 行番号 127 * @param value 入力値 128 * 129 * @return データ表示用の文字列 130 */ 131 @Override 132 public String getValue( final int row,final String value ) { 133 // uuidをidとして使用する 134 String uuid = UUID.randomUUID().toString(); 135 TagBuffer tag = new TagBuffer( "textarea" ); 136 tag.add( "id" , uuid); 137 tag.add( tagBuffer.makeTag() ); 138 tag.setBody( value ); 139 140 return tag.makeTag( row,value ) + createCLEditorSc(uuid); 141 } 142 143 // CLEditorスクリプトの生成 144 private String createCLEditorSc(String id) { 145 StringBuilder js = new StringBuilder(); 146 js.append("<script type='text/javascript'>"); 147 js.append("var trg = $('#").append(id).append("').cleditor({"); 148 js.append("height:").append(size1); 149 js.append(",width:").append(size2); 150 js.append(",controls:''"); 151 js.append(",bodyStyle:'background-color: transparent;'})[0];"); 152 js.append("trg.disable('true');"); // 操作の無効化 153 js.append("trg.$toolbar.remove();"); // メニューバーの削除 154 js.append("trg.$main.css('background-color','transparent');"); // bodyのstyle設定 155 // linkは新規ウィンドウに表示 156 js.append("$('#").append(id).append("').next('iframe').contents().find('a').attr('target','_blank');"); 157 js.append("</script>"); 158 return js.toString(); 159 } 160}