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.fukurou.util.Attributes; 019import org.opengion.fukurou.util.ToString; // 6.1.1.0 (2015/01/17) 020import org.opengion.fukurou.util.ArraySet; // 6.4.3.4 (2016/03/11) 021import org.opengion.hayabusa.common.HybsSystem; 022import org.opengion.hayabusa.html.ViewMarker; 023import org.opengion.hayabusa.html.ViewLink_LINK; 024 025import java.util.Set; // 6.4.3.4 (2016/03/11) 026import java.util.Locale ; 027import java.io.ObjectInputStream; 028import java.io.IOException; 029 030/** 031 * HTML のaタグと同等のリンクを作成するタグで、さらに国際化対応と引数の受け渡しが可能です。 032 * 033 * DBTableModelオブジェクトを表示する、共通オブジェクトです。 034 * このオブジェクトに、 データ(DBTableModel)と、コントローラ(EntryTagForm)を与えて、 035 * 外部からコントロールすることで、各種形式で データ(DBTableModel)を表示させることが 036 * 可能です。 037 * 038 * @og.formSample 039 * ●形式:<og:viewLink command="…" > <og:link name="…" ... /> </og:viewLink > 040 * ●body:あり(EVAL_BODY_BUFFERED:BODYを評価し、{@XXXX} を解析します) 041 * 042 * ●Tag定義: 043 * <og:viewLink 044 * command ○【TAG】コマンド (NEW,RENEW,RESET,REVIEW)をセットします(必須)。 045 * viewLinkId 【TAG】(通常は使いません)requestから取得する ViewLink に対応する Attributes オブジェクトの ID 046 * caseKey 【TAG】このタグ自体を利用するかどうかの条件キーを指定します(初期値:null) 047 * caseVal 【TAG】このタグ自体を利用するかどうかの条件値を指定します(初期値:null) 048 * caseNN 【TAG】指定の値が、null/ゼロ文字列 でない場合(Not Null=NN)は、このタグは使用されます(初期値:判定しない) 049 * caseNull 【TAG】指定の値が、null/ゼロ文字列 の場合は、このタグは使用されます(初期値:判定しない) 050 * caseIf 【TAG】指定の値が、true/TRUE文字列の場合は、このタグは使用されます(初期値:判定しない) 051 * debug 【TAG】デバッグ情報を出力するかどうか[true/false]を指定します(初期値:false) 052 * > ... Body ... 053 * </og:viewLink> 054 * 055 * ●使用例 056 * QueryTagとViewTagの間にviewLinkを使います。 057 * <og:viewLink command="{@command}"> 058 * <og:link column="NOSYN" gamenId="01PATTERN1" href="query.jsp" target="QUERY" 059 * keys="NOSYN,NMSYN,CDBK" value="[NOSYN],[NMSYN],[CDBK]" /> 060 * <og:link column="NMSYN" gamenId="01PATTERN1" href="query.jsp" target="QUERY" 061 * keys="NMSYN" value="[NMSYN]" /> 062 * <og:link column="CDBK" gamenId="01PATTERN1" href="query.jsp" target="QUERY" 063 * keys="NOSYN,NMSYN" value="[NOSYN],[NMSYN]" /> 064 * </og:viewLink> 065 * 066 * @og.group 画面表示 067 * 068 * @version 4.0 069 * @author Kazuhiko Hasegawa 070 * @since JDK5.0, 071 */ 072public class ViewLinkTag extends CommonTagSupport { 073 /** このプログラムのVERSION文字列を設定します。 {@value} */ 074 private static final String VERSION = "6.7.2.0 (2017/01/16)" ; 075 private static final long serialVersionUID = 672020170116L ; 076 077 /** command 引数に渡す事の出来る コマンド 新規 {@value} */ 078 public static final String CMD_NEW = "NEW" ; 079 /** command 引数に渡す事の出来る コマンド 再検索 {@value} */ 080 public static final String CMD_RENEW = "RENEW" ; 081 /** command 引数に渡す事の出来る コマンド リセット {@value} */ 082 public static final String CMD_RESET = "RESET" ; // 3.5.4.0 (2003/11/25) 083 /** command 引数に渡す事の出来る コマンド 再表示 {@value} */ 084 public static final String CMD_REVIEW = "REVIEW" ; // 3.5.4.0 (2003/11/25) 085 086 // 6.4.3.4 (2016/03/11) String配列 から、Setに置き換えます。 087 private static final Set<String> COMMAND_SET = new ArraySet<>( CMD_NEW , CMD_RENEW ,CMD_RESET , CMD_REVIEW ); 088 089 private String viewLinkId = HybsSystem.VIEWLINK_KEY; 090 private String command ; 091 private transient ViewMarker viewMarker = new ViewLink_LINK(); 092 093 /** 094 * デフォルトコンストラクター 095 * 096 * @og.rev 6.4.2.0 (2016/01/29) PMD refactoring. Each class should declare at least one constructor. 097 */ 098 public ViewLinkTag() { super(); } // これも、自動的に呼ばれるが、空のメソッドを作成すると警告されるので、明示的にしておきます。 099 100 /** 101 * Taglibの開始タグが見つかったときに処理する doStartTag() を オーバーライドします。 102 * 103 * @og.rev 5.1.9.0 (2010/08/01) 戻り値を、EVAL_BODY_INCLUDE → EVAL_BODY_BUFFERED に変更 104 * @og.rev 6.3.4.0 (2015/08/01) caseKey,caseVal,caseNN,caseNull,caseIf 属性対応 105 * @og.rev 6.4.3.4 (2016/03/11) String配列 から、Setに置き換えます。 106 * 107 * @return 後続処理の指示 108 */ 109 @Override 110 public int doStartTag() { 111 // 6.4.1.1 (2016/01/16) PMD refactoring. A method should have only one exit point, and that should be the last statement in the method 112 return useTag() && check( command, COMMAND_SET ) 113 ? EVAL_BODY_BUFFERED 114 : SKIP_BODY ; 115 116 } 117 118 /** 119 * Taglibの終了タグが見つかったときに処理する doEndTag() を オーバーライドします。 120 * 121 * @og.rev 3.1.1.2 (2003/04/04) Tomcat4.1 対応。release2() を doEndTag()で呼ぶ。 122 * @og.rev 6.3.4.0 (2015/08/01) caseKey,caseVal,caseNN,caseNull,caseIf 属性対応 123 * @og.rev 6.4.3.4 (2016/03/11) String配列 から、Setに置き換えます。 124 * @og.rev 6.7.2.0 (2017/01/16) ColumnMarkerTagなどが、caseKey,caseVal等で未使用のときの対応。 125 * 126 * @return 後続処理の指示 127 */ 128 @Override 129 public int doEndTag() { 130 debugPrint(); // 4.0.0 (2005/02/28) 131 if( useTag() && check( command, COMMAND_SET ) && viewMarker.isUsable() ) { // 6.7.2.0 (2017/01/16) 132 setRequestAttribute( viewLinkId,viewMarker ); 133 } 134 135 return EVAL_PAGE ; 136 } 137 138 /** 139 * タグリブオブジェクトをリリースします。 140 * キャッシュされて再利用されるので、フィールドの初期設定を行います。 141 * 142 * @og.rev 2.0.0.4 (2002/09/27) カスタムタグの release() メソッドを、追加 143 * @og.rev 3.1.1.2 (2003/04/04) Tomcat4.1 対応。release2() を doEndTag()で呼ぶ。 144 * 145 */ 146 @Override 147 protected void release2() { 148 super.release2(); 149 viewLinkId = HybsSystem.VIEWLINK_KEY; 150 command = null; 151 viewMarker = new ViewLink_LINK(); 152 } 153 154 /** 155 * 内部タグの LinkTag より、個々のカラムの値を書き換える 為の 156 * リンク文字列を受け取る。 157 * 158 * 複数の値を受け取って、後ほど、すべてのカラムに対して処理を行います。 159 * 160 * @og.rev 3.1.2.0 (2003/04/07) taglib パッケージ内部で使用している箇所を protected 化する。 161 * @og.rev 4.0.0.0 (2005/08/31) 同一カラムの複数登録を許可します。 162 * 163 * @param attri リンクアトリビュート 164 */ 165 protected void addAttribute( final Attributes attri ) { 166 viewMarker.addAttribute( attri ); 167 } 168 169 /** 170 * 【TAG】コマンド (NEW,RENEW,RESET,REVIEW)をセットします。 171 * 172 * @og.tag 173 * コマンドは,HTMLから(get/post)指定されますので,CMD_xxx で設定される 174 * フィールド定数値のいづれかを、指定できます。 175 * 176 * @param cmd コマンド (public static final 宣言されている文字列) 177 * @see <a href="../../../../constant-values.html#org.opengion.hayabusa.taglib.ViewLinkTag.CMD_NEW">コマンド定数</a> 178 */ 179 public void setCommand( final String cmd ) { 180 final String cmd2 = getRequestParameter( cmd ); 181 if( cmd2 != null && cmd2.length() > 0 ) { command = cmd2.toUpperCase(Locale.JAPAN); } 182 } 183 184 /** 185 * 【TAG】(通常は使いません)requestから取得する ViewLink に対応する Attributes オブジェクトの ID。 186 * 187 * @og.tag 188 * ViewLink オブジェクトをこのキーで、登録することにより、 189 * ViewForm オブジェクトで、リンク情報を付加して表示させる。 190 * 初期値は、HybsSystem.VIEWLINK_KEY です。 191 * 192 * @og.rev 3.1.4.0 (2003/04/18) 新規追加 193 * @og.rev 3.5.6.3 (2004/07/12) {@XXXX} 変数を使用できるように変更。 194 * @og.rev 3.5.6.4 (2004/07/16) LINK_ID を付加して、他のid と混同しないようにします。 195 * 196 * @param id オブジェクトID 197 */ 198 public void setViewLinkId( final String id ) { 199 final String temp = getRequestParameter( id ) ; 200 if( temp != null && temp.length() > 0 ) { 201 viewLinkId = temp + TaglibUtil.LINK_ID; 202 } 203 } 204 205 /** 206 * シリアライズ用のカスタムシリアライズ読み込みメソッド 207 * 208 * ここでは、transient 宣言された内部変数の内、初期化が必要なフィールドのみ設定します。 209 * 210 * @og.rev 4.0.0.0 (2006/09/31) 新規追加 211 * @serialData 一部のオブジェクトは、シリアライズされません。 212 * 213 * @param strm ObjectInputStreamオブジェクト 214 * @see #release2() 215 * @throws IOException シリアライズに関する入出力エラーが発生した場合 216 * @throws ClassNotFoundException クラスを見つけることができなかった場合 217 */ 218 private void readObject( final ObjectInputStream strm ) throws IOException , ClassNotFoundException { 219 strm.defaultReadObject(); 220 viewMarker = new ViewLink_LINK(); 221 } 222 223 /** 224 * このオブジェクトの文字列表現を返します。 225 * 基本的にデバッグ目的に使用します。 226 * 227 * @return このクラスの文字列表現 228 * @og.rtnNotNull 229 */ 230 @Override 231 public String toString() { 232 return ToString.title( this.getClass().getName() ) 233 .println( "VERSION" ,VERSION ) 234 .println( "viewLinkId" ,viewLinkId ) 235 .println( "command" ,command ) 236 .println( "Other..." ,getAttributes().getAttribute() ) 237 .fixForm().toString() ; 238 } 239}