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 * Taglibの終了タグが見つかったときに処理する doEndTag() を オーバーライドします。 119 * 120 * @og.rev 3.1.1.2 (2003/04/04) Tomcat4.1 対応。release2() を doEndTag()で呼ぶ。 121 * @og.rev 6.3.4.0 (2015/08/01) caseKey,caseVal,caseNN,caseNull,caseIf 属性対応 122 * @og.rev 6.4.3.4 (2016/03/11) String配列 から、Setに置き換えます。 123 * @og.rev 6.7.2.0 (2017/01/16) ColumnMarkerTagなどが、caseKey,caseVal等で未使用のときの対応。 124 * 125 * @return 後続処理の指示 126 */ 127 @Override 128 public int doEndTag() { 129 debugPrint(); // 4.0.0 (2005/02/28) 130 if( useTag() && check( command, COMMAND_SET ) && viewMarker.isUsable() ) { // 6.7.2.0 (2017/01/16) 131 setRequestAttribute( viewLinkId,viewMarker ); 132 } 133 134 return EVAL_PAGE ; 135 } 136 137 /** 138 * タグリブオブジェクトをリリースします。 139 * キャッシュされて再利用されるので、フィールドの初期設定を行います。 140 * 141 * @og.rev 2.0.0.4 (2002/09/27) カスタムタグの release() メソッドを、追加 142 * @og.rev 3.1.1.2 (2003/04/04) Tomcat4.1 対応。release2() を doEndTag()で呼ぶ。 143 * 144 */ 145 @Override 146 protected void release2() { 147 super.release2(); 148 viewLinkId = HybsSystem.VIEWLINK_KEY; 149 command = null; 150 viewMarker = new ViewLink_LINK(); 151 } 152 153 /** 154 * 内部タグの LinkTag より、個々のカラムの値を書き換える 為の 155 * リンク文字列を受け取る。 156 * 157 * 複数の値を受け取って、後ほど、すべてのカラムに対して処理を行います。 158 * 159 * @og.rev 3.1.2.0 (2003/04/07) taglib パッケージ内部で使用している箇所を protected 化する。 160 * @og.rev 4.0.0.0 (2005/08/31) 同一カラムの複数登録を許可します。 161 * 162 * @param attri リンクアトリビュート 163 */ 164 protected void addAttribute( final Attributes attri ) { 165 viewMarker.addAttribute( attri ); 166 } 167 168 /** 169 * 【TAG】コマンド (NEW,RENEW,RESET,REVIEW)をセットします。 170 * 171 * @og.tag 172 * コマンドは、HTMLから(get/post)指定されますので、CMD_xxx で設定される 173 * フィールド定数値のいづれかを、指定できます。 174 * 175 * @param cmd コマンド (public static final 宣言されている文字列) 176 * @see <a href="../../../../constant-values.html#org.opengion.hayabusa.taglib.ViewLinkTag.CMD_NEW">コマンド定数</a> 177 */ 178 public void setCommand( final String cmd ) { 179 final String cmd2 = getRequestParameter( cmd ); 180 if( cmd2 != null && cmd2.length() > 0 ) { command = cmd2.toUpperCase(Locale.JAPAN); } 181 } 182 183 /** 184 * 【TAG】(通常は使いません)requestから取得する ViewLink に対応する Attributes オブジェクトの ID。 185 * 186 * @og.tag 187 * ViewLink オブジェクトをこのキーで、登録することにより、 188 * ViewForm オブジェクトで、リンク情報を付加して表示させる。 189 * 初期値は、HybsSystem.VIEWLINK_KEY です。 190 * 191 * @og.rev 3.1.4.0 (2003/04/18) 新規追加 192 * @og.rev 3.5.6.3 (2004/07/12) {@XXXX} 変数を使用できるように変更。 193 * @og.rev 3.5.6.4 (2004/07/16) LINK_ID を付加して、他のid と混同しないようにします。 194 * 195 * @param id オブジェクトID 196 */ 197 public void setViewLinkId( final String id ) { 198 final String temp = getRequestParameter( id ) ; 199 if( temp != null && temp.length() > 0 ) { 200 viewLinkId = temp + TaglibUtil.LINK_ID; 201 } 202 } 203 204 /** 205 * シリアライズ用のカスタムシリアライズ読み込みメソッド 206 * 207 * ここでは、transient 宣言された内部変数の内、初期化が必要なフィールドのみ設定します。 208 * 209 * @og.rev 4.0.0.0 (2006/09/31) 新規追加 210 * @serialData 一部のオブジェクトは、シリアライズされません。 211 * 212 * @param strm ObjectInputStreamオブジェクト 213 * @see #release2() 214 * @throws IOException シリアライズに関する入出力エラーが発生した場合 215 * @throws ClassNotFoundException クラスを見つけることができなかった場合 216 */ 217 private void readObject( final ObjectInputStream strm ) throws IOException , ClassNotFoundException { 218 strm.defaultReadObject(); 219 viewMarker = new ViewLink_LINK(); 220 } 221 222 /** 223 * このオブジェクトの文字列表現を返します。 224 * 基本的にデバッグ目的に使用します。 225 * 226 * @return このクラスの文字列表現 227 * @og.rtnNotNull 228 */ 229 @Override 230 public String toString() { 231 return ToString.title( this.getClass().getName() ) 232 .println( "VERSION" ,VERSION ) 233 .println( "viewLinkId" ,viewLinkId ) 234 .println( "command" ,command ) 235 .println( "Other..." ,getAttributes().getAttribute() ) 236 .fixForm().toString() ; 237 } 238}