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