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' frameborder='0' などです。
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 = "7.4.2.0 (2021/04/30)" ;
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         *
069         * @param       clm     DBColumnオブジェクト
070         */
071        private Renderer_IFRAME( final DBColumn clm ) {
072                // 6.4.1.1 (2016/01/16) PMD refactoring. It is a good practice to call super() in a constructor
073                super();
074
075                name  = clm.getName();
076//              param = StringUtil.nval( clm.getRendererParam(), null );        // 空文字列はあえてnullにする。
077                param = StringUtil.nvalAdd( clm.getRendererParam() ,
078                                                                        clm.getRendererAttributes().get( "optionAttributes" ) );
079        }
080
081        /**
082         * 各オブジェクトから自分のインスタンスを返します。
083         * 自分自身をキャッシュするのか、新たに作成するのかは、各サブクラスの実装に
084         * まかされます。
085         *
086         * @param       clm     DBColumnオブジェクト
087         *
088         * @return      CellEditorオブジェクト
089         * @og.rtnNotNull
090         */
091        public CellRenderer newInstance( final DBColumn clm ) {
092                return new Renderer_IFRAME( clm );
093        }
094
095        /**
096         * データの表示用文字列を返します。
097         *
098         * @og.rev 7.4.2.0 (2021/04/30) 新規作成
099         *
100         * @param   value 入力値
101         *
102         * @return  データの表示用文字列
103         * @og.rtnNotNull
104         */
105        @Override
106        public String getValue( final String value ) {
107                return makeIframe( name, value );
108        }
109
110        /**
111         * データの表示用文字列を返します。
112         *
113         * @og.rev 7.4.2.0 (2021/04/30) 新規作成
114         *
115         * @param   row   行番号
116         * @param   value 入力値
117         *
118         * @return  データ表示用の文字列
119         * @og.rtnNotNull
120         */
121        @Override
122        public String getValue( final int row,final String value ) {
123                final String newName = name + HybsSystem.JOINT_STRING + row;
124                return makeIframe( newName, value );
125        }
126
127        /**
128         * データ出力用の文字列を作成します。
129         * ファイル等に出力する形式を想定しますので、HTMLタグを含まない
130         * データを返します。
131         * 基本は、#getValue( String ) をそのまま返します。
132         *
133         * @og.rev 7.4.2.0 (2021/04/30) 新規作成
134         *
135         * @param   value 入力値
136         *
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         *
154         * @return  データ表示用の文字列
155         * @og.rtnNotNull
156         */
157        private String makeIframe( final String name,final String value ) {
158                return DIV_ST
159                        +       new TagBuffer( "iframe" )
160                                        .add( "name"    , name  )
161                                        .add( "id"              , name  )
162                                        .add( "src"             , value )
163                                        .addOptions( param              )               // タグの属性として追加。nullの場合は、何もしない。
164                                        .addBody( value )                               // iframeが機能しない場合に表示される。
165                                        .makeTag()
166                        +       DIV_ED;
167        }
168}