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