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 * IMAGE レンデラは、value で指定したファイルをimgタグで表示する場合に 027 * 使用するクラスです。 028 * imgのサイズはレンデラーパラメータに、設定したい属性を記述します。 029 * 例えば、width='600px' height='450px' border='0' などです。 030 * src属性はvalueを設定し、name属性はカラム名(複数行の場合は、行番号付きの名前) 031 * alt属性は、そのままvalueを設定しておきます。 032 * img の親には、div要素とclass="Renderer_IMAGE" を付与しておきます。 033 * 034 * <div class="Renderer_IMAGE"> 035 * <img name="カラム名" src="valueの値" alt="valueの値" レンデラーパラメータ > 036 * </div> 037 * 038 * カラムの表示に必要な属性は, DBColumn オブジェクト より取り出します。 039 * このクラスは、DBColumn オブジェクト毎に1つ作成されます。 040 * 041 * @og.rev 7.4.2.0 (2021/04/30) 新規作成 042 * @og.group データ表示 043 * 044 * @version 7.4 045 * @author Kazuhiko Hasegawa 046 * @since JDK11.0, 047 */ 048public class Renderer_IMAGE extends AbstractRenderer { 049 /** このプログラムのVERSION文字列を設定します。 {@value} */ 050 private static final String VERSION = "7.4.2.0 (2021/04/30)" ; 051 052 private static final String DIV_ST = "<div class=\"Renderer_IMAGE\">"; 053 private static final String DIV_ED = "</div>"; 054 055 private String name; 056 private String param; 057 058 /** 059 * デフォルトコンストラクター。 060 * このコンストラクターで、基本オブジェクトを作成します。 061 * 062 */ 063 public Renderer_IMAGE() { super(); } // これも、自動的に呼ばれるが、空のメソッドを作成すると警告されるので、明示的にしておきます。 064 065 /** 066 * DBColumnオブジェクトを指定したprivateコンストラクター。 067 * 068 * @og.rev 7.4.2.0 (2021/04/30) 新規作成 069 * 070 * @param clm DBColumnオブジェクト 071 */ 072 private Renderer_IMAGE( final DBColumn clm ) { 073 // 6.4.1.1 (2016/01/16) PMD refactoring. It is a good practice to call super() in a constructor 074 super(); 075 076 name = clm.getName(); 077 078// param = StringUtil.nval( clm.getRendererParam(), null ); // 空文字列はあえてnullにする。 079 param = StringUtil.nvalAdd( clm.getRendererParam() , 080 clm.getRendererAttributes().get( "optionAttributes" ) ); 081 } 082 083 /** 084 * 各オブジェクトから自分のインスタンスを返します。 085 * 自分自身をキャッシュするのか、新たに作成するのかは、各サブクラスの実装に 086 * まかされます。 087 * 088 * @param clm DBColumnオブジェクト 089 * 090 * @return CellEditorオブジェクト 091 * @og.rtnNotNull 092 */ 093 public CellRenderer newInstance( final DBColumn clm ) { 094 return new Renderer_IMAGE( clm ); 095 } 096 097 /** 098 * データの表示用文字列を返します。 099 * 100 * @og.rev 7.4.2.0 (2021/04/30) 新規作成 101 * 102 * @param value 入力値 103 * 104 * @return データの表示用文字列 105 * @og.rtnNotNull 106 */ 107 @Override 108 public String getValue( final String value ) { 109 return makeImae( name, value ); 110 } 111 112 /** 113 * データの表示用文字列を返します。 114 * 115 * @og.rev 7.4.2.0 (2021/04/30) 新規作成 116 * 117 * @param row 行番号 118 * @param value 入力値 119 * 120 * @return データ表示用の文字列 121 * @og.rtnNotNull 122 */ 123 @Override 124 public String getValue( final int row,final String value ) { 125 final String newName = name + HybsSystem.JOINT_STRING + row; 126 return makeImae( newName, value ); 127 } 128 129 /** 130 * データ出力用の文字列を作成します。 131 * ファイル等に出力する形式を想定しますので、HTMLタグを含まない 132 * データを返します。 133 * 基本は、#getValue( String ) をそのまま返します。 134 * 135 * @og.rev 7.4.2.0 (2021/04/30) 新規作成 136 * 137 * @param value 入力値 138 * 139 * @return データ出力用の文字列 140 * @og.rtnNotNull 141 * @see #getValue( String ) 142 */ 143 @Override 144 public String getWriteValue( final String value ) { 145 return value == null ? "" : value; 146 } 147 148 /** 149 * データの表示用文字列を返します。 150 * 151 * @og.rev 7.4.2.0 (2021/04/30) 新規作成 152 * 153 * @param name カラム名 154 * @param value 入力値 表示するファイルのアドレス 155 * 156 * @return データ表示用の文字列 157 * @og.rtnNotNull 158 */ 159 private String makeImae( final String name,final String value ) { 160 return DIV_ST 161 + new TagBuffer( "img" ) 162 .add( "name" , name ) 163 .add( "src" , value ) 164 .add( "alt" , value ) 165 .addOptions( param ) // タグの属性として追加。nullの場合は、何もしない。 166 .makeTag() 167 + DIV_ED; 168 } 169}