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