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.hayabusa.taglib; 017 018import org.opengion.hayabusa.common.HybsSystem; 019import org.opengion.fukurou.system.OgBuilder ; // 6.4.4.1 (2016/03/18) 020import org.opengion.fukurou.util.ToString; // 6.1.1.0 (2015/01/17) 021import org.opengion.fukurou.util.StringUtil ; // 6.2.2.0 (2015/03/27) 022 023import static org.opengion.fukurou.util.StringUtil.nval; 024 025import java.util.concurrent.atomic.AtomicInteger; // 5.5.2.6 (2012/05/25) findbugs対応 026 027/** 028 * Query画面の拡張検索領域を指定用のタグです。 029 * 030 * 通常は属性を何もセットせずにQuery画面の隠しメニューに利用します。 031 * queryButtonタグが存在しない場合はボタンを出力したい場所にIDをセットしたspanタグを 032 * 配置し、そのIDをこのタグのbuttonId属性で指定して下さい。 033 * タグの動きとしてはにはbody内に書いた内容をbuttonIdで指定した領域に動的に作成した 034 * ボタン(初期値はシステムパラメータの画像)でON/OFF制御可能とします。 035 * なお、body部分にはog:firldsetタグも利用可能です。 036 * 037 * @og.formSample 038 * ●形式: 039 * ・<og:hideMenu 040 * [ id = "uniqHideId" ] タグで囲われた部分に付けるID 041 * [ buttonId = "targetId" ] ボタンを出力する場所のIDを指定 042 * [ defaultNone = "[true|false]" ] 初期状態の開閉指定 043 * [ openButton = "open.png" ] 開く(+)ボタンの画像 044 * [ closeButton = "close.png" ] 閉じる(-)ボタンの画像 045 * [ lbl = "MSG0076" ] 画像のalt属性に付けるメッセージ(初期値:MSG0076) 046 * > 047 * ●body:あり(EVAL_BODY_INCLUDE:BODYをインクルードし、{@XXXX} は解析しません) 048 * 049 * ●Tag定義: 050 * <og:hideMenu 051 * id 【TAG】このタグのBODY部分にIDを指定します 052 * buttonId 【TAG】画像ボタン出力先のIDを指定します 053 * defaultNone 【TAG】初期状態の開閉指定[[true:閉じている/false:開いている]を指定します(初期値:true) 054 * openButton 【TAG】開くボタンの画像を指定します(初期値:"jsp/image/" + SystemData#HIDE_OPEN_BUTTON[={@og.value SystemData#HIDE_OPEN_BUTTON}]) 055 * closeButton 【TAG】閉じるボタンの画像を指定します(初期値:"jsp/image/" + SystemData#HIDE_CLOSE_BUTTON[={@og.value SystemData#HIDE_CLOSE_BUTTON}]) 056 * lbl 【TAG】ラベルリソースのラベルIDを指定します 057 * debug 【TAG】デバッグ情報を出力するかどうか[true/false]を指定します(初期値:false) 058 * > ... Body ... 059 * </og:hideMenu> 060 * 061 * ●使用例 062 * 例1:通常のQUERY画面での利用 063 * <og:hideMenu> 064 * <table><tr> 065 * <og:column name="CLM"/> 066 * </tr></table> 067 * </og:hideMenu> 068 * 069 * 例2:queryButtonタグが存在しない状況での利用(buttonIdの明示的な指定) 070 * <span id="hideButtonSet"> </span> 071 * <og:hideMenu> 072 * ...... 073 * </og:hideMenu> 074 * 075 * @og.rev 4.3.6.0 (2009/04/01) 新規作成 076 * @og.rev 7.3.2.3 (2021/04/09) システム定数のICON_DIRやIMAGE_DIRを使用します。 077 * @og.group 画面部品 078 * 079 * @version 4.0 080 * @author Takahashi Masakazu 081 * @since JDK5.0, 082 */ 083public class HideMenuTag extends CommonTagSupport { 084 /** このプログラムのVERSION文字列を設定します。 {@value} */ 085 private static final String VERSION = "7.3.2.3 (2021/04/09)" ; 086 private static final long serialVersionUID = 732320210409L ; 087 088 private static final AtomicInteger UNIQ_ID = new AtomicInteger(1); // 5.5.2.6 (2012/05/25) findbugs対応 // 6.4.1.1 (2016/01/16) uniqID → UNIQ_ID refactoring 089 090 private String id ; // この領域に付けるid 091 private String buttonId = "query-button-append"; // ボタンを出力する場所のid 092 private boolean defaultNone = true; // 開閉初期状態 093 094 // 7.3.2.3 (2021/04/09) システム定数のICON_DIRやIMAGE_DIRを使用します。 095 private static final String JSP_ICON = HybsSystem.sys( "JSP_ICON" ) + "/" ; 096 097// private String openButton = HybsSystem.sys( "JSP" ) + "/image/" + HybsSystem.sys( "HIDE_OPEN_BUTTON" ); // 開くボタン 098 private String openButton = JSP_ICON + HybsSystem.sys( "HIDE_OPEN_BUTTON" ); // 開くボタン 099// private String closeButton = HybsSystem.sys( "JSP" ) + "/image/" + HybsSystem.sys( "HIDE_CLOSE_BUTTON" ); // 閉じるボタン 100 private String closeButton = JSP_ICON + HybsSystem.sys( "HIDE_CLOSE_BUTTON" ); // 閉じるボタン 101 private String hideClass ; // 5.5.4.4 (2012/07/20) 102 103 /** 104 * デフォルトコンストラクター 105 * 106 * @og.rev 6.4.2.0 (2016/01/29) PMD refactoring. Each class should declare at least one constructor. 107 */ 108 public HideMenuTag() { super(); } // これも、自動的に呼ばれるが、空のメソッドを作成すると警告されるので、明示的にしておきます。 109 110 /** 111 * Taglibの開始タグが見つかったときに処理する doStartTag() を オーバーライドします。 112 * 113 * @og.rev 5.5.2.6 (2012/05/25) findbugs対応。staticフィールドへの書き込みに、AtomicInteger を利用します。 114 * @og.rev 5.5.3.2 (2012/06/08) 画像にalt属性を追加します。 115 * @og.rev 5.5.4.4 (2012/07/20) hideClassを外部から指定可能にします 116 * @og.rev 5.7.1.2 (2013/12/20) msg ⇒ msglbl 変更 117 * @og.rev 6.0.2.4 (2014/10/17) img タグに、title 属性追記 118 * @og.rev 6.2.2.0 (2015/03/27) BRと\nを相互に変換する処理を追加 119 * @og.rev 6.2.2.3 (2015/04/10) htmlフィルターに、BR→改行処理機能を追加。 120 * @og.rev 5.9.2.1 (2015/11/12) , 6.3.9.0 (2015/11/06) id修正 121 * @og.rev 6.4.4.1 (2016/03/18) StringBuilderの代わりに、OgBuilderを使用する。 122 * @og.rev 7.0.1.0 (2018/10/15) XHTML → HTML5 対応(空要素の、"/>" 止めを、">" に変更します)。 123 * 124 * @return 後続処理の指示( EVAL_BODY_INCLUDE ) 125 */ 126 @Override 127 public int doStartTag() { 128 // 6.3.9.0 (2015/11/06) Variables should start with a lowercase character(PMD) 129 // IMG を final 化するに当たり、実際に使用する直前で生成するように変更。 130 if( hideClass == null || hideClass.isEmpty() ){ // 5.5.4.4 (2012/07/20) 外部指定対応 131 hideClass = "hideMenu" + ( UNIQ_ID.getAndIncrement() ); 132 } 133 134 // 5.5.3.2 (2012/06/08) 画像にalt属性を追加します。 135 String msglbl = getMsglbl(); // 5.7.1.2 (2013/12/20) msg ⇒ msglbl 変更 136 if( msglbl == null ) { setLbl( "MSG0076" ); msglbl = getMsglbl(); } // 初期値は、MSG0076:拡張検索条件 137 138 final OgBuilder buf = new OgBuilder() 139 .append( "<div class=\"" , hideClass , "\" " ) 140 .appendIf( id != null // if 141 , "id=\"" , id , "\" " ) 142 .appendIf( defaultNone // if 143 , "style=\"display: none;\"" ) 144 .append( ">" ); 145 146 // 指定したIDにボタン画像を放り込むスクリプトを出力 147 if( buttonId != null && buttonId.length() > 0){ 148 final String IMG = " <img id=\"queryHide\" src=\"" 149 + ( defaultNone ? openButton : closeButton ) 150 + "\" alt=\"" + msglbl + "\" border=\"0px\"" 151 + " title=\"" + StringUtil.htmlFilter( msglbl,true ) + "\"" // 6.0.2.4 (2014/10/17) img タグに、title 属性追記 152// + " onClick=\"hideClass( event, this, '" + hideClass + "', '" + openButton + "', '" + closeButton + "' )\"/> " ; 153 + " onClick=\"hideClass( event, this, '" + hideClass + "', '" + openButton + "', '" + closeButton + "' )\"> " ; // 7.0.1.0 (2018/10/15) 154 155 buf.appendCR( "<script language=\"javascript\">" ) 156 .append( "$(function(){$('#" , buttonId , "').append(\"" ) 157 .append( IMG.replace( "\"", "\\\"" ) ) 158 .appendCR( "\");})" ) 159 .appendCR( "</script>"); 160 } 161 162 jspPrint( buf.toString() ); 163 return EVAL_BODY_INCLUDE ; // Body インクルード( extends TagSupport 時) 164 } 165 166 /** 167 * Taglibの終了タグが見つかったときに処理する doEndTag() を オーバーライドします。 168 * 169 * @return 後続処理の指示 170 */ 171 @Override 172 public int doEndTag() { 173 debugPrint(); 174 175 jspPrint( CR + "</div>" ); 176 177 return EVAL_PAGE ; // ページの残りを評価する。 178 } 179 180 /** 181 * タグリブオブジェクトをリリースします。 182 * キャッシュされて再利用されるので、フィールドの初期設定を行います。 183 * 184 * @og.rev 5.5.4.4 (2012/07/20) hideClass対応 185 * @og.rev 7.3.2.3 (2021/04/09) システム定数のICON_DIRやIMAGE_DIRを使用します。 186 */ 187 @Override 188 protected void release2() { 189 super.release2(); 190 id = null; 191 buttonId = "query-button-append"; 192 defaultNone = true; 193// openButton = HybsSystem.sys( "JSP" ) + "/image/" + HybsSystem.sys( "HIDE_OPEN_BUTTON" ); // 開くボタン 194 openButton = JSP_ICON + HybsSystem.sys( "HIDE_OPEN_BUTTON" ); // 開くボタン 195// closeButton = HybsSystem.sys( "JSP" ) + "/image/" + HybsSystem.sys( "HIDE_CLOSE_BUTTON" ); // 閉じるボタン 196 closeButton = JSP_ICON + HybsSystem.sys( "HIDE_CLOSE_BUTTON" ); // 閉じるボタン 197 hideClass = null; 198 } 199 200 /** 201 * 【HTML】要素に対して固有の名前(id)をつける場合に設定します。 202 * 203 * @og.tag 204 * 開閉される部分を囲っているDIVタグのBODY部分にIDを指定します。 205 * 特定のhideMenuにスタイルを指定したい場合等に利用して下さい。 206 * 207 * @param input BODY部分のID 208 */ 209 @Override 210 public void setId( final String input) { 211 id = nval( getRequestParameter( input ), id ); 212 } 213 214 /** 215 * 【TAG】画像ボタン出力先のIDを指定します。 216 * 217 * @og.tag 218 * 初期値は"query-button-append"です。 219 * queryButtonタグが存在する画面では通常指定する必要はありません。 220 * queryButtonタグが存在しない場合は、別途用意したspanタグの 221 * IDを指定する事でボタンが表示されます。 222 * 223 * @param input 出力先のID 224 * 225 */ 226 public void setButtonId( final String input) { 227 buttonId = nval( getRequestParameter( input ), buttonId ); 228 } 229 230 /** 231 * 【TAG】初期状態の開閉指定[[true:閉じている/false:開いている]を指定します(初期値:true)。 232 * 233 * @og.tag 234 * 初期状態が開いているか、閉じているかを指定します。 235 * 初期値は閉じる(true)です。 236 * 237 * @param flag 開閉指定 [true:閉じている/false:開いている] 238 * 239 */ 240 public void setDefaultNone( final String flag) { 241 defaultNone = nval( getRequestParameter( flag ), defaultNone ); 242 } 243 244 /** 245 * 【TAG】開くボタンの画像を指定します 246 * (初期値:"jsp/image/" + SystemData#HIDE_OPEN_BUTTON[={@og.value SystemData#HIDE_OPEN_BUTTON}])。 247 * 248 * @og.tag 249 * ボタンの画像を指定します。 250 * 絶対パスの場合は、システムの先頭から、相対パスの場合、基底は各画面のフォルダとなります。 251 * 初期値はjsp/imageフォルダ内のシステムパラメータHIDE_OPEN_BUTTONのファイルです。 252 * (/システムID/jsp/image/expand_u.png) 253 * 254 * @param name 画像ファイル名 255 */ 256 public void setOpenButton( final String name) { 257 openButton = nval( getRequestParameter( name ), openButton ); 258 } 259 260 /** 261 * 【TAG】閉じるボタンの画像を指定します 262 * (初期値:"jsp/image/" + SystemData#HIDE_CLOSE_BUTTON[={@og.value SystemData#HIDE_CLOSE_BUTTON}])。 263 * 264 * @og.tag 265 * ボタンの画像を指定します。 266 * 絶対パスの場合は、システムの先頭から、相対パスの場合、基底は各画面のフォルダとなります。 267 * 初期値はjsp/imageフォルダ内のシステムパラメータHIDE_CLOSE_BUTTONのファイルです。 268 * (/システムID/jsp/image/shrink_u.png) 269 * 270 * @param name 画像ファイル名 271 */ 272 public void setCloseButton( final String name) { 273 closeButton = nval( getRequestParameter( name ), closeButton ); 274 } 275 276 /** 277 * 【TAG】開閉するclassを指定します。 278 * 279 * @og.tag 280 * 開閉を制御するためのclass属性を外部から指定します。 281 * 指定しない場合は自動でユニークなClassがセットされます。 282 * 283 * @param name クラス 284 * 285 * @og.rev 5.5.4.4 (2012/07/20) 新規追加 286 */ 287 public void setHideClass( final String name) { 288 hideClass = nval( getRequestParameter( name ), hideClass ); 289 } 290 291 /** 292 * このオブジェクトの文字列表現を返します。 293 * 基本的にデバッグ目的に使用します。 294 * 295 * @return このクラスの文字列表現 296 * @og.rtnNotNull 297 */ 298 @Override 299 public String toString() { 300 return ToString.title( this.getClass().getName() ) 301 .println( "VERSION" ,VERSION ) 302 .println( "id" ,id ) 303 .println( "buttonId" ,buttonId ) 304 .println( "defaultNone" ,defaultNone ) 305 .println( "openButton" ,openButton ) 306 .println( "closeButton" ,closeButton ) 307 .println( "Other..." ,getAttributes().getAttribute() ) 308 .fixForm().toString() ; 309 } 310}