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.plugin.view;
017
018import org.opengion.hayabusa.common.HybsSystem;
019import org.opengion.hayabusa.db.DBTableModel;
020import org.opengion.hayabusa.html.AbstractViewForm;
021import org.opengion.hayabusa.html.TableFormatter;                       // 6.3.9.0 (2015/11/06)
022import org.opengion.fukurou.model.Formatter;
023import org.opengion.fukurou.util.StringUtil;
024
025/**
026 * 検索結果を自動的に表形式に変換する、テーブル作成クラスです。
027 *
028 * AbstractViewForm により、setter/getterメソッドのデフォルト実装を提供しています。
029 * 各HTMLのタグに必要な setter/getterメソッドのみ,追加定義しています。
030 *
031 * AbstractViewForm を継承している為,ロケールに応じたラベルを出力させる事が出来ます。
032 *
033 * @og.group 画面表示
034 *
035 * @version  4.0
036 * @author       Kazuhiko Hasegawa
037 * @since    JDK5.0,
038 */
039public class ViewForm_HTMLTable extends AbstractViewForm {
040        /** このプログラムのVERSION文字列を設定します。   {@value} */
041        private static final String VERSION = "6.8.1.1 (2017/07/22)" ;
042
043        // 3.6.0.0 (2004/09/17) チェック済みの行の先頭に、フォーカスを当てる処理
044        private static final String LAYER_FOCUS = "<a href=\"#top\" name=\"h_fcs\" id=\"h_fcs\" ></a>" ;
045
046        // 6.4.4.1 (2016/03/18) static final 定数化します。
047        protected static final String NUMBER_DISPLAY = "<colgroup class=\"X\" ><!-- --></colgroup><colgroup class=\"BIT\" ><!-- --></colgroup><colgroup class=\"S9\" ><!-- --></colgroup>" + CR ;
048
049        // 5.2.3.0 (2010/12/01) テーブル罫線対応
050        private final String tableParam         = HybsSystem.sys( "HTML_TABLE_PARAM" ) ;
051        private final boolean useRowId          = HybsSystem.sysBool( "USE_CHECKBOX_ROW_ID" ) ; // 3.6.0.0 (2004/09/17)
052
053        // 6.1.2.0 (2015/01/24) HTML5 で colgroup が効かない対応で、protected化します。
054        protected final boolean useIE7Header    = HybsSystem.sysBool( "USE_IE7_HEADER" );               // 5.7.5.0 (2014/04/04) HTML5 で colgroup が効かない対応
055
056        /** ヘッダー部分のキャッシュ変数 */
057        protected String        headerLine      ;               // 3.5.2.0 (2003/10/20)
058
059        private String  cacheTag                ;               // 3.5.5.5 (2004/04/23)
060        private int[]   popupClmNo              ;               // 3.8.6.1 (2006/10/20)
061
062        /**
063         * デフォルトコンストラクター
064         *
065         * @og.rev 6.4.2.0 (2016/01/29) PMD refactoring. Each class should declare at least one constructor.
066         */
067        public ViewForm_HTMLTable() { super(); }                // これも、自動的に呼ばれるが、空のメソッドを作成すると警告されるので、明示的にしておきます。
068
069        /**
070         * 内容をクリア(初期化)します。
071         *
072         * @og.rev 3.1.1.0 (2003/03/28) 同期メソッド(synchronized付き)を非同期に変更する。
073         * @og.rev 3.5.2.0 (2003/10/20) ヘッダー繰り返し属性( headerSkipCount )を採用
074         * @og.rev 3.5.5.5 (2004/04/23) cacheTag,isCache 属性追加(チェックボックス作成用)
075         * @og.rev 3.5.6.2 (2004/07/05) bgColorCycle 変数の削除。
076         * @og.rev 3.8.6.1 (2006/10/20) popup の値を返す為のカラム番号配列(popupClmNo)追加
077         * @og.rev 5.1.6.0 (2010/05/01) caption 属性が使われていないため、削除する。
078         */
079        @Override
080        public void clear() {
081                super.clear();
082                cacheTag         = null;                // 3.5.5.5 (2004/04/23)
083                popupClmNo       = null;                // 3.8.6.1 (2006/10/20)
084        }
085
086        /**
087         * DBTableModel から HTML文字列を作成して返します。
088         * startNo(表示開始位置)から、pageSize(表示件数)までのView文字列を作成します。
089         * 表示残りデータが pageSize 以下の場合は,残りのデータをすべて出力します。
090         *
091         * @og.rev 3.5.2.0 (2003/10/20) ヘッダー繰り返し属性( headerSkipCount )を採用
092         * @og.rev 3.5.3.1 (2003/10/31) skip属性を採用。headerLine のキャッシュクリア
093         * @og.rev 3.5.5.0 (2004/03/12) No 欄そのものの作成判断ロジックを追加
094         * @og.rev 3.5.6.4 (2004/07/16) ヘッダーとボディー部をJavaScriptで分離
095         * @og.rev 3.7.0.3 (2005/03/01) getBgColorCycleClass に、選択行マーカーを採用
096         * @og.rev 4.3.1.0 (2008/09/08) 編集行のみを表示する属性(isSkipNoEdit)追加
097         * @og.rev 4.3.3.0 (2008/10/01) noTransition属性対応
098         * @og.rev 6.8.1.1 (2017/07/22) ckboxTD変数は、&lt;td&gt; から &lt;td に変更します(タグの最後が記述されていない状態でもらう)。
099         *
100         * @param  startNo        表示開始位置
101         * @param  pageSize   表示件数
102         *
103         * @return      DBTableModelから作成された HTML文字列
104         * @og.rtnNotNull
105         */
106        public String create( final int startNo, final int pageSize )  {
107                if( getRowCount() == 0 ) { return ""; } // 暫定処置
108
109                headerLine       = null;
110                final int lastNo = getLastNo( startNo, pageSize );
111                final int blc = getBackLinkCount();
112                final int hsc = getHeaderSkipCount();           // 3.5.2.0 (2003/10/20)
113                int hscCnt = 1;                                                         // 3.5.2.0 (2003/10/20)
114
115                final StringBuilder out = new StringBuilder( BUFFER_LARGE )
116                                .append( getCountForm( startNo,pageSize ) )
117                                .append( getHeader() );
118
119                final String ckboxTD = "  <td";                         // 6.8.1.1 (2017/07/22)
120
121                out.append("<tbody>").append( CR );
122                int bgClrCnt = 0;
123                final int clmCnt = getColumnCount();            // 3.5.5.7 (2004/05/10)
124                for( int row=startNo; row<lastNo; row++ ) {
125                        if( isSkip( row ) || isSkipNoEdit( row ) ) { continue; } // 4.3.1.0 (2008/09/08)
126                        out.append(" <tr").append( getBgColorCycleClass( bgClrCnt++,row ) );
127                        if( isNoTransition() ) {                        // 4.3.3.0 (2008/10/01)
128                                out.append( getHiddenRowValue( row ) );
129                        }
130                        out.append('>').append( CR );           // 6.0.2.5 (2014/10/31) char を append する。
131                        // 3.5.5.0 (2004/03/12) No 欄そのものの作成判断追加
132                        if( isNumberDisplay() ) {
133                                out.append( makeCheckbox( ckboxTD, row, blc ) ).append( CR );
134                        }
135                        for( int column=0; column<clmCnt; column++ ) {
136                                if( isColumnDisplay( column ) ) {
137                                        out.append("  <td>")
138                                                .append( getValueLabel(row,column) )
139                                                .append("</td>").append( CR );
140                                }
141                        }
142                        out.append(" </tr>").append( CR );
143
144                // 3.5.2.0 (2003/10/20) ヘッダー繰り返し属性( headerSkipCount )を採用
145                        if( hsc > 0 && hscCnt % hsc == 0 ) {
146                                out.append( getHeadLine() );
147                                hscCnt = 1;
148                        }
149                        else {
150                                hscCnt ++ ;
151                        }
152                }
153                out.append("</tbody>").append( CR )
154                        .append("</table>").append( CR )
155                        .append( getScrollBarEndDiv() );        // 3.8.0.3 (2005/07/15)
156
157                return out.toString();
158        }
159
160        /**
161         * 選択用のチェックボックスと行番号と変更タイプ(A,C,D)を表示します。
162         *
163         * 行番号の個別に、class="S9" を入れる処理を行うための新しいメソッドを作成しました。
164         * 互換性を保つためのメソッドを追加します。
165         *
166         * @og.rev 6.8.1.1 (2017/07/22) 互換性を保つためのメソッド
167         *
168         * @param       ckboxTD チェックボックスのタグ(マルチカラム時のrowspan対応)
169         * @param       row      行番号
170         * @param       blc      バックラインカウント(先頭へ戻るリンク間隔)
171         *
172         * @return      tdタグで囲まれたチェックボックスのHTML文字列
173         * @og.rtnNotNull
174         */
175        protected String makeCheckbox( final String ckboxTD,final int row,final int blc ) {
176                return makeCheckbox( ckboxTD, row, blc, false );
177        }
178
179        /**
180         * 選択用のチェックボックスと行番号と変更タイプ(A,C,D)を表示します。
181         *
182         * フォーマット系のViewに、makeNthChild を適用すると、思わぬ所で、副作用が発生します。
183         * その場合は、データ量は増えますが、個々の行番号欄に、class="S9" を入れていくのが
184         * もっとも確実な方法です。その切替を、useS9 変数で行います。
185         *
186         * @og.rev 3.5.1.0 (2003/10/03) Noカラムに、numberType 属性を追加
187         * @og.rev 3.5.4.0 (2003/11/25) Formatter をローカル変数に変更
188         * @og.rev 3.5.4.1 (2003/12/01) table オブジェクトのセット廃止
189         * @og.rev 3.5.5.5 (2004/04/23) Attributes オブジェクトのセット廃止
190         * @og.rev 3.6.0.0 (2004/09/17) ガントチャートの移動時にチェックするためのIDを追加
191         * @og.rev 3.6.0.0 (2004/09/17) チェック済みの行の先頭に、フォーカスを当てる処理を追加
192         * @og.rev 3.8.6.1 (2006/10/20) popup 用の値を設定する機能を追加
193         * @og.rev 6.4.3.4 (2016/03/11) Formatterに新しいコンストラクターを追加する。
194         * @og.rev 6.8.1.1 (2017/07/22) ckboxTD変数は、&lt;td&gt; から &lt;td に変更します(タグの最後が記述されていない状態でもらう)。
195         * @og.rev 6.8.1.1 (2017/07/22) 行番号のtdに、個別に class="S9" を追加するための useS9 変数を追加。
196         *
197         * @param       ckboxTD チェックボックスのタグ(マルチカラム時のrowspan対応)
198         * @param       row      行番号
199         * @param       blc      バックラインカウント(先頭へ戻るリンク間隔)
200         * @param       useS9    trueにすると、行番号のtdに、class="S9" を個別に入れます。
201         *
202         * @return      tdタグで囲まれたチェックボックスのHTML文字列
203         * @og.rtnNotNull
204         */
205        protected String makeCheckbox( final String ckboxTD,final int row,final int blc,final boolean useS9 ) {
206
207                final DBTableModel table = getDBTableModel() ;
208
209                // 6.3.9.0 (2015/11/06) Found 'DD'-anomaly for variable(PMD)
210                final String opAtt;
211                final String fmt = getOptionTypeAttributes();
212                if( fmt == null ) {
213                        opAtt = null;                   // 6.3.9.0 (2015/11/06)
214                }
215                else {
216                        final Formatter format = new Formatter( table,fmt );    // 6.4.3.4 (2016/03/11)
217                        opAtt = format.getFormatString( row );
218                }
219
220                final StringBuilder out = new StringBuilder( BUFFER_MIDDLE )
221                                        .append( ckboxTD ).append( '>' )                                // 6.8.1.1 (2017/07/22)
222                                        .append( table.getModifyType( row ) )
223                                        .append("</td>")
224                                        .append( ckboxTD ).append( '>' );                               // 6.8.1.1 (2017/07/22)
225
226                // 3.5.5.5 (2004/04/23) Attributes オブジェクトのセット廃止
227                final String inputTag = makeChboxTag();
228                if( isWritable( row ) && inputTag != null ) {
229                        out.append( inputTag );
230                        if( opAtt != null ) { out.append( opAtt ); }
231                        if( isChecked( row ) ) {
232                                out.append( " checked=\"checked\"" );
233                        }
234                        if( useRowId ) {        // 3.6.0.0 (2004/09/17)
235                                out.append( " id=\"" )
236                                        .append( HybsSystem.ROW_ID_KEY )
237                                        .append( row ).append( '"' );           // 6.0.2.5 (2014/10/31) char を append する。
238                        }
239                        if( popupClmNo != null ) {                                      // 3.8.6.1 (2006/10/20)
240                                makePopupReturn( out,row );                             // 内部で StringBuilder に append しています。
241                        }
242                        out.append( " value=\"" ).append( row ).append( "\" />" );
243                }
244                out.append("</td>" );
245                // 6.8.1.1 (2017/07/22) useS9 変数を追加
246                if( useS9 ) {
247                        final int ad = ckboxTD.indexOf( "class=" );             // class がすでに登録済みの場合
248                        if( ad >= 0 ) {
249                                out.append( ckboxTD.substring( 0,ad+7 ) ).append( "S9 " )       // +7 は、( class=" ) の文字数
250                                        .append( ckboxTD.substring( ad+7 ) ).append( '>' );
251                        }
252                        else {
253                                out.append( ckboxTD ).append( " class=\"S9\">");
254                        }
255                }
256                else {
257                        out.append( ckboxTD ).append( '>' );
258                }
259
260                // 3.5.1.0 (2003/10/03) Noカラムに、numberType 属性を追加
261                if( blc != 0 && (row+1) % blc == 0 ) {
262                        out.append( "<a href=\"#top\">" ).append( getNumberData( row ) ).append( "</a>");
263                } else {
264                        out.append( getNumberData( row ) );
265                }
266
267                // 4.3.5.3 (2008/02/22) Focus2のアンカー位置をtdタグ内に変更
268                if( isFirstChecked( row ) ) {
269                        out.append( LAYER_FOCUS );
270                }
271                out.append("</td>");
272                // if( isFirstChecked( row ) ) {
273                //      out.insert( 0,LAYER_FOCUS );
274                // }
275
276                return out.toString();
277        }
278
279        /**
280         * DBTableModel から テーブルのヘッダータグ文字列を作成して返します。
281         *
282         * @og.rev 3.5.2.0 (2003/10/20) ヘッダーそのもののキャッシュはしない。
283         *
284         * @return      テーブルのヘッダータグ文字列
285         * @og.rtnNotNull
286         */
287        protected String getHeader() {
288                return getTableTag() + getTableHead() ;
289        }
290
291        /**
292         * DBTableModel から テーブルのタグ文字列を作成して返します。
293         *
294         * @og.rev 3.5.0.0 (2003/09/17) &lt;tr&gt;属性は、元のフォーマットのまま使用します。
295         * @og.rev 3.5.1.0 (2003/10/03) Noカラムに、numberType 属性を追加
296         * @og.rev 3.5.4.0 (2003/11/25) TableFormatter クラスを使用するように変更。
297         * @og.rev 3.5.4.7 (2004/02/06) ヘッダーにソート機能用のリンクを追加します。
298         * @og.rev 3.5.5.0 (2004/03/12) systemFormat(例:[KEY.カラム名]形式等)の対応
299         * @og.rev 3.5.5.0 (2004/03/12) No 欄そのものの作成判断ロジックを追加
300         * @og.rev 6.2.0.0 (2015/02/27) フォーマット系の noDisplay 対応
301         * @og.rev 6.3.9.0 (2015/11/06) 引数にTableFormatterを渡して、処理の共有化を図る。
302         *
303         * @param       footerFormat TableFormatterオブジェクト
304         * @return      テーブルのタグ文字列
305         * @og.rtnNotNull
306         */
307        protected String getTableFoot( final TableFormatter footerFormat ) {
308                footerFormat.makeFormat( getDBTableModel() );
309                // 6.2.0.0 (2015/02/27) フォーマット系の noDisplay 対応
310                setFormatNoDisplay( footerFormat );
311
312                final StringBuilder buf = new StringBuilder( BUFFER_MIDDLE )
313                        .append("<tfoot>").append( CR )
314                        .append( footerFormat.getTrTag() ).append( CR );
315
316                // 3.5.5.0 (2004/03/12) No 欄そのものの作成判断追加
317                if( isNumberDisplay() ) {
318                        buf.append("<th colspan=\"3\"")
319                                .append( footerFormat.getRowspan() )
320                                .append("></th>");
321                }
322
323                int cl = 0;
324                for( ; cl<footerFormat.getLocationSize(); cl++ ) {
325                        final int loc = footerFormat.getLocation(cl);
326                        if( loc >= 0 ) { buf.append( getSortedColumnLabel(loc) ); }
327                }
328                buf.append( footerFormat.getFormat(cl) ).append( CR )
329                        .append("</tfoot>").append( CR );
330
331                return buf.toString();
332        }
333
334        /**
335         * DBTableModel から テーブルのタグ文字列を作成して返します。
336         *
337         * @og.rev 3.5.6.4 (2004/07/16) ヘッダーとボディー部をJavaScriptで分離
338         * @og.rev 3.6.0.0 (2004/09/17) ヘッダー固定スクロールの簡素化(スクロールバーを右に出す)
339         * @og.rev 3.6.0.5 (2004/10/18) 印刷時の罫線出力関連機能の追加。id 属性を出力します。
340         * @og.rev 4.0.0.0 (2005/08/31) テーブル表示の CSSファイル利用の有無
341         * @og.rev 5.1.6.0 (2010/05/01) caption 属性が使われていないため、削除する。
342         * @og.rev 5.2.3.0 (2010/12/01) テーブル罫線対応
343         * @og.rev 5.3.4.0 (2011/04/01) テーブル罫線の初期値チェック変更
344         *
345         * @return      テーブルのタグ文字列
346         * @og.rtnNotNull
347         */
348        protected String getTableTag() {
349                final StringBuilder buf = new StringBuilder( BUFFER_MIDDLE )
350                        .append( getScrollBarStartDiv() )                                       // 3.8.0.3 (2005/07/15)
351                        .append("<table ");
352                // 5.2.3.0 (2010/12/01) テーブル罫線対応
353                if( tableParam != null && !tableParam.isEmpty() ) {
354                        buf.append( tableParam ).append( ' ' );                                 // 6.0.2.5 (2014/10/31) char を append する。
355                }
356                buf.append( "id=\"viewTable\" class=\"" )
357                        .append( getTableClass() )
358                        .append( "\">" ).append( CR );
359
360                return buf.toString();
361        }
362
363        /**
364         * HTML5 で colgroup が効かない暫定対応の、処理をまとめるメソッド
365         * 
366         * #viewTable td:nth-child(n) { text-align:right; } CSSを出力するメソッドをまとめました。
367         * 呼び出し元の、getTableHead() のコードをすっきりさせるためのメソッドです。
368         *
369         * @og.rev 5.7.5.0 (2014/04/04) 新規追加
370         * @og.rev 6.1.2.0 (2015/01/24) 他のクラスでも使用する為、protected化します。
371         * @og.rev 5.9.5.3 (2016/02/26) viewTableにtableIdのクラスを追加する対応
372         * @og.rev 6.4.4.1 (2016/03/18) StringBuilderのappend部分の見直し。
373         * @og.rev 6.4.4.2 (2016/04/01) className に BIT が指定された場合の対応。
374         * @og.rev 6.4.6.1 (2016/06/03) tableId 廃止(利用目的を明確にするため、パラメータ名をviewClassに変更)
375         * @og.rev 6.4.6.1 (2016/06/03) DbType とClassName が複雑化しているため、とりあえずの暫定対策。
376         *
377         * @param buf           タグ文字列をappendしていくStringBuilder
378         * @param ad            TDタグの番号 nth-child(n)設置する場合の n の値
379         * @param dbType        text-alignを決めるためのDBTYPE
380         *                  (R,S9,X9→text-align:right; , BIT→text-align:center; , 他素通り)
381         *
382         * @return      テーブルのタグ文字列(入力と同じStringBuilder)
383         * @og.rtnNotNull
384         * @see         #getTableHead()
385         */
386        protected StringBuilder makeNthChild( final StringBuilder buf , final int ad , final String dbType ) {
387                // 6.4.6.1 (2016/06/03) DbType とClassName が複雑化しているため、とりあえずの暫定対策。
388                // 従来の dbType には、R,S9,X9 などが、単独で来ます。
389                // BIT は、ClassName に含まれており、R,S9,X9 も、スペース連結で含まれます。
390                // 先に、BIT判定を行います。
391                int hantei = 0;                 // 0:は素通りする。
392                if( dbType != null ) {  // たぶん、不要
393                        if( dbType.contains( "BIT" ) ) { hantei = 2; }
394                        else {
395                                final String type = " " + dbType + " " ;
396                                if( type.contains( " R " ) || type.contains( " S9 " ) || type.contains( " X9 " ) ) { hantei = 1; }
397                        }
398                }
399
400                if( hantei == 1 ) {                             // 6.4.6.1 (2016/06/03)
401                        buf.append( "  #viewTable." ).append( getViewClass() ).append( " td:nth-child(" ).append( ad )
402                                .append( ") { text-align:right; }" ).append( CR );
403                }
404                else if( hantei == 2 ) {                // 6.4.6.1 (2016/06/03)
405                        buf.append( "  #viewTable." ).append( getViewClass() ).append( " td:nth-child(" ).append( ad )
406                                .append( ") { text-align:center; }" ).append( CR );
407                }
408                // 上記(R,S9,X9,BIT)以外のdbTypeの場合は、素通りします。(入力のStringBuilderをそのまま返すだけ)
409
410                return buf ;
411        }
412
413        /**
414         * DBTableModel から テーブルのタグ文字列を作成して返します。
415         *
416         * @og.rev 3.5.1.0 (2003/10/03) Noカラムに、numberType 属性を追加
417         * @og.rev 3.5.2.0 (2003/10/20) ヘッダー繰り返し部をgetHeadLine()へ移動
418         * @og.rev 3.5.3.1 (2003/10/31) VERCHAR2 を VARCHAR2 に修正。
419         * @og.rev 3.5.5.0 (2004/03/12) No 欄そのものの作成判断ロジックを追加
420         * @og.rev 3.5.6.5 (2004/08/09) thead に、id="header" を追加
421         * @og.rev 4.0.0.0 (2005/01/31) DBColumn の 属性(CLS_NM)から、DBTYPEに変更
422         * @og.rev 4.0.0.0 (2005/01/31) 新規作成(getColumnClassName ⇒ getColumnDbType)
423         * @og.rev 5.7.5.0 (2014/04/04) HTML5 で colgroup が効かない暫定対応(真の原因不明)
424         * @og.rev 5.9.1.2 (2015/10/23) 自己終了警告対応
425         * @og.rev 6.4.4.1 (2016/03/18) NUMBER_DISPLAYを、static final 定数化します。
426         * @og.rev 6.4.5.0 (2016/04/08) メソッド変更( getColumnDbType(int) → getClassName(int) )
427         * @og.rev 6.4.6.1 (2016/06/03) DbType とClassName が複雑化しているため、とりあえずの暫定対策。
428         * @og.rev 6.8.1.0 (2017/07/14) HTML5対応ヘッダー出力設定時に、ブラウザを互換設定したときの対応。
429         *
430         * @return      テーブルのタグ文字列
431         * @og.rtnNotNull
432         */
433        protected String getTableHead() {
434                final StringBuilder buf = new StringBuilder( BUFFER_MIDDLE );
435
436                // 5.7.5.0 (2014/04/04) HTML5 で colgroup が効かない対応
437                // 本当は、tableタグの前に入れたかったが、ややこしいので table タグの直後に入れます。
438                // 互換モードでない場合専用。処理速度を気にするより、処理を一か所にまとめておきます。
439                if( !useIE7Header ) {
440                        buf.append( "<style type=\"text/css\">" ).append( CR );
441                        // 6.3.9.0 (2015/11/06) Found 'DD'-anomaly for variable(PMD)
442                        int ad = 1;
443        //              int ad ;
444                        if( isNumberDisplay() ) {
445                                makeNthChild( buf,2,"BIT" );
446                                makeNthChild( buf,3,"S9"  );
447                                ad = 4;
448                        }
449        //              else {
450        //                      ad = 1;         // 6.3.9.0 (2015/11/06)
451        //              }
452
453                        final int clmCnt = getColumnCount();
454                        for( int column=0; column<clmCnt; column++ ) {
455                                if( isColumnDisplay( column ) ) {
456                                        // 6.4.6.1 (2016/06/03) DbType とClassName が複雑化しているため、とりあえずの暫定対策。
457                                        makeNthChild( buf,ad,getClassName(column) );                    // 6.4.6.1 (2016/06/03)
458                                        ad++ ;                  // tdタグの順番なので、表示する場合のみカウントする。
459                                }
460                        }
461                        buf.append( "</style>" ).append( CR );
462                }
463
464                // 3.5.5.0 (2004/03/12) No 欄そのものの作成判断追加
465                if( isNumberDisplay() ) {
466                        // 5.9.1.2 (2015/10/23) 自己終了警告対応
467                        // 6.4.4.1 (2016/03/18) NUMBER_DISPLAYを、static final 定数化します。
468                        buf.append( NUMBER_DISPLAY );                                   // 6.8.1.0 (2017/07/14) HTML5ネイティブ時でも、出力します。
469                }
470
471                final int clmCnt = getColumnCount();                            // 3.5.5.7 (2004/05/10)
472                for( int column=0; column<clmCnt; column++ ) {
473                        if( isColumnDisplay( column ) ) {
474                                buf.append("<colgroup class=\"" )
475                                        .append( getClassName(column) )                 // 6.4.5.0 (2016/04/08)
476                                        // 5.9.1.2 (2015/10/23) 自己終了警告対応
477                                        .append("\"><!-- --></colgroup>")
478                                        .append( CR );
479                        }
480                }
481
482        // 3.5.2.0 (2003/10/20) ヘッダー繰り返し部をgetHeadLine()へ移動
483                buf.append("<thead id=\"header\">").append( CR )        // 3.5.6.5 (2004/08/09)
484                        .append( getHeadLine() )
485                        .append("</thead>").append( CR );
486
487                return buf.toString();
488        }
489
490        /**
491         * ヘッダー繰り返し部を、getTableHead()メソッドから分離。
492         *
493         * @og.rev 3.5.4.5 (2004/01/23) 実装をgetHeadLine( String thTag )に移動
494         * @og.rev 6.1.2.0 (2015/01/24) キャッシュを返すのを、#getHeadLine() に移動。
495         *
496         * @return      テーブルのタグ文字列
497         * @og.rtnNotNull
498         */
499        protected String getHeadLine() {
500                if( headerLine == null ) {                                      // キャッシュになければ、設定する。
501                        headerLine = getHeadLine( "<th" ) ;
502                }
503
504                return headerLine ;
505        }
506
507        /**
508         * ヘッダー繰り返し部を、getTableHead()メソッドから分離。
509         *
510         * @og.rev 3.5.2.0 (2003/10/20) 新規作成
511         * @og.rev 3.5.4.3 (2004/01/05) useCheckControl 属性の機能を追加
512         * @og.rev 3.5.4.5 (2004/01/23) thタグの属性設定出来る様に新規追加。
513         * @og.rev 3.5.4.6 (2004/01/30) numberType="none" 時の処理を追加(Noラベルを出さない)
514         * @og.rev 3.5.4.7 (2004/02/06) ヘッダーにソート機能用のリンクを追加します。
515         * @og.rev 3.7.0.1 (2005/01/31) 全件チェックコントロール処理変更
516         * @og.rev 6.1.2.0 (2015/01/24) キャッシュを返すのを、#getHeadLine() に移動。
517         *
518         * @param       thTag タグの文字列
519         *
520         * @return      テーブルのタグ文字列
521         * @og.rtnNotNull
522         */
523        protected String getHeadLine( final String thTag ) {
524
525                final StringBuilder buf = new StringBuilder( BUFFER_MIDDLE )
526                        .append("<tr class=\"row_h\">").append( CR );
527
528                // 3.5.5.0 (2004/03/12) No 欄そのものの作成判断追加
529                if( isNumberDisplay() ) {
530                        // 3.5.4.3 (2004/01/05) 追加分
531                        if( isUseCheckControl() && "checkbox".equals( getSelectedType() ) ) {
532                                // 3.5.4.5 (2004/01/23) thタグの属性設定出来る様に変更。
533                                // 6.0.2.5 (2014/10/31) char を append する。
534                                buf.append(  thTag ).append( "></th>" )
535                                        .append( thTag ).append( '>' ).append( getAllCheckControl() ).append( "</th>" )
536                                        .append( thTag ).append( '>' ).append( getNumberHeader()    ).append( "</th>" );        // 3.5.4.6 (2004/01/30)
537                        }
538                        else {
539                                // 3.5.4.5 (2004/01/23) thタグの属性設定出来る様に変更。
540                                buf.append( thTag ).append( " colspan='3'>" ).append( getNumberHeader() ).append( "</th>" );    // 3.5.4.6 (2004/01/30)
541                        }
542                }
543
544                buf.append( CR );
545                final int clmCnt = getColumnCount();                    // 3.5.5.7 (2004/05/10)
546                for( int column=0; column<clmCnt; column++ ) {
547                        if( isColumnDisplay( column ) ) {
548                                // 3.5.4.5 (2004/01/23) thタグの属性設定出来る様に変更。
549                                buf.append( thTag ).append('>')                 // 6.0.2.5 (2014/10/31) char を append する。
550                                        .append( getSortedColumnLabel(column) )
551                                        .append("</th>").append( CR );
552                        }
553                }
554                buf.append("</tr>").append( CR );
555
556                return buf.toString();                          // 6.1.2.0 (2015/01/24)
557        }
558
559        /**
560         * フォーマットメソッドを使用できるかどうかを問い合わせます。
561         *
562         * @return  使用可能(true)/ 使用不可能(false)
563         */
564        public boolean canUseFormat() {
565                return false;
566        }
567
568        /**
569         * ogPopup で検索結果の値を返すキーを、CSV形式で指定します。
570         *
571         * popup の検索結果を返す画面で、結果のラジオボタンにイベントセットします。
572         * この場合、オープンもとのwindow に値を返しますが、そのキーをCSV形式で
573         * 指定します。なお、設定は、init 以降(つまり、DBTableModelは設定済み)の
574         * 状態で呼び出してください。(エラーにしません)
575         * なお、このメソッドは、一覧表示(HTMLTable)関係のビューのみでサポートして
576         * いますが、チェックメソッドの関係で、それ以外のビューに適用しても素通り
577         * するようにします。(エラーにしません)
578         *
579         * @og.rev 3.8.6.1 (2006/10/20) 新規追加
580         *
581         * @param  rtnKeys ogPopupで値を返すカラム文字列(CSV形式)
582         */
583        @Override
584        public void setPopupReturnKeys( final String rtnKeys ) {
585                final DBTableModel table = getDBTableModel() ;
586                if( table != null && table.getRowCount() > 0 && rtnKeys != null ) {
587                        final String[] clmNames = StringUtil.csv2Array( rtnKeys );
588                        popupClmNo = new int[clmNames.length];
589                        for( int i=0; i<clmNames.length; i++ ) {
590                                final int no = table.getColumnNo( clmNames[i] );
591                                if( no >= 0 ) { popupClmNo[ i ] = no; }
592                        }
593                }
594        }
595
596        /**
597         * ogPopup で検索結果の値を返すキーを、CSV形式で指定します。
598         *
599         * popup の検索結果を返す画面で、結果のラジオボタンにイベントセットします。
600         * この場合、オープンもとのwindow に値を返しますが、そのキーをCSV形式で
601         * 指定します。なお、設定は、init 以降(つまり、DBTableModelは設定済み)の
602         * 状態で呼び出してください。(エラーにしません)
603         * なお、このメソッドは、一覧表示(HTMLTable)関係のビューのみでサポートして
604         * いますが、チェックメソッドの関係で、それ以外のビューに適用しても素通り
605         * するようにします。(エラーにしません)
606         * rtnPopup に値を渡す場合に、ダブルクオート(")、シングルクオート(')は、
607         * それぞれ、ASCII コード(¥x22、¥x27)に置き換えます。
608         *
609         * @og.rev 3.8.6.1 (2006/10/20) 新規追加
610         *
611         * @param  buf StringBuilder 追加するStringBuilderオブジェクト
612         * @param       rowNo   列番号
613         *
614         * @return      引数にデータを追加した後の同一オブジェクト
615         * @og.rtnNotNull
616         */
617        private StringBuilder makePopupReturn( final StringBuilder buf,final int rowNo ) {
618                int clmNo = popupClmNo[ 0 ];
619                String val = StringUtil.quoteFilter( getValue( rowNo,clmNo ) );
620                buf.append( " onClick=\"rtnPopup(new Array('" ).append( val ).append( '\'' );
621                for( int i=1; i<popupClmNo.length; i++ ) {
622                        clmNo = popupClmNo[ i ];
623                        val = StringUtil.quoteFilter( getValue( rowNo,clmNo ) );
624                        buf.append( ",'" ).append( val ).append( '\'' );
625                }
626                buf.append( "));\"" );
627
628                return buf;
629        }
630
631        /**
632         * 選択用のチェックボックスの input タグを作成します。
633         *
634         * @og.rev 3.5.5.5 (2004/04/23) 新規作成
635         *
636         * @return      チェックボックスのinputタグ
637         */
638        private String makeChboxTag() {
639                // 6.3.9.1 (2015/11/27) A method should have only one exit point, and that should be the last statement in the method.(PMD)
640                if( cacheTag == null ) {
641                        final String type = getSelectedType();          // "checkbox"/"radio"/"hidden"
642
643                        if( type != null ) {
644                                final StringBuilder buf = new StringBuilder( BUFFER_MIDDLE )
645                                        .append( "<input type=\"" ).append( type ).append( '"' )
646                                        .append( " name=\"" ).append( HybsSystem.ROW_SEL_KEY ).append( '"' );           // 6.0.2.5 (2014/10/31) char を append する。
647
648                                cacheTag = buf.toString();
649                        }
650                }
651                return cacheTag ;
652        }
653
654        /**
655         * カラムのラベル名(短)を返します。
656         * カラムの項目名に対して,見える形の文字列を返します。
657         * 一般には,リソースバンドルと組合せて,各国ロケール毎にラベルを
658         * 切替えます。
659         *
660         * @og.rev 4.0.0.0 (2005/01/31) 新規追加( shortLabel を返します。)
661         *
662         * @param       column カラム番号
663         *
664         * @return      カラムのラベル名(短)
665         */
666        @Override
667        protected String getColumnLabel( final int column ) {
668                return getDBColumn( column ).getShortLabel();
669        }
670}