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