OSDN Git Service

Ver8.5.2.0
[opengion/opengionV8.git] / uap / webapps / gf / src / org / opengion / plugin / column / Renderer_URLCALL.java
1 /*
2  * Copyright (c) 2009 The openGion Project.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific language
14  * governing permissions and limitations under the License.
15  */
16 package org.opengion.plugin.column;
17
18 // import org.opengion.hayabusa.common.HybsSystem;                                                              // 8.0.0.0 (2021/07/31) Delete
19 import org.opengion.hayabusa.db.AbstractRenderer;
20 import org.opengion.hayabusa.db.CellRenderer;
21 import org.opengion.hayabusa.db.DBColumn;
22 import org.opengion.fukurou.util.StringFormat;
23 import org.opengion.fukurou.util.StringUtil;
24 import org.opengion.fukurou.util.TagBuffer;
25
26 /**
27  * URLCALL レンデラーは、汎用ボタンにURLをクリックする機能を適用するクラスです。
28  *
29  * ボタンのラベルは、ラベルリソースから取得します。それ以外に値に設定された文字列から、
30  * 変数 $1,$2,$3,$4 を適用できます。
31  * AAA:BBB:CCC:DDD という値を、$1,$2,$3,$4 に割り当てます。
32  *
33  * <button name="CC" id="CC" type="button" onClick="window.open('URL','CC_FRM').close();" >CC</button>
34  * <iframe style="display:none;" name="CC_FRM"><!-- --></iframe>
35  *
36  * window.open で、すぐに閉じるのと、iframe を 見えなくすることで、ajax と同じような感じで実行できる。
37  *
38  * ※ 色々と試行錯誤した結果、window.open + 見えない iframe 方式で行います。
39  *
40  * 不採用案1:ajaxによる非同期通信
41  *  <button name="AA" id="AA" type="button" onClick="ajaxCall('URL');" >ラベルAA</button>
42  *  default.js に ajaxCall を用意して、非同期にURLを呼び出す。
43  *  IE11 では、localhost 等から呼び出せない(セキュリティ)を低にすれば動作する。Microsoft Edge では実行可能。
44  *  将来的には、こちらの方法になる可能性は大きい
45  *
46  * 不採用案2:location.href 遷移
47  *  <button name="BB" id="BB" type="button" onClick="location.href='URL'" >ラベルBB</button>
48  *  どうしても、URLに飛んで画面遷移してしまう。return false; を入れてもすでに遷移してしまう。
49  *
50  * @og.rev 7.4.2.0 (2021/05/14) 新規作成
51  * @og.group データ表示
52  *
53  * @version     7.4
54  * @author      Kazuhiko Hasegawa
55  * @since       JDK11,
56  */
57 public class Renderer_URLCALL extends AbstractRenderer {
58         /** このプログラムのVERSION文字列を設定します。 {@value} */
59         private static final String VERSION = "8.5.2.0 (2023/07/14)" ;
60
61 //      private static final CellRenderer DB_CELL = new Renderer_URLCALL() ;
62
63         private String          name;
64         private String          label;
65         private String          param;
66
67         /**
68          * デフォルトコンストラクター。
69          * このコンストラクターで、基本オブジェクトを作成します。
70          *
71          */
72         public Renderer_URLCALL() {
73                 super();
74         }
75
76         /**
77          * DBColumnオブジェクトを指定したprivateコンストラクター。
78          *
79          * @param       clm     DBColumnオブジェクト
80          */
81         private Renderer_URLCALL( final DBColumn clm ) {
82                 super();
83
84                 name  = clm.getName();
85                 label = clm.getLabel();
86                 param = StringUtil.nvalAdd( clm.getRendererParam() ,
87                                                                         clm.getRendererAttributes().get( "optionAttributes" ) );
88         }
89
90         /**
91          * 各オブジェクトから自分のインスタンスを返します。
92          * 自分自身をキャッシュするのか、新たに作成するのかは、各サブクラスの実装に
93          * まかされます。
94          *
95          * @param       clm     DBColumnオブジェクト
96          * @return      CellRendererオブジェクト
97          * @og.rtnNotNull
98          */
99         public CellRenderer newInstance( final DBColumn clm ) {
100                 return new Renderer_URLCALL( clm );
101         }
102
103         /**
104          * データの表示用文字列を返します。
105          *
106          * @og.rev 7.4.2.0 (2021/05/14) 新規作成
107          *
108          * @param       value   入力値
109          * @return      データの表示用文字列
110          * @og.rtnNotNull
111          */
112         @Override
113         public String getValue( final String value ) {
114                 return makeButton( name, value );
115         }
116
117         /**
118          * データ出力用の文字列を作成します。
119          * ファイル等に出力する形式を想定しますので、HTMLタグを含まない
120          * データを返します。
121          * 基本は、#getValue( String ) をそのまま返します。
122          *
123          * @og.rev 7.4.2.0 (2021/05/14) 新規作成
124          *
125          * @param       value 入力値
126          *
127          * @return      データ出力用の文字列
128          * @og.rtnNotNull
129          * @see         #getValue( String )
130          */
131         @Override
132         public String getWriteValue( final String value ) {
133                 return value == null ? "" : value;
134         }
135
136         /**
137          * データの表示用文字列を返します。
138          *
139          * @og.rev 7.4.2.0 (2021/05/14) 新規作成
140          * @og.rev 8.5.2.0 (2023/07/14) iframeのnameに "_FRM" 追加
141          *
142          * @param       name    カラム名
143          * @param       value   入力値 表示するファイルのアドレス
144          * @return      データ表示用の文字列
145          * @og.rtnNotNull
146          */
147         private String makeButton( final String name,final String value ) {
148                 final String newVal = new StringFormat( param, value, name ).format();  // $C は name に置き換える。
149
150                 final String button = new TagBuffer( "button" )
151                                         .add( "name"    , name  )
152                                         .add( "id"              , name  )
153                                         .add( "type"    , "button"      )
154                                         .add( "onClick" , "window.open('" + newVal + "','" + name + "_FRM').close();" )
155                                         .addBody( label )                                                                                       // ボタンの表示
156                                         .makeTag();
157
158                 final String iframe = new TagBuffer( "iframe" )
159 //                                      .add( "name"    , name  )
160                                         .add( "name"    , name + "_FRM" )                                                       // 8.5.2.0 (2023/07/14) Modify
161                                         .add( "style"   , "display:none;" )
162                                         .makeTag();
163
164                 return button + iframe;
165         }
166 }