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.html;
017
018import org.opengion.fukurou.system.OgRuntimeException ;                 // 6.4.2.0 (2016/01/29)
019import static org.opengion.fukurou.system.HybsConst.CR ;                // 6.1.0.0 (2014/12/26)
020import org.opengion.fukurou.util.StringUtil;
021import org.opengion.fukurou.model.Formatter;
022import org.opengion.hayabusa.common.HybsSystemException;
023import org.opengion.hayabusa.db.DBTableModel;
024
025import java.util.regex.Pattern;
026import java.util.regex.Matcher;
027import java.util.stream.IntStream;                                                              // 6.4.3.4 (2016/03/11)
028
029/**
030 * [PN],[OYA] などの [] で指定されたカラムで表されたフォーマットデータに対して、
031 * DBTableModelオブジェクトを適用して 各カラムに実データを割り当てるオブジェクトです。
032 *
033 * 特に、[XXXX]に対して、[#XXXX]、[$XXXX]、[$XXXX]などの特殊記号が使用できます。
034 * 特殊記号の解釈は、HTMLFormatTextField系とHTMLFormatTable系で異なりますので
035 * ご注意ください。
036 *
037 * @og.rev 3.5.4.0 (2003/11/25) 新規追加
038 * @og.group 画面表示
039 *
040 * @version  4.0
041 * @author   Kazuhiko Hasegawa
042 * @since    JDK5.0,
043 */
044public class TableFormatter {
045
046        /** フォーマットタイプの指定の特殊なマーク {@value} */
047        public static final String HYBS_ITD_MARKER = "h_itd_marker";
048        // 4.3.2.0 (2008/09/10) </td>前のスペースを取り消す。
049        private static final Pattern PTN_KEY = Pattern.compile( "[ \t]+</td" );                 // 6.4.1.1 (2016/01/16) ptnKey → PTN_KEY refactoring
050
051        private FormatterType   formatType      ;
052        private int[]                   location        ;
053        private String[]                format          ;
054        private String                  formatTag       ;
055        private String                  rowspan         = " rowspan=\"2\"";
056        private String                  trTag           ;
057        private boolean                 noClass         ;
058        // 3.5.6.0 (2004/06/18) '!' 値のみ 追加 既存の '$' は、レンデラー
059        private char[]                  type            ;                       // '#':ラベルのみ  '$':レンデラー '!':値のみ  その他:通常
060        private String                  usableKey       ;                       // キー情報のカラム文字列
061        private int                             usableKeyNo     = -1;           // キー情報のカラム番号
062        private String                  usableList      = "1";
063
064        private String                  keyBreakClm     ;                       // 5.7.6.3 (2014/05/23) キーブレイクをチェックするカラムID
065        private int                             breakClmNo      = -1;           // 5.7.6.3 (2014/05/23) キーブレイクカラム番号
066        private String                  breakVal        ;                       // 5.7.6.3 (2014/05/23) キーブレイクをチェックする値
067
068        private String                  itdBody         = "";           // 3.5.6.0 (2004/06/18) 追加
069        private Formatter               formatter       ;
070
071        /**
072         * デフォルトコンストラクター
073         *
074         * @og.rev 6.4.2.0 (2016/01/29) PMD refactoring. Each class should declare at least one constructor.
075         */
076        public TableFormatter() { super(); }            // これも、自動的に呼ばれるが、空のメソッドを作成すると警告されるので、明示的にしておきます。
077
078        /**
079         * フォーマットをセットします。
080         * フォーマットに、&lt;table&gt;を含む場合、TextField扱いなので、フォーマット分割
081         * しません。table を含まず、tr を含む場合は、1行分のデータとして扱う為、
082         * trTag を求めます。
083         * trTag と format との間に、行ヘッダーが入ります。
084         * Tomcat6では、JSPのパース時に、tabやspaceはそのままパースされるため、&lt;/td&gt;前
085         * のスペース削除処理も行います。
086         *
087         * @og.rev 4.3.2.0 (2008/09/10) &lt;/td&gt;前のスペースを取り消します。
088         * @og.rev 5.5.0.3 (2012/03/13) &lt;tr&gt;を取らないフラグ追加
089         *
090         * @param       fmt  [カラム名] 形式のフォーマットデータ
091         * @param   flag  falseにすると先頭のtrタグを取る処理を行いません(5.5.0.3)
092         */
093        public void setFormat( final String fmt , final boolean flag ) {
094                final int tbl = fmt.indexOf( "<table" );
095                final int str = fmt.indexOf( "<tr" );
096
097                // tr を含み、かつ、tableを含まないか、含んでも tr の後ろにtableがある場合。
098                if( str >= 0 && ( tbl < 0 || str < tbl ) && flag ) { // 5.5.0.3(2012/03/13)
099                        final int end = fmt.indexOf( '>',str );
100                        formatTag = fmt.substring(end+1);
101                        trTag = fmt.substring(0,end+1) ;
102                }
103                else {
104                        formatTag = fmt;
105                        trTag     = null;
106                }
107                // 4.3.2.0 (2008/09/10) </td>前のスペースを取り消す。
108                final Matcher matcher = PTN_KEY.matcher( formatTag );
109                formatTag = matcher.replaceAll( "</td" );
110
111        }
112
113        /**
114         * フォーマットをセットします。
115         * フォーマットに、&lt;table&gt;を含む場合、TextField扱いなので、フォーマット分割
116         * しません。table を含まず、tr を含む場合は、1行分のデータとして扱う為、
117         * trTag を求めます。
118         * trTag と format との間に、行ヘッダーが入ります。
119         * Tomcat6では、JSPのパース時に、tabやspaceはそのままパースされるため、&lt;/td&gt;前
120         * のスペース削除処理も行います。
121         *
122         * @og.rev 5.5.0.3 (2012/03/13) 引数追加につき。
123         *
124         * @param       fmt  [カラム名] 形式のフォーマットデータ
125         */
126        public void setFormat( final String fmt ) {
127                setFormat( fmt , true );
128        }
129
130        /**
131         * フォーマットを取得します。
132         *
133         * @og.rev 3.5.5.8 (2004/05/20) 新規追加
134         * @og.rev 5.1.7.0 (2010/06/01) サニタイズ戻し処理("\\]\\"から"["に戻し)を追加
135         *
136         * @return      フォーマットデータ
137         */
138        public String getFormat() {
139                // 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
140                // 反転注意
141                return trTag == null ? decodeSanitizedStr( formatTag ) : decodeSanitizedStr( trTag + formatTag );
142
143        }
144
145        /**
146         * DBTableModelを利用して、フォーマットデータを初期化します。
147         *
148         * @og.rev 3.5.5.0 (2004/03/12) [KEY.カラム名] 機能追加
149         * @og.rev 3.5.5.2 (2004/04/02) [I] で、行番号を作成します。
150         * @og.rev 3.5.6.0 (2004/06/18) '!' 値のみ 追加 既存の '$' は、レンデラー
151         * @og.rev 3.6.0.0 (2004/09/17) [ROW.ID] で、行毎のチェックボックスのIDを返します。
152         * @og.rev 5.1.7.0 (2010/06/01) サニタイズ戻し処理("\\]\\"から"["に戻し)を追加
153         * @og.rev 5.7.6.3 (2014/05/23) キーブレイクをチェックする keyBreakClm 属性追加
154         * @og.rev 6.4.3.4 (2016/03/11) Formatterに新しいコンストラクターを追加する。
155         *
156         * @param       table   DBTableModelオブジェクト
157         */
158        public void makeFormat( final DBTableModel table ) {
159                formatter = new Formatter( table,formatTag );           // 6.4.3.4 (2016/03/11)
160                location = formatter.getClmNos();
161                format   = formatter.getFormat();
162
163                // 5.1.7.0 (2010/06/01) サニタイズ戻し処理("\\]\\"から"["に戻し)を追加
164                // 6.0.2.5 (2014/10/31)  null でないことがわかっている値の冗長な null チェックがあります。 
165                        for( int i=0; i<format.length; i++ ) {
166                                format[i] = decodeSanitizedStr( format[i] );
167                        }
168
169                type = formatter.getType();
170
171                // このフォーマットを使用するかどうかを指定する判定条件の初期設定です。
172                if( usableKey != null ) {
173                        usableKeyNo = table.getColumnNo( usableKey );
174                }
175
176                // 5.7.6.3 (2014/05/23) キーブレイクをチェックする keyBreakClm 属性追加
177                if( keyBreakClm != null ) {
178                        breakClmNo = table.getColumnNo( keyBreakClm );
179                        breakVal   = null;              // 初期化します。
180                }
181        }
182
183        /**
184         * テーブルフォーマットのタイプを指定します。
185         * enum FormatterType で、指定します。
186         *
187         * @og.rev 4.0.0.0 (2007/05/02) enum 定義に変更
188         *
189         * @param  ftype フォーマットのタイプ
190         */
191        public void setFormatType( final FormatterType ftype ) {
192                formatType = ftype;
193        }
194
195        /**
196         * このフォーマットのタイプを返します。
197         *
198         * このフォーマットのタイプを返します。
199         *
200         * @og.rev 4.0.0.0 (2007/05/02) enum 定義に変更
201         *
202         * @return      このフォーマットのタイプを返します。
203         */
204        public FormatterType getFormatType() {
205                return formatType;
206        }
207
208        /**
209         * テーブルの rowspan 属性をセットします。
210         * rowspan は、ヘッダー部のフォーマットの行数です。初期値は 2行 です。
211         * 設定は、"2" などの、数字部のみをセットします。
212         *
213         * @param  rowspan 属性
214         */
215        public void setRowspan( final String rowspan ) {
216                if( rowspan == null || rowspan.isEmpty() || rowspan.equals( "1" ) ) {
217                        this.rowspan = "";
218                }
219                else {
220                        this.rowspan = " rowspan=\"" + rowspan + "\"";
221                }
222        }
223
224        /**
225         * 設定された rowspan を返します。
226         * これは、フォーマットの段組の数を取り出します。
227         * 文字列としては、rowspan="2" という形で取り出します。
228         *
229         * @return フォーマット文字列
230         */
231        public String getRowspan() {
232                return rowspan;
233        }
234
235        /**
236         * ロケーション番号のサイズを返します。
237         * フォーム位置番号は、0 から getLocationSize()-1 までの数字を指定します。
238         * ロケーションサイズは、aaa[ABC]bbb[DEF]ccc[GHI]ddd となっている場合、
239         * aaa , bbb , ccc , ddd は、フォーマットで、サイズは4。
240         * ABC , DEF , GHI に対応するカラム番号がロケーションで、サイズは3。
241         * このメソッドで返すのは、ロケーション番号(3)の方です。
242         *
243         * @og.rev 6.3.9.0 (2015/11/06) コンストラクタで初期化されていないフィールドを null チェックなしで利用している(findbugs)
244         *
245         * @return  ロケーション番号のサイズ
246         */
247        public int getLocationSize() {
248                // 6.3.9.0 (2015/11/06) コンストラクタで初期化されていないフィールドを null チェックなしで利用している(findbugs)
249                if( location == null ) {
250                        final String errMsg = "#makeFormat(DBTableModel)を先に実行しておいてください。" ;
251                        throw new OgRuntimeException( errMsg );
252                }
253
254                return location.length;
255        }
256
257        /**
258         * カラムのロケーション番号を返します。
259         * 引数は、0 から、getLocationSize()-1 までの数で指定します。
260         * 指定の位置の、フォーマットのカラム名に対応するロケーション番号
261         * を返します。
262         *
263         * @og.rev 6.3.9.0 (2015/11/06) コンストラクタで初期化されていないフィールドを null チェックなしで利用している(findbugs)
264         *
265         * @param no フォーム位置番号
266         *
267         * @return ロケーション番号
268         */
269        public int getLocation( final int no ) {
270                // 6.3.9.0 (2015/11/06) コンストラクタで初期化されていないフィールドを null チェックなしで利用している(findbugs)
271                if( location == null ) {
272                        final String errMsg = "#makeFormat(DBTableModel)を先に実行しておいてください。" ;
273                        throw new OgRuntimeException( errMsg );
274                }
275
276                return location[no];
277        }
278
279        /**
280         * カラムのロケーション番号をIntStreamで返します。
281         *
282         * 指定の位置の、フォーマットのカラム名に対応するロケーション番号のIntStreamです。
283         *
284         * @og.rev 6.4.3.4 (2016/03/11) 内部のLocation配列を、IntStreamで返します。
285         *
286         * @return 内部のLocation配列を、IntStreamで返します。
287         */
288        public IntStream getLocationStream() {
289                // 6.3.9.0 (2015/11/06) コンストラクタで初期化されていないフィールドを null チェックなしで利用している(findbugs)
290                if( location == null ) {
291                        final String errMsg = "#makeFormat(DBTableModel)を先に実行しておいてください。" ;
292                        throw new OgRuntimeException( errMsg );
293                }
294
295                return IntStream.of( location );
296        }
297
298        /**
299         * 指定のロケーション番号の値をクリアします。
300         * ただし、直前のフォーマットに、td タグが存在する場合は、
301         * style="display:none;" を設定することで、td タグそのものが
302         * 無くなります。
303         * その場合、段組みなどのレイアウトを行っていると、フォーマットが
304         * 崩れますので、十分ご確認ください。
305         * また、同一 td 内に複数のカラムを指定した場合は、tdタグ内のすべての
306         * カラムが消えます。
307         * td タグが存在しない場合は、非表示というより、データを空に
308         * するだけになります。
309         *
310         * @og.rev 6.2.0.0 (2015/02/27) フォーマット系の noDisplay 対応
311         * @og.rev 6.2.0.1 (2015/03/06) 非表示のマーカーに、Formatter#NO_DISPLAY を使用する。
312         * @og.rev 6.3.9.0 (2015/11/06) コンストラクタで初期化されていないフィールドを null チェックなしで利用している(findbugs)
313         *
314         * @param no フォーム位置番号
315         */
316        protected void setNoDisplay( final int no ) {
317                // 6.3.9.0 (2015/11/06) コンストラクタで初期化されていないフィールドを null チェックなしで利用している(findbugs)
318                if( location == null || format == null ) {
319                        final String errMsg = "#makeFormat(DBTableModel)を先に実行しておいてください。" ;
320                        throw new OgRuntimeException( errMsg );
321                }
322
323                location[no] = Formatter.NO_DISPLAY ;
324
325                int tdIdx = format[no] == null ? -1 : format[no].indexOf( "<td" ) ;             // nullチェックも兼ねる
326
327                // 6.2.0.1 (2015/03/06) 非表示のマーカーの td に、style="display:none;" 追加
328                if( tdIdx >= 0 ) {
329                        int adrs = format[no].indexOf( "style=\"" );
330                        if( adrs >= 0 ) {                                       // style 属性が既に存在する場合。
331                                adrs += "style=\"".length();    // style=" の直後の位置を求める。
332                                format[no] = format[no].substring( 0,adrs )
333                                                                + "display:none;"
334                                                                + format[no].substring( adrs ) ;
335                        }
336                        else {                                                          // style 属性がないので、td の直後に入れる。
337                                tdIdx += "<td".length();                // td の直後の位置を求める。
338                                format[no] = format[no].substring( 0,tdIdx )
339                                                                + " style=\"display:none;\""
340                                                                + format[no].substring( tdIdx ) ;
341                        }
342                }
343        }
344
345        /**
346         * フォーマット文字列を返します。
347         * 引数は、0 から、getLocationSize() までの数で指定します。
348         * 指定のフォーマットが、aaa[ABC]bbb[DEF]ccc[GHI]ddd となっている場合、
349         * aaa , bbb , ccc , ddd を引数 0 , 1 , 2 , 3 で返します。
350         *
351         * @og.rev 6.3.9.0 (2015/11/06) コンストラクタで初期化されていないフィールドを null チェックなしで利用している(findbugs)
352         *
353         * @param no フォーム位置番号
354         *
355         * @return フォーマット文字列
356         */
357        public String getFormat( final int no ) {
358                // 6.3.9.0 (2015/11/06) コンストラクタで初期化されていないフィールドを null チェックなしで利用している(findbugs)
359                if( format == null ) {
360                        final String errMsg = "#makeFormat(DBTableModel)を先に実行しておいてください。" ;
361                        throw new OgRuntimeException( errMsg );
362                }
363
364                return format[no];
365        }
366
367        /**
368         * システムフォーマット文字列を返します。
369         * システムフォーマット文字列は、[KEY.カラム名] などの特殊記号で指定された
370         * カラム名の事で、location には、マイナスの値が設定されます。
371         * マイナスの値に応じて、処理を変えることが出来ます。
372         *
373         * [KEY.カラム名] : 行番号付きカラム名
374         * [I]            : 行番号
375         * [ROW.ID]       : 行毎のチェックボックスのID
376         * [ROW.JSON]     : 行毎の全データのJavaScriptオブジェクト形式
377         *
378         * @og.rev 3.5.5.0 (2004/03/12) [KEY.カラム名] 機能追加
379         * @og.rev 3.5.5.2 (2004/04/02) [I] で、行番号を作成します。
380         * @og.rev 3.6.0.0 (2004/09/17) [ROW.ID] で、行毎のチェックボックスのIDを返します。
381         * @og.rev 4.0.0.0 (2007/05/02) Formatter を使用するように変更
382         * @og.rev 6.2.0.1 (2015/03/06) 非表示のマーカーに、Formatter#NO_DISPLAY を使用する。
383         * @og.rev 6.3.9.0 (2015/11/06) コンストラクタで初期化されていないフィールドを null チェックなしで利用している(findbugs)
384         *
385         * @param       row     行番号
386         * @param       loc     位置番号
387         *
388         * @return フォーマット文字列
389         * @og.rtnNotNull
390         */
391        public String getSystemFormat( final int row,final int loc ) {
392                if( loc == Formatter.SYS_ROWNUM ) {
393                        return String.valueOf( row );
394                }
395                else if( loc == Formatter.SYS_JSON ) {
396                        // 6.3.9.0 (2015/11/06) コンストラクタで初期化されていないフィールドを null チェックなしで利用している(findbugs)
397                        if( formatter == null ) {
398                                final String errMsg = "#makeFormat(DBTableModel)を先に実行しておいてください。" ;
399                                throw new OgRuntimeException( errMsg );
400                        }
401
402                        return formatter.getJson( row );
403                }
404                else if( loc == Formatter.NO_DISPLAY ) {                // 6.2.0.1 (2015/03/06) 非表示のマーカー
405                        return "";
406                }
407
408                final String errMsg = "システムフォーマットは、下記の形式しか使用できません。[" + loc + "]" + CR
409                                + "  : [KEY.カラム名] : 行番号付きカラム名" + CR
410                                + "  : [I]            : 行番号" + CR
411                                + "  : [ROW.ID]       : 行毎のチェックボックスのID" + CR
412                                + "  : [ROW.JSON]     : 行毎の全データのJavaScriptオブジェクト形式" ;
413                throw new HybsSystemException( errMsg );
414        }
415
416        /**
417         * タイプ文字列を返します。
418         * タイプとは、[XXX] の記述で、[#XXX] は、XXXカラムのラベルを、[$XXX]は、XXXカラムの
419         * レンデラーを、[!XXX} は、値のみ取り出す指定を行います。
420         * 主に、TextField系のフォーマットとTable系では、意味合いが異なりますので、
421         * ご注意ください。
422         *
423         * @og.rev 6.3.9.0 (2015/11/06) コンストラクタで初期化されていないフィールドを null チェックなしで利用している(findbugs)
424         *
425         * @param no フォーム位置番号
426         *
427         * @return タイプ文字列 '#':ラベルのみ  '$':レンデラー '!':値のみ  その他:通常
428         */
429        public char getType( final int no ) {
430                // 6.3.9.0 (2015/11/06) コンストラクタで初期化されていないフィールドを null チェックなしで利用している(findbugs)
431                if( type == null ) {
432                        final String errMsg = "#makeFormat(DBTableModel)を先に実行しておいてください。" ;
433                        throw new OgRuntimeException( errMsg );
434                }
435
436                return type[no];
437        }
438
439        /**
440         * 設定された フォーマットの trタグを返します。
441         * これは、trタグにclass属性他の設定がされていた場合に、変換後の
442         * 文字列にも反映させる為に必要です。
443         *
444         * @og.rev 5.1.7.0 (2010/06/01) サニタイズ戻し処理("\\]\\"から"["に戻し)を追加
445         *
446         * @return フォーマットの trタグ
447         * @og.rtnNotNull
448         */
449        public String getTrTag() {
450                // 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
451                return trTag == null ? "" : decodeSanitizedStr( trTag ) ;
452
453        }
454
455        /**
456         * カラムのクラス名(X,S9 など)のセットを行うかどうか指定します。
457         *
458         * "true" で、クラス属性を設定しません。これは、CSSファイルに書かれている属性を
459         * 使用しないことを意味します。
460         * 初期値は、"false" です。
461         *
462         * @param       flag クラス名使用の有無(true:使用しない/false:使用する。)
463         */
464        public void setNoClass( final String flag ) {
465                noClass = StringUtil.nval( flag,noClass );
466        }
467
468        /**
469         * カラムのクラス名(X,S9 など)のセットを行うかどうか取得します。
470         *
471         * "true" で、クラス属性を設定しません。これは、CSSファイルに書かれている属性を
472         * 使用しないことを意味します。
473         * 初期値は、"false" です。
474         *
475         * @return      クラス名使用の有無(true:使用しない/false:使用する。)
476         */
477        public boolean isNoClass() {
478                return noClass;
479        }
480
481        /**
482         * フォーマットの使用可否を判断するキーとなるカラム名を指定します。
483         *
484         * キーが、usableList に含まれる場合は、このフォームを使用できます。
485         * キー(カラム名)が指定されない場合は、常に使用されます。
486         * ※ 現時点では、BODYタイプのみ使用しています。
487         *
488         * @param  key フォーマットの使用可否を判断するカラム名
489         */
490        public void setUsableKey( final String key ) {
491                usableKey = key;
492        }
493
494        /**
495         *  フォーマットの使用可否を判断する文字列リストを指定します。
496         *
497         * キーが、この文字列リスト中に存在する場合は、このフォームを使用できます。
498         * この文字列リストは、固定な文字列です。{&#064;XXXX}は使用できますが、[XXXX]は
499         * 使用できません。
500         * 初期値は、"1" です。
501         * ※ 現時点では、BODYタイプのみ使用しています。
502         *
503         * @param  list フォーマットの使用可否を判断する文字列リスト
504         * @see TableFormatter#isUse( int,DBTableModel )
505         */
506        public void setUsableList( final String list ) {
507                if( list != null ) {
508                        usableList = list;
509                }
510        }
511
512        /**
513         * ここで指定したカラムの値が、キーブレイクした場合、このタグを使用します。
514         *
515         * キーブレイクで 使用可否を指定する為の機能です。
516         * この設定値は、usableKey,usableList とは、独立しているため、それぞれで
517         * 有効になれば、使用されると判断されます。
518         * キーブレイク判定では、最初の1件目は、必ず使用されると判断されます。
519         *
520         * @og.rev 5.7.6.3 (2014/05/23) 新規追加
521         *
522         * @param  kclm  キーブレイクをチェックするカラムID
523         */
524        public void setKeyBreakClm( final String kclm ) {
525                keyBreakClm = kclm;
526        }
527
528        /**
529         * このフォーマットを使用するかどうかの問い合わせを返します。
530         *
531         * "true" で、使用します。setUsableKey( String ) で、指定された
532         * カラム名の値が、setUsableList( String ) で指定された文字列に含まれていれば、
533         * 使用します。カラム名がセットされない場合は、デフォルト値("true")が使用されます。
534         * ※ 現時点では、BODYタイプのみ使用しています。
535         * カラムのデータに、不正なスペースが入る場合を想定して、trim() しています。
536         * よって、usableList の値にスペースは使用できません。
537         *
538         * 5.7.6.3 (2014/05/23) 以降は、keyBreakClm によるキーブレイクチェックも追加されました。
539         * 従来の usableKey,usableList とは、独立しているため、それぞれで有効になれば、
540         * 使用されると判断されます。
541         *
542         * @og.rev 3.5.6.2 (2004/07/05) 判定評価用カラムの値を trim() します。
543         * @og.rev 5.7.6.3 (2014/05/23) キーブレイクをチェックする keyBreakClm 属性追加
544         *
545         * @param  row 行番号
546         * @param       table   DBTableModelオブジェクト
547         *
548         * @return      このフォームを使用するかどうか(true:使用する/false:使用しない)
549         * @see TableFormatter#setUsableKey( String )
550         * @see TableFormatter#setUsableList( String )
551         */
552        public boolean isUse( final int row, final DBTableModel table ) {
553
554                // どちらも設定されていなければ、使用される(=true)
555                if( usableKeyNo < 0 && breakClmNo < 0 ) { return true; }
556
557                // 以下、どちらかは設定されているため、true の時点で、使用される(=true)を返す。
558                if( usableKeyNo >= 0 ) {
559                        final String val = table.getValue( row,usableKeyNo ).trim();
560                        if( usableList.indexOf( val ) >= 0 ) { return true; }
561                }
562
563                if( breakClmNo >= 0 ) {
564                        final String val = table.getValue( row,breakClmNo ).trim();
565                        if( !val.equals( breakVal ) ) {                 // 同じでない場合は、true
566                                breakVal = val;
567                                return true;
568                        }
569                }
570
571                return false ;                  // 最後まで残ると、使用されないと判断、false を返す。
572        }
573
574        /**
575         *  itdフォーマット文字列を設定します。
576         *
577         * itd ボディ部の文字列を指定します。
578         * itd ボディは、繰り返し処理を行います。これを、上位のボディ文字列の中の
579         * HYBS_ITD_MARKER 文字列 と置き換えます。
580         *
581         * @og.rev 3.5.6.0 (2004/06/18) itdフォーマット文字列の取り込み
582         *
583         * @param  itd itdフォーマットの文字列
584         */
585        public void setItdBody( final String itd ) {
586                if( itd != null ) {
587                        itdBody = itd;
588                }
589        }
590
591        /**
592         *  itdフォーマット文字列を取得します。
593         *
594         * itd ボディ部の文字列を取得します。
595         * itd ボディは、繰り返し処理を行います。これを、上位のボディ文字列の中の
596         * HYBS_ITD_MARKER 文字列 と置き換えます。
597         *
598         * @og.rev 3.5.6.0 (2004/06/18) itdフォーマット文字列の取り込み
599         *
600         * @return      itdフォーマットの文字列
601         */
602        public String getItdBody() {
603                return itdBody;
604        }
605
606        /**
607         * サニタイズの戻し("\\]\\"から"["に戻し)を行います。
608         *
609         * @og.rev 5.1.7.0 (2010/06/01) 新規作成
610         *
611         * @param str サニタイズされた文字列
612         *
613         * @return サニタイズ戻し処理後の文字列
614         */
615        private String decodeSanitizedStr( final String str ) {
616                // 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
617                return str != null && str.indexOf( "\\]\\" ) >= 0 ?  str.replace( "\\]\\", "[" ) : str;
618
619        }
620}