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 */ 016 package org.opengion.hayabusa.taglib; 017 018 import static org.opengion.fukurou.util.StringUtil.nval ; 019 020 /** 021 * switch タグは、指定された条件を?case タグに伝えます? 022 * 023 * ??は、{@XXXX} 変数が使用できます? 024 * これは、ServletRequest から、XXXX をキーに値を取り??こ?変数に 025 * 割り当てます?つまり?こ?XXXXをキーにリクエストすれ?? 026 * こ?変数に値をセ?することができます? 027 * 028 * @og.formSample 029 * ●形式?lt;og:switch key="???" /> 030 * <og:case match="A" /> ??? </og:case> 031 * <og:case match="B" /> ??? </og:case> 032 * <og:case match="C" /> ??? </og:case> 033 * <og:case isDefault="true" /> ??? </og:case> 034 * </og:switch> 035 * ●body?あ?EVAL_BODY_INCLUDE:BODYをインクルードし、{@XXXX} は解析しません) 036 * 037 * ●Tag定義?? 038 * <og:switch 039 * key ○?TAG】switch のマッチ判定用のキーを設定します?(??) 040 * debug 【TAG】デバッグ??を?力するかど?[true/false]を指定しま?初期値:false) 041 * > ... Body ... 042 * </og:switch> 043 * 044 * ●使用? 045 * <og:switch key="{@PARAM}" /> 046 * <og:case match="A" /> 処? </og:case> 047 * <og:case match="B" /> 処? </og:case> 048 * <og:case match="C" /> 処? </og:case> 049 * <og:case isDefault="true" /> 処? </og:case> 050 * </og:switch> 051 * 052 * ・switch の key に対して、case の match に?された値が?マッ?switch_key.match( case_match )) 053 * した場合に、case の BODY 部?処?れます? 054 * マッチしなければ、BODY部は、スキ??されます? 055 * ・isDefault="true" の場合?、どれと?マッチしなかった?合に、実行されます? 056 * ・Javaの switch-case ??、最初に処?れた case 以降を処?ます?通常は、break を?れて 057 * 後続??実行されな??して?す? 058 * こ?、switch-case タグは、caseタグの isBreak 属?で制御します?初期値?isBreak="true" に? 059 * なって?ため??常は、どれかの case が実行された段階で、switchの処??、終?れます? 060 * isBreak="false" にすると、switchから抜けずに、継続して case との match を実行します? 061 * こ?場合?Java等と異なる?は、直後?case?実行されるのではなく?あくまで match 作業? 062 * 継続されると?ことです?つまり??の case で処?行いたい場合?、isBreak="false" に 063 * すると同時に、match 条件もそれぞれで、??するように設定する?があります? 064 * 065 * <og:switch key="{@PARAM}" /> 066 * <og:case match="[1]" isBreak="false" /> 処? </og:case> 067 * <og:case match="[12]" isBreak="false" /> 処? </og:case> 068 * <og:case match="[123]" isBreak="false" /> 処? </og:case> 069 * <og:case isNull="true" /> 処? </og:case> 070 * <og:case isDefault="true" /> 処? </og:case> 071 * </og:switch> 072 * 073 * ・上記指定では、isBreak="false" が指定されて?ため、??した後も継続して判定??実施されます? 074 * ・上記例で?と、PARAM ?"1" の場合?上記3つともにマッチします? 075 * ・isNull="true" は、switch の key ?null の場合に成立します?(null とは、ゼロ??も含? 076 * 077 * @og.group 画面制御 078 * @og.rev 5.2.3.0 (2010/12/01) 新規追? 079 * 080 * @version 5.2.3.0 (2010/12/01) 081 * @author Kazuhiko Hasegawa 082 * @since JDK1.6, 083 */ 084 public class SwitchTag extends CommonTagSupport { 085 //* こ?プログラ??VERSION??を設定します? {@value} */ 086 private static final String VERSION = "5.2.3.0 (2010/12/01)" ; 087 088 private static final long serialVersionUID = 523020101201L ; 089 090 private String switchKey = null; 091 // private boolean isMatch = true; // マッチ??継続して行う場合?true 092 private boolean useMatch = true; // マッチ??継続して行う場合?true (5.3.0.0 (2010/12/01) 変数名変更) 093 094 /** 095 * Taglibの開始タグが見つかったときに処??doStartTag() ?オーバ?ライドします? 096 * 097 * @return 後続????( EVAL_BODY_INCLUDE ) 098 */ 099 @Override 100 public int doStartTag() { 101 // isMatch = true; // 初期? 102 useMatch = true; // 初期? 103 104 return( EVAL_BODY_INCLUDE ); // Body インクルー? extends TagSupport ? 105 } 106 107 /** 108 * Taglibの終?グが見つかったときに処??doEndTag() ?オーバ?ライドします? 109 * 110 * @return 後続???? 111 */ 112 @Override 113 public int doEndTag() { 114 debugPrint(); 115 116 return(EVAL_PAGE); 117 } 118 119 /** 120 * タグリブオブジェクトをリリースします? 121 * キャ?ュされて再利用される?で、フィールド?初期設定を行います? 122 * 123 */ 124 @Override 125 protected void release2() { 126 super.release2(); 127 switchKey = null; 128 // isMatch = true; 129 useMatch = true; 130 } 131 132 /** 133 * 【TAG】switch のマッチ判定用のキーを設定します? 134 * 135 * @og.tag switch のマッチ判定用のキーを設定します? 136 * 137 * @param key マッチ判定用のキー 138 * @see #getKey() 139 */ 140 public void setKey( final String key ) { 141 switchKey = nval( getRequestParameter( key ),switchKey ); 142 } 143 144 /** 145 * switch のマッチ判定用のキーを取得します? 146 * 147 * case タグで、この値を取り?して、??判定を行います? 148 * 149 * @return マッチ判定用のキー 150 * @see #setKey( String ) 151 */ 152 protected String getKey() { 153 return switchKey; 154 } 155 156 /** 157 * case タグが?ブレイクした場合に、このメソ?を呼び出します? 158 * 159 * これは?case タグ?isBreak="true" でマッチした?合?こ?メソ?? 160 * 呼び出し?isMatch フラグ?false に設定します? 161 * 他? case は、このフラグを参照して、false であれば、スルーします? 162 * 163 * @see #isMatch() 164 */ 165 protected void setBreak() { 166 // isMatch = false ; 167 useMatch= false ; 168 } 169 170 /** 171 * すでにマッチしたかど?を返します? 172 * 173 * これは?case タグ?処?継続するかど?の判定に利用します? 174 * case タグ?isBreak="true" でマッチした?合?isMatch フラグは? 175 * false が返ります?で、継続??ません? 176 * 177 * @return マッチしたかど?[true:継続判?false:スルー] 178 * @see #setBreak() 179 */ 180 protected boolean isMatch() { 181 // return isMatch ; 182 return useMatch ; 183 } 184 185 /** 186 * こ?オブジェクト???表現を返します? 187 * 基本???目?使用します? 188 * 189 * @return こ?クラスの??表現 190 */ 191 @Override 192 public String toString() { 193 return org.opengion.fukurou.util.ToString.title( this.getClass().getName() ) 194 .println( "VERSION" ,VERSION ) 195 .println( "switchKey" ,switchKey ) 196 .println( "Other..." ,getAttributes().getAttribute() ) 197 .fixForm().toString() ; 198 } 199 }