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     */
016    package org.opengion.hayabusa.report;
017    
018    import org.opengion.hayabusa.common.HybsSystem;
019    import org.opengion.hayabusa.common.HybsSystemException;
020    import org.opengion.fukurou.util.LogWriter;
021    import org.opengion.hayabusa.db.DBTableModel;
022    import org.opengion.hayabusa.db.DBColumn;
023    import org.opengion.hayabusa.resource.ResourceManager;
024    import org.opengion.fukurou.util.StringUtil;
025    import org.opengion.fukurou.util.FileUtil;
026    import org.opengion.fukurou.util.Closer ;
027    
028    import java.io.File;
029    import java.io.BufferedReader;
030    import java.io.PrintWriter;
031    
032    /**
033     * DBTableReport インターフェース のãƒ?ƒ•ォルト実è£?‚¯ラスですã?
034     * writeReport() をã?オーバã?ライドすれã??Œ各種出力フォーマットに合わせた
035     * サブクラスを実現する事が可能ですã?
036     *
037     * @og.group 帳票シスãƒ?ƒ 
038     *
039     * @version  4.0
040     * @author       Kazuhiko Hasegawa
041     * @since    JDK5.0,
042     */
043    public abstract class AbstractDBTableReport implements DBTableReport {
044            private static final String ENCODE = HybsSystem.REPORT_ENCODE ;
045    
046            protected String[]              headerKeys      = null;         // 固定部の key 部åˆ?‚’æŒ?®šするã?カンマでè¤?•°æŒ?®šできるã€?
047            protected String[]              headerVals      = null;         // 固定部の key に対応するå?を指定するã?
048            protected String[]              footerKeys      = null;         // 繰り返し部の終äº?¾Œに表示する key 部åˆ?‚’æŒ?®šするã?カンマでè¤?•°æŒ?®šできるã€?
049            protected String[]              footerVals      = null;         // 繰り返し部の終äº?¾Œに表示する key に対する値を指定するã?
050            protected boolean               pageEndCut      = false;        // ボディー部(繰り返し部)がなくなったときに、それ以降ã?ペã?ジをå?力するかæŒ?®šするã?
051            protected int                   maxRowCount     = 0;            // 自動計算方式を採用
052            protected int                   pageRowCount    = 0;    // 過去のペã?ジのæœ?¤§件数ã€?3.7.0.1 (2005/01/31)
053            protected int                   lineCopyCnt     = 0;            // LINE_COPY した際ã?åŠ?®—行番号ã€?4.0.0 (2007/06/08)
054            protected ResourceManager resource  = null;             // 4.0.0 (2005/01/31)
055            protected PrintWriter   writer          = null;
056            protected BufferedReader reader         = null;
057            protected File                  templateFile            = null;         // 3.8.0.0 (2005/06/07)
058            protected File                  firstTemplateFile       = null;         // 3.8.0.0 (2005/06/07)
059            protected String                htmlDir         = null;
060            protected String                htmlFileKey     = null;
061            protected String                ykno            = null;         // 3.8.5.1 (2006/04/28) 追åŠ?
062            protected DBTableModel  table           = null;
063    
064            protected int                   pageCount       = 0;
065            protected int                   maxPageCount = 1000;
066            protected boolean               rowOver         = false;        // ãƒ??タ件数åˆ??カラãƒ?‚’要求されると、true にセãƒ?ƒˆされるã?
067            protected boolean               dataOver        = false;        // 3.8.1.2 (2005/12/19) ãƒ??タがなくなると、true にセãƒ?ƒˆされるã?
068    
069            // 3.6.0.0 (2004/09/24) フォーマットエラーの判å®?formatErr)をã?子クラスから移動しますã?
070            private boolean  formatErr      = false;                // フォーマットエラーの判å®?
071    
072            // 3.6.1.0 (2005/01/05) 帳票?©?¤追åŠ?
073            protected String                listId          = null;
074    
075            // 3.7.0.1 (2005/01/31) ペã?ジブレイク時ã?処ç�?
076            private static final String PAGEBREAK = "PAGEBREAK";
077            private int                             pbClmNo         = -1;           // PAGEBREAK カラãƒ??番号
078            private boolean                 pageBreak       = false;        // PAGEBREAK = "1" が見つかった時、true
079            private int                             tableSize       = 0;
080    
081            /**
082             * DBTableModel から ãƒ??タを作æ?して,PrintWriter に書きå?しますã?
083             *
084             */
085            public void writeReport() {
086                    setHeaderFooter();
087                    initReader();
088                    initWriter();
089                    String str ;
090                    while( (str = readLine()) != null ) {
091                            println( changeData( str ) );
092                    }
093                    close();
094            }
095    
096            /**
097             * 入力文字å? を読み取って、å?力しますã?
098             * tr タグを目印にã€?¼‘è¡?trタグé–?ずつ取り出しますã?
099             * 読み取りを終äº?�™るå?合ã?、null を返しますã?
100             * å�?‚µブクラスで実è£?�—てくださいã€?
101             *
102             * @return      出力文字å?
103             */
104            abstract protected String readLine() ;
105    
106            /**
107             * 入力文字å? を加工して、å?力しますã?
108             * {@XXXX} をテーブルモãƒ?ƒ«より読み取り、å?をセãƒ?ƒˆしますã?
109             * å�?‚µブクラスで実è£?�—てくださいã€?
110             *
111             * @param       inLine  入力文字å?
112             *
113             * @return      出力文字å?
114             */
115            abstract protected String changeData( final String inLine ) ;
116    
117            /**
118             * 入力文字å? を読み取って、å?力しますã?
119             * å�?‚µブクラスで実è£?�—てくださいã€?
120             *
121             * @param line 出力文字å?
122             */
123            abstract protected void println( final String line ) ;
124    
125            /**
126             * リソースマネージャーをセãƒ?ƒˆしますã?
127             * これは、è¨?ª?ロケール)に応じã�?DBColumn をあらかじめ設定しておく為に
128             * å¿?¦�ですã?
129             * リソースマネージャーが設定されてã�?�ªã�??またã?、所定ã?キーの DBColumn ã�?
130             * リソースに存在しなã�??合ã?、å?部で DBColumn オブジェクトを作æ?しますã?
131             *
132             * @og.rev 4.0.0.0 (2005/01/31) lang â‡?ResourceManager へ変更
133             *
134             * @param  resource リソースマネージャー
135             */
136            public void setResourceManager( final ResourceManager resource ) {
137                    this.resource = resource;
138            }
139    
140            /**
141             * 帳票?©?¤ をセãƒ?ƒˆしますã?
142             * こã?帳票?©?¤を利用して、画像ファイル等ã?セーブディレクトリを求めますã?
143             *
144             * @og.rev 3.6.1.0 (2005/01/05) 新規作æ?
145             *
146             * @param   listId 帳票?©?¤
147             */
148            public void setListId( final String listId ) {
149                    this.listId = listId ;
150            }
151    
152            /**
153             * DBTableModel をセãƒ?ƒˆしますã?
154             *
155             * @og.rev 3.7.0.1 (2005/01/31) ペã?ジブレイク時ã?処ç�?
156             *
157             * @param       table   DBTableModelオブジェクãƒ?
158             */
159            public void setDBTableModel( final DBTableModel table ) {
160                    this.table = table;
161                    // 3.7.0.1 (2005/01/31) ペã?ジブレイク時ã?処ç�?
162                    tableSize = table.getRowCount();
163                    pbClmNo   = table.getColumnNo( PAGEBREAK,false );               // 存在しなã�??合ã?ã€?1
164    
165    //              try {
166    //                      pbClmNo = table.getColumnNo( PAGEBREAK );
167    //              }
168    //              catch( HybsSystemException e ) {
169    //                      pbClmNo = -1;
170    //              }
171            }
172    
173            /**
174             * 雛型ファイル名をセãƒ?ƒˆしますã?
175             *
176             * @og.rev 3.6.0.0 (2004/09/17) メソãƒ?ƒ‰名ã?変更。setInputFile â‡?setTemplateFile
177             * @og.rev 3.8.0.0 (2005/06/07) 引数ã‚?String  â‡?File に変更
178             *
179             * @param   inFile 雛型ファイルå�?
180             */
181            public void setTemplateFile( final File inFile ) {
182                    templateFile = inFile;
183            }
184    
185            /**
186             * æœ??のペã?ジのみに使用する雛型ファイル名をセãƒ?ƒˆしますã?
187             *
188             * @og.rev 3.6.0.0 (2004/09/17) 新規追åŠ?
189             * @og.rev 3.8.0.0 (2005/06/07) 引数ã‚?String  â‡?File に変更
190             *
191             * @param   inFile æœ??のペã?ジの雛型ファイルå�?
192             */
193            public void setFirstTemplateFile( final File inFile ) {
194                    firstTemplateFile = inFile;
195            }
196    
197            /**
198             * 変換後ファイルをå?力するディレクトリ名をセãƒ?ƒˆしますã?
199             * ãƒ?‚£レクトリが存在しなã�??合ã?、新規に作æ?しますã?
200             *
201             * @og.rev 3.7.1.1 (2005/05/23) フォルãƒ?�Œなã�??合ã?、è¤?•°階層åˆ??フォルãƒ?‚’自動で作æ?しますã?
202             *
203             * @param   outDir 出力ディレクトリ
204             */
205            public void setOutputDir( final String outDir ) {
206                    htmlDir = outDir;
207    
208                    File dir = new File(htmlDir);
209                    if( ! dir.exists() && ! dir.mkdirs() ) {
210                            String errMsg = "ãƒ?‚£レクトリの作æ?に失敗しましたã€?" + htmlDir + "]";
211                            throw new HybsSystemException( errMsg );
212                    }
213            }
214    
215            /**
216             * 変換後ファイルキーをセãƒ?ƒˆしますã?
217             * キーとは、拡張子ã?無ã�?ж態までのファイル名ですã?
218             * 変換後ファイルは、è¤?•°発生しますã?
219             * 実際に出力されるファイル名ã?、outFile + "_連番.html" となりますã?
220             *
221             * @param   outFile 出力ファイル名ã?共通部
222             */
223            public void setOutputFileKey( final String outFile ) {
224                    htmlFileKey = outFile;
225            }
226    
227            /**
228             * 帳票起動された要求番号をセãƒ?ƒˆしますã?
229             *
230             * @og.rev 3.8.5.1 (2006/04/28) 新規追åŠ?
231             *
232             * @param   ykno 要求番号
233             */
234            public void setYkno( final String ykno ) {
235                    this.ykno = ykno;
236            }
237    
238            /**
239             * 固定部の key 部åˆ?‚’æŒ?®šしますã?
240             * カンマでè¤?•°æŒ?®šできますã?
241             *
242             * @og.rev 3.5.6.0 (2004/06/18) 配å?の設定ã?、arraycopy して取り込みますã?
243             *
244             * @param   hKeys 固定部のキー
245             */
246            public void setHeaderKeys( final String[] hKeys ) {
247                    if( hKeys != null ) {
248                            int size = hKeys.length ;
249                            headerKeys = new String[size];
250                            System.arraycopy( hKeys,0,headerKeys,0,size );
251                    }
252                    else {
253                            headerKeys = null;
254                    }
255            }
256    
257            /**
258             * 固定部のkey に対応するå?を指定しますã?
259             * カンマでè¤?•°æŒ?®šで、リクエスト情報でも設定できますã?
260             *
261             * @og.rev 3.5.6.0 (2004/06/18) 配å?の設定ã?、arraycopy して取り込みますã?
262             *
263             * @param   hVals 固定部の値
264             */
265            public void setHeaderVals( final String[] hVals ) {
266                    if( hVals != null ) {
267                            int size = hVals.length ;
268                            headerVals = new String[size];
269                            System.arraycopy( hVals,0,headerVals,0,size );
270                    }
271                    else {
272                            headerVals = null;
273                    }
274            }
275    
276            /**
277             * 雛型帳票に対する、実際の行番号を求めますã?
278             * これはã€?››型ã?è¤?•°回読みをサポã?トする為、実際の雛型のrow番号と
279             * DBTableModel から取得すべã�?row番号がã?異なる為ですã?
280             * オーバã?フロー時ã?、Exception を避ける為ã€?1 を返しますã?
281             *
282             * @og.rev 3.5.6.0 (2004/06/18) noDataflag の追åŠ??
283             * @og.rev 3.5.6.3 (2004/07/12) noDataflag のå»?­¢ã€?
284             * @og.rev 3.6.0.4 (2004/10/14) FIRST 雛型時ã?対応追åŠ??
285             * @og.rev 3.7.0.1 (2005/01/31) ペã?ジブレイク処ç�?�«対応ã?
286             * @og.rev 3.8.1.2 (2005/12/19) PAGE_END_CUT用にdataOverフラグを追åŠ?
287             *
288             * @param       row 固定部の値(オーバã?フロー時ã?ã€?1 )
289             *
290             * @return      実際の行番号
291             */
292            protected int getRealRow( final int row ) {
293    
294                    // 3.7.0.1 (2005/01/31) ペã?ジブレイク処ç�?�«対応ã?
295                    int realRow = pageRowCount + row + lineCopyCnt ;
296                    if( maxRowCount <= realRow ) { maxRowCount = realRow + 1; }
297    
298                    if( realRow >= (tableSize-1) ) {                     // 行番号が最大値と同じ(ãƒ??タは存在)
299                            rowOver = true;
300                            if( realRow >= tableSize ) { // さらに、データは存在しなã�??
301                                    realRow = -1;           // 3.5.6.3 (2004/07/12) オーバã?フロー
302                                    dataOver = true;        // 3.8.1.2 (2005/12/19)
303                            }
304                    }
305    
306                    return realRow ;
307            }
308    
309            /**
310             * æŒ?®šã?キーにつã�?�¦、その値を取得しますã?
311             * 値の取得方法としてã€?
312             * ã€??{&#064;xxx_no} 形式ã?場合ã?、DBTableModel からã€?
313             * ã€??{&#064;XXXX} 形式で、かつ、rowOver ã�?false の場合ã?、ã?ãƒ?ƒ€ーからã€?
314             * ã€??{&#064;XXXX} 形式で、かつ、rowOver ã�?true の場合ã?、フãƒ?‚¿ーからã€?
315             * 取得しますã?
316             * rowOver は、{&#064;xxx_no} 形式ã?番号æ¬?no)がã?DBTableModel のãƒ??タ件数よりã‚?
317             * 大きい場合に、セãƒ?ƒˆされますã?
318             *
319             * @og.rev 3.5.6.0 (2004/06/18) noDataflag の追åŠ??
320             * @og.rev 3.5.6.3 (2004/07/12) noDataflag のå»?­¢ã€?
321             * @og.rev 3.6.0.0 (2004/09/24) フォーマットエラーの判å®?formatErr)をã?子クラスから移動しますã?
322             * @og.rev 3.7.0.1 (2005/01/31) ペã?ジブレイク時ã?処ç�?¿½åŠ??
323             * @og.rev 3.7.0.2 (2005/02/18) HTML のエスケープ文字対å¿?
324             * @og.rev 3.7.1.1 (2005/05/09) セルå†??改è¡?<br> は、エスケープしなã�??
325             * @og.rev 3.8.0.0 (2005/06/07) Shift-JIS で中国語を扱ã�??(Unicodeエスケープ文字ã?、エスケープしなã�?
326             * @og.rev 3.8.5.1 (2006/04/28) YKNO を特別扱ã�?�™るã?
327             *
328             * @param   key æŒ?®šã?キー
329             *
330             * @return  æŒ?®šã?キーの値
331             */
332            protected String getValue( final String key ) {
333                    if( pageBreak ) { return ""; }          // 3.7.0.1 (2005/01/31) ペã?ジブレイク時ã?処ç�?
334    
335                    int sp = key.lastIndexOf( '_' );
336                    if( sp >= 0 ) {
337                            try {
338                                    int row = Integer.parseInt( key.substring( sp+1 ) );
339                                    int realRow = getRealRow( row );
340    
341                                    if( realRow >= 0 ) { // 3.5.6.3 (2004/07/12)
342                                            formatErr = false;      // 3.6.0.0 (2004/09/24)
343                                            int col = table.getColumnNo( key.substring( 0,sp ),false );
344                                            if( col < 0 ) {
345                                                    // è¶?š«定対策:I 変数で、行番号をå?力するã?
346                                                    if( "I".equals( key.substring( 0,sp ) ) ) {
347                                                            return String.valueOf( realRow+1 );             // 行番号は物ç�?¡Œ+ï¼?
348                                                    }
349                                                    else {
350                                                            String errMsg = "カラãƒ?��が存在しません:[" + key + "]" ;
351                                                            System.out.println( errMsg );
352                                                            LogWriter.log( errMsg );
353                                                            return "" ;
354                                                    }
355                                            }
356    
357                                            String val = table.getValue( realRow,col );
358    
359                                            // 3.7.0.1 (2005/01/31) ペã?ジブレイク時ã?処ç�?¿½åŠ?
360                                            if( pbClmNo == col ) {
361                                                    if( ! rowOver ) {
362                                                            String val2 = table.getValue( realRow+1,pbClmNo );      // 先読み
363                                                            if( val != null && ! val.equals( val2 ) ) {
364                                                                    pageBreak = true;
365                                                            }
366                                                    }
367                                                    return "";      // ペã?ジブレイクカラãƒ??、すべて""に変換するã€?
368                                            }
369                                            // 3.7.1.1 (2005/05/09) セルå†??改è¡?<br> は、エスケープしなã�??
370                                            val = StringUtil.htmlFilter( val );
371                                            val = StringUtil.replace( val,"&lt;br&gt;","<br>" );
372                                            // 3.8.0.0 (2005/06/07) Shift-JIS で中国語を扱ã�??(Unicodeエスケープ文字ã?、エスケープしなã�?
373                                            val = StringUtil.replace( val,"&amp;#","&#" );  // 中国語変換対å¿?&amp;# は変換しなã�?
374                                            return table.getDBColumn( col ).getRendererValue( val );
375                                    }
376                            }
377                            catch ( NumberFormatException ex ) {    // 4.0.0 (2005/01/31)
378                                    String errMsg = "警告:ã?ãƒ?ƒ€ーに'_'カラãƒ?��が使用  "
379                                                            + "key=[" + key + "]  "
380                                                            + ex.getMessage() ;
381                                    LogWriter.log( errMsg );
382                                    // フォーマットエラーは、何もしなã�??
383                                    // 通常のカラãƒ?��にアンãƒ??バã?が使用されてã�?‚‹可能性があるためã?
384                            }
385                            catch ( RuntimeException ex ) {
386                                    String errMsg = "カラãƒ?ƒ‡ータ取得å?ç�?�§、エラーが発生しましたã€? "
387                                                            + "key=[" + key + "]  "
388                                                            + ex.getMessage() ;
389                                    LogWriter.log( errMsg );
390                                    // フォーマットエラーは、何もしなã�??
391                            }
392                    }
393    
394                    // 3.8.5.1 (2006/04/28) YKNO を特別扱ã�?�™るã?
395                    if( "YKNO".equals( key ) ) { return ykno; }
396    
397                    String rtnVal ;
398                    if( rowOver ) { rtnVal = getFooterValue( key ); }
399                    else          { rtnVal = getHeaderValue( key ); }
400    
401                    if( rtnVal == null ) { rtnVal = ""; }
402                    return rtnVal ;
403            }
404    
405            /**
406             * 固定部のkey に対応するå?を取得しますã?
407             *
408             * @param   key String
409             *
410             * @return   固定部の値
411             */
412            private String getHeaderValue( final String key ) {
413                    if( headerKeys == null ||
414                            headerVals == null ||
415                            key        == null ) { return null; }
416    
417                    for( int i=0; i<headerKeys.length; i++ ) {
418                            if( key.equals( headerKeys[i] ) ) { return headerVals[i]; }
419                    }
420                    return null;
421            }
422    
423            /**
424             * 繰り返し部の終äº?¾Œに表示する key 部åˆ?‚’æŒ?®šしますã?
425             * カンマでè¤?•°æŒ?®šできますã?
426             *
427             * @og.rev 3.5.6.0 (2004/06/18) 配å?の設定ã?、arraycopy して取り込みますã?
428             *
429             * @param   fKeys 繰り返し部の終äº?¾Œに表示する key
430             */
431            public void setFooterKeys( final String[] fKeys ) {
432                    if( fKeys != null ) {
433                            int size = fKeys.length ;
434                            footerKeys = new String[size];
435                            System.arraycopy( fKeys,0,footerKeys,0,size );
436                    }
437                    else {
438                            footerKeys = null;
439                    }
440            }
441    
442            /**
443             * 繰り返し部の終äº?¾Œに表示する key 部åˆ?‚’取得しますã?
444             *
445             * @param   key String
446             *
447             * @return   繰り返し部の終äº?¾Œに表示する key
448             */
449            private String getFooterValue( final String key ) {
450                    if( footerKeys == null ||
451                            footerVals == null ||
452                            key        == null ) { return null; }
453    
454                    for( int i=0; i<footerKeys.length; i++ ) {
455                            if( key.equals( footerKeys[i] ) ) { return footerVals[i]; }
456                    }
457                    return null;
458            }
459    
460            /**
461             * 固定部のkey に対応するå?を指定しますã?
462             * カンマでè¤?•°æŒ?®šで、リクエスト情報でも設定できますã?
463             *
464             * @og.rev 3.5.6.0 (2004/06/18) 配å?の設定ã?、arraycopy して取り込みますã?
465             *
466             * @param   fVals 繰り返し部の終äº?¾Œに表示する値
467             */
468            public void setFooterVals( final String[] fVals ) {
469                    if( fVals != null ) {
470                            int size = fVals.length ;
471                            footerVals = new String[size];
472                            System.arraycopy( fVals,0,footerVals,0,size );
473                    }
474                    else {
475                            footerVals = null;
476                    }
477            }
478    
479            /**
480             * ボディー部(繰り返し部)がなくなったときに、それ以降を表示するかどã�?�‹を指定しますã?
481             * true では、それ以降を出力しませんã€?
482             * ãƒ?ƒ•ォルãƒ?"true" (なくなった時点で、å?力しなã�??)ですã?
483             *
484             * @param   pageEndCut 繰り返し部の終äº?¾Œに継続å?ç�?�™るかどã�?�‹ (true:処ç�?�—なã�?false:処ç�?�™ã‚?
485             */
486            public void setPageEndCut( final boolean pageEndCut ) {
487                    this.pageEndCut = pageEndCut ;
488            }
489    
490            /**
491             * BufferedReader をã?初期化しますã?
492             * これはã€?››型ファイルの終端まで読取り、å?ç�?�—たå?合ã?もうä¸?º¦
493             * 初めから読み込みなおす処ç�?‚’行いますã?
494             * 基本çš?�«、書き込みもå?期化するå¿?¦�がありますã?
495             *
496             * メモリ上に読み込んで、繰り返し利用するかどã�?�‹は、実è£?¾�存ですã?
497             *
498             * @og.rev 3.1.3.0 (2003/04/10) "DEFAULT" エンコーãƒ?‚£ング名ã?サポã?トをå»?­¢ã€?
499             * @og.rev 3.5.5.9 (2004/06/07) FileUtil.getBufferedReader を使用
500             * @og.rev 3.6.0.0 (2004/09/17) æœ??のペã?ジのみに使用する雛型ファイル名を追åŠ?�—ますã?
501             * @og.rev 3.6.0.0 (2004/09/24) フォーマットエラーの判å®?formatErr)をã?子クラスから移動しますã?
502             *
503             */
504            protected void initReader() {
505                    Closer.ioClose( reader );               // 4.0.0 (2006/01/31) close 処ç�?™‚の IOException を無è¦?
506    
507                    if( reader == null && firstTemplateFile != null ) {
508                            reader = FileUtil.getBufferedReader(firstTemplateFile,ENCODE);
509                    }
510                    else {
511                            if( formatErr ) {
512                                    String errMsg = "Error in HTML File. " + HybsSystem.CR
513                                                                    + "Excel containing two or more sheets is not supporting."
514                                                                    + HybsSystem.CR
515                                                                    + "or HTML template File is not in '{@xxxx_0}' key word." ;
516                                    throw new HybsSystemException( errMsg );
517                            }
518                            reader = FileUtil.getBufferedReader(templateFile,ENCODE);
519                            formatErr = true;               // 初期化しますã?クリアしなければエラー
520                    }
521            }
522    
523            /**
524             * PrintWriter をã?初期化しますã?
525             * これはã€?››型ファイルを終端まで読取り、å?ç�?�—たå?合ã?出力ファイル名を
526             * 変えて、別ファイルとして出力する為のもã?ですã?
527             * 基本çš?�«、読取も初期化するå¿?¦�がありますã?
528             *
529             * メモリ上に読み込んで、繰り返し利用するかどã�?�‹は、実è£?¾�存ですã?
530             *
531             * @og.rev 3.0.0.1 (2003/02/14) ペã?ジのæœ?¤§ペã?ジ数の制限を追åŠ??暴走停止用
532             * @og.rev 3.1.3.0 (2003/04/10) "DEFAULT" エンコーãƒ?‚£ング名ã?サポã?トをå»?­¢ã€?
533             * @og.rev 3.5.5.9 (2004/06/07) FileUtil.getPrintWriter メソãƒ?ƒ‰を使用
534             * @og.rev 3.7.0.1 (2005/01/31) ペã?ジブレイク処ç�?�«対応ã?
535             * @og.rev 3.8.0.0 (2005/06/07) FileUtil#getPrintWriter を利用ã€?
536             * @og.rev 3.8.5.3 (2006/06/30) EXCELæœ?¤§シート数のエラーメãƒ?‚»ージを変更ã€?
537             *
538             */
539            protected void initWriter() {
540                    if( writer != null ) {
541                            writer.flush();
542                            writer.close();
543                            writer = null;
544                            pageCount++ ;
545                            if( pageCount >= maxPageCount ) {
546                                    String errMsg = "EXCELのペã?ジ(シーãƒ?が最大ペã?ジ数(1000)をオーバã?しましたã€?
547                                                                    + HybsSystem.CR
548                                                                    + "こã?数は、DB_MAX_ROW_COUNT ではなくã?LISTID_999.htmlのオーバã?を意味しますã?"
549                                                                    + HybsSystem.CR;
550                                    throw new HybsSystemException( errMsg );
551                            }
552                    }
553    
554                    int pgCnt = pageCount + 1000;           // 桁合わせの為、下3桁を利用しますã?
555    
556                    String subName = String.valueOf( pgCnt ).substring( 1 );
557                    String filename = htmlFileKey + "_" + subName + ".html" ;
558    
559                    // 3.8.0.0 (2005/06/07) FileUtil#getPrintWriter を利用ã€?
560                    writer = FileUtil.getPrintWriter( new File( htmlDir,filename ),ENCODE );
561    
562                    // 3.7.0.1 (2005/01/31) ペã?ジブレイク時ã?処ç�?
563                    pageRowCount = maxRowCount ;    // そã?ペã?ジの頭のãƒ??タ行数をセãƒ?ƒˆ
564                    pageBreak    = false;                   // pageBreak フラグをå?に戻すã?
565            }
566    
567            /**
568             * ヘッãƒ??フッターのレンãƒ?ƒ©ーãƒ??タを設定しますã?
569             * カンマでè¤?•°æŒ?®šで、リクエスト情報でも設定できますã?
570             *
571             */
572            protected void setHeaderFooter() {
573    
574                    DBColumn clm ;
575                    if( headerKeys != null ) {
576                            for( int i=0; i<headerKeys.length; i++ ) {
577                                    clm = resource.getDBColumn( headerKeys[i] );
578                                    if( clm != null ) {
579                                            headerVals[i] = clm.getRendererValue( headerVals[i] );
580                                    }
581                            }
582                    }
583    
584                    if( footerKeys != null ) {
585                            for( int i=0; i<footerKeys.length; i++ ) {
586                                    clm = resource.getDBColumn( footerKeys[i] );
587                                    if( clm != null ) {
588                                            footerVals[i] = clm.getRendererValue( footerVals[i] );
589                                    }
590                            }
591                    }
592            }
593    
594            /**
595             * リーãƒ??、ライターの終äº??ç�?‚’行いますã?
596             *
597             */
598            private void close() {
599                    if( writer != null ) {
600                            writer.flush();
601                            writer.close();
602                            writer = null;
603                    }
604                    Closer.ioClose( reader );               // 4.0.0 (2006/01/31) close 処ç�?™‚の IOException を無è¦?
605                    reader = null;
606            }
607    }