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.HybsSystemException; 019import org.opengion.fukurou.util.XHTMLTag; 020import org.opengion.fukurou.util.ToString; // 6.1.1.0 (2015/01/17) 021import org.opengion.fukurou.util.ArraySet; // 6.4.3.4 (2016/03/11) 022 023import java.util.Set; // 6.4.3.4 (2016/03/11) 024 025/** 026 * ボタンを作成するHTML拡張タグです。 027 * 028 * ボタンごとに必要な画面を選び出して制御を転送することができます。 029 * BODY 部分にラベルや強調文字などのタグを記述すれば、そのままボタンとして表示されます。 030 * [ヒント] 031 * buttonタグとinputタグが生成するボタンは、機能的には同等ですが、buttonタグの方が 032 * レタリング能力があり、内容を持つことができます。 033 * 例えば、画像を内容に持つbutton機能は、type属性がimageのinputタグと 034 * そっくり同じですが、buttonタグは内容を持つことができます。 035 * 036 * @og.formSample 037 * ●形式:<og:button type="…" name="…" value="…" lbl="…" /> 038 * ●body:あり(EVAL_BODY_BUFFERED:BODYを評価し、{@XXXX} を解析します) 039 * 040 * ●Tag定義: 041 * <og:button 042 * type ○【HTML】ボタンのタイプ[submit/reset/button]を指定します(必須)。 043 * name 【HTML】ボタンの名称を指定します 044 * value 【HTML】ボタンの値を指定します 045 * caseKey 【TAG】このタグ自体を利用するかどうかの条件キーを指定します(初期値:null) 046 * caseVal 【TAG】このタグ自体を利用するかどうかの条件値を指定します(初期値:null) 047 * caseNN 【TAG】指定の値が、null/ゼロ文字列 でない場合(Not Null=NN)は、このタグは使用されます(初期値:判定しない) 048 * caseNull 【TAG】指定の値が、null/ゼロ文字列 の場合は、このタグは使用されます(初期値:判定しない) 049 * caseIf 【TAG】指定の値が、true/TRUE文字列の場合は、このタグは使用されます(初期値:判定しない) 050 * lbl 【TAG】ラベルリソースのラベルIDを指定します 051 * id 【HTML】要素に対して固有の名前(id)をつける場合に設定します 052 * lang 【HTML】要素の内容と他の属性値の言語(lang,xml:lang)を指定します 053 * dir 【HTML】文字表記の方向(dir)を指定します 054 * title 【HTML】要素に対する補足的情報(title)を設定します 055 * style 【HTML】この要素に対して適用させるスタイルシート(style)を設定します 056 * disabled 【TAG】その部品に対して、選択や変更が出来ないように(disabled)指定します(サーバーに送信されない) 057 * tabindex 【HTML】タブの移動順(tabindex)を指定します(0 ~ 32767) 058 * accesskey 【HTML】アクセスキー(alt+キーで直接指定)を割り当てます 059 * clazz 【HTML】要素に対して class 属性を設定します 060 * language 【TAG】タグ内部で使用する言語コード[ja/en/zh/…]を指定します 061 * onClick 【HTML】JavaScriptのイベント onClick を設定します(例:onClick="renew('query.jsp','QUERY');") 062 * onBlur 【HTML】JavaScriptのイベント onBlur を設定します(例:onBlur="this.value=value.toUpperCase();") 063 * onFocus 【HTML】JavaScriptのイベント onFocus を設定します 064 * ondblClick 【HTML】JavaScriptのイベント ondblClick を設定します 065 * onMouseDown 【HTML】JavaScriptのイベント onMouseDown を設定します 066 * onMouseUp 【HTML】JavaScriptのイベント onMouseUp を設定します 067 * onMouseMove 【HTML】JavaScriptのイベント onMouseMove を設定します 068 * onMouseOut 【HTML】JavaScriptのイベント onMouseOut を設定します 069 * onMouseOver 【HTML】JavaScriptのイベント onMouseOver を設定します 070 * autofocus 【HTML5】指定した入力欄にカーソルが当たって自動的にフォーカスされます。 071 * roles 【TAG】ロールをセットします 072 * debug 【TAG】デバッグ情報を出力するかどうか[true/false]を指定します(初期値:false) 073 * > ... Body ... 074 * </og:button> 075 * 076 * ●使用例 077 * <og:button type="submit" name="test" value="1" lbl="test" /> LabelResource プロパティのラベル使用したいとききはlbl属性に、LabelResourceを使います。 078 * <og:button type="submit" name="test" value="1" msg="MSG0103" /> MessageResource プロパティのラベル使用したいときはmsg属性を使います。 079 * 080 * @og.group 画面部品 081 * 082 * @version 4.0 083 * @author Kazuhiko Hasegawa 084 * @since JDK5.0, 085 */ 086public class ButtonTag extends HTMLTagSupport { 087 /** このプログラムのVERSION文字列を設定します。 {@value} */ 088 private static final String VERSION = "6.4.3.4 (2016/03/11)" ; 089 private static final long serialVersionUID = 643420160311L ; 090 091 // 6.3.4.0 (2015/08/01) String から String配列 に置き換え 092 // 6.4.3.4 (2016/03/11) String配列 から、Setに置き換えます。 093 private static final Set<String> TYPE_SET = new ArraySet<>( "submit" , "reset" , "button" ); 094 095 /** 096 * デフォルトコンストラクター 097 * 098 * @og.rev 6.4.2.0 (2016/01/29) PMD refactoring. Each class should declare at least one constructor. 099 */ 100 public ButtonTag() { super(); } // これも、自動的に呼ばれるが、空のメソッドを作成すると警告されるので、明示的にしておきます。 101 102 /** 103 * Taglibの開始タグが見つかったときに処理する doStartTag() を オーバーライドします。 104 * 105 * @og.rev 3.1.1.2 (2003/04/04) Tomcat4.1 対応。ボディが存在する場合のみボディが呼ばれる対応。 106 * @og.rev 5.2.2.0 (2010/11/01) caseKey 、caseVal 属性対応 107 * 108 * @return 後続処理の指示( EVAL_BODY_BUFFERED ) 109 */ 110 @Override 111 public int doStartTag() { 112 // 5.2.2.0 (2010/11/01) caseKey 、caseVal 属性対応 113 if( useTag() ) { 114 set( "body",getLongLabel() ); 115 return EVAL_BODY_BUFFERED ; // Body を評価する。( extends BodyTagSupport 時) 116 } 117 return SKIP_BODY ; // Body を評価しない 118 } 119 120 /** 121 * Taglibのタグ本体を処理する doAfterBody() を オーバーライドします。 122 * 123 * @og.rev 3.1.1.0 (2003/03/28) ボディの内容を取得する処理を、CommonTagSupport で行う。 124 * @og.rev 3.1.1.2 (2003/04/04) Tomcat4.1 対応。ボディが存在する場合のみボディが呼ばれる対応。 125 * 126 * @return 後続処理の指示(SKIP_BODY) 127 */ 128 @Override 129 public int doAfterBody() { 130 final String label = getBodyString(); 131 132 if( label != null && label.length() > 0 ) { 133 set( "body",label ); 134 } 135 136 return SKIP_BODY ; 137 } 138 139 /** 140 * ボタンを作成します。 141 * 142 * <button type="submit" name="名前" value="値"> 143 * 144 * @return ボタンタグ文字列 145 * @og.rtnNotNull 146 */ 147 @Override 148 protected String makeTag() { 149 return XHTMLTag.button( getAttributes() ); 150 } 151 152 /** 153 * 【HTML】ボタンのタイプ[submit/reset/button]を指定します。 154 * 155 * @og.tag 156 * 157 * submit:提出ボタンを作成します。 158 * reset:リセットボタンを作成します。 159 * button:押しボタンを作成します。 160 * 161 * @og.rev 6.3.4.0 (2015/08/01) Arrays.toString から String.join に置き換え。 162 * @og.rev 6.4.3.4 (2016/03/11) String配列 から、Setに置き換えます。 163 * 164 * @param type ボタンのタイプ [submit/reset/button] 165 */ 166 public void setType( final String type ) { 167 final String tp = getRequestParameter( type ); 168 if( check( tp , TYPE_SET ) ) { 169 set( "type",tp ); 170 } 171 else { 172 final String errMsg = "type は、下記の範囲より指定してください。type=[" 173 + tp + "] in [" + String.join( ", " , TYPE_SET ) + "]"; 174 throw new HybsSystemException( errMsg ); 175 } 176 } 177 178 /** 179 * 【HTML】ボタンの名称を指定します。 180 * 181 * @og.tag 182 * @param name ボタンの名称 183 */ 184 public void setName( final String name ) { 185 set( "name",getRequestParameter( name ) ); 186 } 187 188 /** 189 * 【HTML】ボタンの値を指定します。 190 * 191 * @og.tag 192 * @param value ボタンの値 193 */ 194 public void setValue( final String value ) { 195 set( "value",getRequestParameter( value ) ); 196 } 197 198 /** 199 * このオブジェクトの文字列表現を返します。 200 * 基本的にデバッグ目的に使用します。 201 * 202 * @return このクラスの文字列表現 203 * @og.rtnNotNull 204 */ 205 @Override 206 public String toString() { 207 return ToString.title( this.getClass().getName() ) 208 .println( "VERSION" ,VERSION ) 209 .println( "Other..." ,getAttributes().getAttribute() ) 210 .fixForm().toString() ; 211 212 } 213}