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.common.HybsSystemException;
020import org.opengion.hayabusa.db.DBTableModel;
021import org.opengion.hayabusa.report.DBTableReport;
022import org.opengion.fukurou.util.FileUtil;
023import org.opengion.fukurou.util.Shell;
024
025import org.opengion.fukurou.util.StringUtil ;
026import static org.opengion.fukurou.util.StringUtil.nval ;
027
028import java.io.File;
029import java.io.IOException;
030import java.io.ObjectOutputStream;
031import java.io.ObjectInputStream;
032
033/**
034 * 検索結果の DBTableModelオブジェクトをレポート形式に変換するタグです。
035 *
036 * データ(DBTableModel)と、コントローラ(DBTableReport クラス)を与えて、
037 * 外部からコントロールすることで、各種形式で データ(DBTableModel)を表示させることが
038 * 可能です。
039 *
040 * @og.formSample
041 * ●形式:<og:report fileURL="[・・・]" listId="[・・・]" ・・・ />
042 * ●body:なし
043 *
044 * ●Tag定義:
045 *   <og:report
046 *       listId           ○【TAG】帳票IDを指定します(必須)。
047 *       fileURL            【TAG】雛型のHTMLファイルの保存してある ディレクトリを指定します
048 *       programFile        【TAG】HTMLファイルをEXCEL変換する場合に使用するBATファイルを指定します
049 *       outFileURL         【TAG】出力HTMLファイルの保存してあるディレクトリを指定します
050 *       outFilename      ○【TAG】ファイルを作成するときの出力ファイル名をセットします(必須)。
051 *       headerKeys         【TAG】固定部の{@KEY} の KEY 部分をCSV形式で複数指定します
052 *       headerVals         【TAG】固定部のKEY に対応する値をCSV形式で複数指定します
053 *       footerKeys         【TAG】繰り返し部の終了後に表示する key 部分をCSV形式で複数指定します
054 *       footerVals         【TAG】固定部のKEY に対応する値をCSV形式で複数指定します
055 *       pageEndCut         【TAG】ボディー部(繰り返し部)がなくなったときに、それ以降を表示するかどうか[true/false]を指定します(初期値:true)
056 *       reportClass        【TAG】実際に書き出すクラス名の略称(DBTableReport_**** の ****)をセットします(初期値:HTML)
057 *       language           【TAG】タグ内部で使用する言語コード[ja/en/zh/…]を指定します
058 *       scope              【TAG】キャッシュする場合のスコープ[request/page/session/applicaton]を指定します(初期値:session)
059 *       tableId            【TAG】(通常使いません)sessionから所得する DBTableModelオブジェクトの ID
060 *       debug              【TAG】デバッグ情報を出力するかどうか[true/false]を指定します(初期値:false)
061 *   />
062 *
063 * ●使用例
064 *
065 * @og.group その他出力
066 *
067 * @version  4.0
068 * @author   Kazuhiko Hasegawa
069 * @since    JDK5.0,
070 */
071public class ReportTableTag extends CommonTagSupport {
072        //* このプログラムのVERSION文字列を設定します。   {@value} */
073        private static final String VERSION = "4.0.0.0 (2007/11/28)" ;
074
075        private static final long serialVersionUID = 400020071128L ;    // 4.0.0.0 (2007/11/28)
076
077        // 印刷時に使用するテンポラリフォルダ名
078        private final String REPORT_URL =
079                nval( HybsSystem.sys( "REPORT_FILE_URL" ) ,
080                                 HybsSystem.sys( "FILE_URL" ) + "REPORT/" ) ;
081
082        // 3.8.0.4 (2005/08/08) 印刷時に使用するシステムID
083        private static final String SYSTEM_ID =HybsSystem.sys( "SYSTEM_ID" );
084
085        // 3.8.0.4 (2005/08/08) 帳票出力に準拠した方式に変更
086        private final int TIMEOUT = HybsSystem.sysInt( "REPORT_DAEMON_TIMEOUT" );
087
088        private final String  BASE_URL  = HybsSystem.sys( "FILE_URL" );
089
090        private String[]  headerKeys    = null;   // 固定部の{@KEY} の KEY 部分を指定する。カンマで複数指定できる。
091        private String[]  headerVals    = null;   // 固定部のKEY に対応する値を指定する。 {@KEY} に置き換わる。
092        private String[]  footerKeys    = null;   // 繰り返し部の終了後に表示する key 部分を指定する。カンマで複数指定できる。
093        private String[]  footerVals    = null;   // 繰り返し部の終了後に表示する key に対する値を指定する。
094        private boolean   pageEndCut    = true;   // ボディー部(繰り返し部)がなくなったときに、それ以降のページを出力するか指定する。
095        private String    fileURL               = BASE_URL;             // 雛型のHTMLファイルの保存してある ディレクトリを指定します。
096        private String    outFileURL    = BASE_URL;             // 出力HTMLファイルの保存してある ディレクトリを指定します。
097        private String    outFilename   = null;                 // 出力HTMLファイル名を指定します。 ディレクトリ名を含んでも構いません。
098        private String    reportClass   = "HTML";
099
100        private transient DBTableModel table    = null;
101        private String  tableId                 = HybsSystem.TBL_MDL_KEY ;
102        // 3.8.0.4 (2005/08/08) 帳票出力に準拠した方式に変更
103        private String  listId                  = null ;        // 雛型のHTMLファイル名を指定します。
104        private String  programFile             = null;         // HTMLファイルのEXCEL化を行うバッチファイルを指定します。
105//      private boolean direct                  = false;
106//      private static final String             disposition = "inline"; // 固定
107
108        /**
109         * Taglibの終了タグが見つかったときに処理する doEndTag() を オーバーライドします。
110         *
111         * @og.rev 3.1.1.2 (2003/04/04) Tomcat4.1 対応。release2() を doEndTag()で呼ぶ。
112         * @og.rev 3.8.0.4 (2005/08/08) 帳票出力に準拠した方式に変更
113         * @og.rev 4.0.0.0 (2007/10/18) メッセージリソース統合( getResource().getMessage ⇒ getResource().getLabel )
114         * @og.rev 4.0.0.0 (2007/11/28) メソッドの戻り値をチェックします。
115         *
116         * @return      後続処理の指示
117         */
118        @Override
119        public int doEndTag() {
120                debugPrint();
121
122//              int rtnCode = EVAL_PAGE;
123                final int rtnCode;
124
125                table = (DBTableModel)getObject( tableId );
126                if( table == null || table.getRowCount() == 0 ) {
127                        rtnCode = SKIP_PAGE ;           // ページの残りの処理を行わない。
128                }
129                else {
130
131//                      try {
132
133                                synchronized( ReportTableTag.class ) {
134                                        String reportDir  = HybsSystem.url2dir( REPORT_URL ) + SYSTEM_ID + HybsSystem.FS + listId ;
135                        //              String ykno       = HybsSystem.getDate( "yyyyMMddHHmmss" );
136                                        String ykno       = String.valueOf( Math.round( Math.random() * 1000000 ) ) ;
137
138                                        create( reportDir,ykno ) ;
139
140                                        // 処理クラス(reportClass)が HTML の場合は、Shell を起動して、VBS で EXCEL化が必要。
141                                        if( programFile != null && "HTML".equalsIgnoreCase( reportClass ) ) {
142                                                String htmlFile = reportDir + HybsSystem.FS + ykno ;
143                                                String cmd = makeShellCommand( htmlFile,listId );
144                                                programRun( cmd );
145                                        }
146
147                                        if( outFilename != null ) {
148                                                File xlsFile = new File( reportDir,ykno + ".xls" );
149                                                File outDir  = new File( HybsSystem.url2dir( outFileURL ) );
150//                                              if( !outDir.exists() ) { outDir.mkdirs(); }
151                                                if( !outDir.exists() && !outDir.mkdirs() ) {
152                                                        String errMsg = "所定のフォルダを作成できませんでした。[" + outDir + "]" ;
153                                                        throw new RuntimeException( errMsg );
154                                                }
155                                                File outFile = new File( outDir,outFilename );
156                //                              File outFile = new File( outFileURL,outFilename );
157                                                FileUtil.copy(  xlsFile , outFile );
158
159//                                              String msg = getResource().getMessage( "MSG0003" )              // MSG0003=ファイルの登録が完了しました。
160                                                String msg = getResource().getLabel( "MSG0003" )                // MSG0003=ファイルの登録が完了しました。
161                                                                        + HybsSystem.BR
162//                                                                      + getResource().getMessage( "MSG0022" )         // MSG0022=ファイル名
163                                                                        + getResource().getLabel( "MSG0022" )   // MSG0022=ファイル名
164                                                                        + ":" + outFile.getAbsolutePath() ;
165                                                jspPrint( msg );
166
167//                                              if( direct ) {
168//                                                      directLoad( outFile.getAbsolutePath(),outFilename );
169//                                                      directLoad( xlsFile.getAbsolutePath(),outFilename );
170//                                              }
171                                        }
172//                                      else {
173//                                              String redirectUrl = StringUtil.urlAppend( sys( "CONTEXT_URL" ),
174//                                                                                              REPORT_URL + SYSTEM_ID + "/" +
175//                                                                                              listId + "/" + ykno + ".xls" ) ;
176//                                              HttpServletResponse response = (HttpServletResponse)pageContext.getResponse();
177//                                              response.sendRedirect( response.encodeRedirectURL( redirectUrl ) );
178//                                      }
179                                }
180//                      }
181//                      catch(IOException ex) {
182//                              String errMsg = "Error in ReportTableTag: " + toString();
183//                              throw new HybsSystemException( errMsg,ex );             // 3.5.5.4 (2004/04/15) 引数の並び順変更
184//                      }
185                        rtnCode = EVAL_PAGE ;
186                }
187
188                return( rtnCode );
189        }
190
191        /**
192         * タグリブオブジェクトをリリースします。
193         * キャッシュされて再利用されるので、フィールドの初期設定を行います。
194         *
195         * @og.rev 2.0.0.4 (2002/09/27) カスタムタグの release() メソッドを、追加
196         * @og.rev 3.1.1.2 (2003/04/04) Tomcat4.1 対応。release2() を doEndTag()で呼ぶ。
197         * @og.rev 3.1.3.0 (2003/04/10) REPORT_ENCODE(帳票エンコーディング)を利用するように修正。
198         * @og.rev 3.8.0.4 (2005/08/08) filename 削除、listId ,programFile 追加 ,
199         *
200         */
201        @Override
202        protected void release2() {
203                super.release2();
204                headerKeys              = null;
205                headerVals              = null;
206                footerKeys              = null;
207                footerVals              = null;
208                pageEndCut              = true;
209                fileURL                 = BASE_URL;
210                outFileURL              = BASE_URL;
211                outFilename             = null;                 // 出力ファイル名
212                reportClass             = "HTML";
213                table                   = null;
214                tableId                 = HybsSystem.TBL_MDL_KEY ;
215                listId                  = null ;                // 3.8.0.4 (2005/08/08)
216                programFile             = null ;                // 3.8.0.4 (2005/08/08)
217//              direct                  = false;
218        }
219
220        /**
221         * TableWriter の実オブジェクトを生成して,PrintWriter に書き込みます。
222         *
223         * @og.rev 3.1.3.0 (2003/04/10) REPORT_ENCODE(帳票エンコーディング)を利用するように修正。
224         * @og.rev 3.5.4.3 (2004/01/05) HTMLDBTableReport のクラス名変更。
225         * @og.rev 3.6.0.0 (2004/09/17) メソッド名の変更。setInputFile ⇒ setTemplateFile
226         * @og.rev 3.8.0.0 (2005/06/07) setTemplateFile メソッドの引数を String  ⇒ File に変更
227         * @og.rev 3.8.0.4 (2005/08/08) 帳票出力に準拠した方式に変更
228         * @og.rev 4.0.0.0 (2005/01/31) lang ⇒ ResourceManager へ変更
229         *
230         * @param       reportDir       出力ディレクトリ名
231         * @param       ykno            要求番号
232         */
233        private void create( final String reportDir,final String ykno )  {
234
235                String className = "org.opengion.hayabusa.report.DBTableReport_" + reportClass  ;
236                DBTableReport report = (DBTableReport)HybsSystem.newInstance( className );      // 3.5.5.3 (2004/04/09)
237
238                String MODELDIR = HybsSystem.url2dir( fileURL ) ;
239
240                File templateFile      = null;
241                File firstTemplateFile = null;
242
243                // 本来は、各クラス中で処理すべき。そのためのオブジェクト指向なのだから。
244                if( "HTML".equalsIgnoreCase( reportClass ) ) {
245                        templateFile      = FileUtil.checkFile( MODELDIR, listId + ".html" , 1 );
246                        firstTemplateFile = FileUtil.checkFile( MODELDIR, listId + "_FIRST.html" ,1 );
247                }
248                else if( "Excel".equalsIgnoreCase( reportClass ) ) {
249                        templateFile      = FileUtil.checkFile( MODELDIR, listId + ".xls" , 1 );
250                }
251                else {
252                        String errMsg = "リポートクラスがサポート外です。[" + reportClass + "]"
253                                                + "クラスは、HTML、Excel のみサポートされています。" ;
254                        throw new RuntimeException( errMsg );
255                }
256
257                FileUtil.copy( templateFile,new File( reportDir ) );
258
259                report.setDBTableModel( table );
260                report.setTemplateFile( templateFile ); // 3.6.0.0 (2004/09/17)
261                report.setFirstTemplateFile( firstTemplateFile );       // 3.6.0.0 (2004/09/17)
262                report.setOutputDir( reportDir );
263                report.setOutputFileKey( ykno );
264                report.setHeaderKeys( headerKeys );
265                report.setHeaderVals( headerVals );
266                report.setFooterKeys( footerKeys );
267                report.setFooterVals( footerVals );
268                report.setPageEndCut( pageEndCut );
269                report.setResourceManager( getResource() );     // 4.0.0 (2005/01/31)
270                report.setListId( listId );             // 3.6.1.0 (2005/01/05)
271                report.writeReport();
272        }
273
274        /**
275         * 【TAG】(通常は使いません)結果のDBTableModelを、sessionに登録するときのキーを指定します
276         *              (初期値:HybsSystem#TBL_MDL_KEY[={@og.value org.opengion.hayabusa.common.HybsSystem#TBL_MDL_KEY}])。
277         *
278         * @og.tag
279         * 検索結果より、DBTableModelオブジェクトを作成します。これを、下流のviewタグ等に
280         * 渡す場合に、通常は、session を利用します。その場合の登録キーです。
281         * query タグを同時に実行して、結果を求める場合、同一メモリに配置される為、
282         * この tableId 属性を利用して、メモリ空間を分けます。
283         *              (初期値:HybsSystem#TBL_MDL_KEY[={@og.value org.opengion.hayabusa.common.HybsSystem#TBL_MDL_KEY}])。
284         *
285         * @param       id sessionに登録する時の ID
286         */
287        public void setTableId( final String id ) {
288                tableId = nval( getRequestParameter( id ), tableId );
289        }
290
291        /**
292         * 【TAG】帳票IDを指定します。
293         *
294         * @og.tag
295         * 雛形ファイルは、帳票ID.html となります。また、ファーストページ対応の場合は、
296         * 帳票ID_FIRST.html になります。
297         * なお、filename 属性が指定された場合は、そちらが優先されます。
298         *
299         * @og.rev 3.8.0.4 (2005/08/08) 新規追加
300         *
301         * @param       listId  帳票ID
302         */
303        public void setListId( final String listId ) {
304                this.listId = nval( getRequestParameter( listId ), this.listId );
305        }
306
307        /**
308         * 【TAG】固定部の{@KEY} の KEY 部分をCSV形式で複数指定します。
309         *
310         * @og.tag
311         * カンマで複数指定できます。
312         * 分解方法は、CSV変数を先に分解してから、getRequestParameter で値を取得します。
313         * こうしないとデータ自身にカンマを持っている場合に分解をミスる為です。
314         *
315         * @og.rev 3.5.6.2 (2004/07/05) 先に配列に分解してからリクエスト変数の値を取得
316         *
317         * @param   hKeys 固定部の key
318         */
319        public void setHeaderKeys( final String hKeys ) {
320                headerKeys = getCSVParameter( hKeys );
321        }
322
323        /**
324         * 【TAG】固定部のKEY に対応する値をCSV形式で複数指定します。
325         *
326         * @og.tag
327         * カンマで複数指定で、リクエスト情報でも設定できます。
328         * 分解方法は、CSV変数を先に分解してから、getRequestParameter で値を取得します。
329         * こうしないとデータ自身にカンマを持っている場合に分解をミスる為です。
330         *
331         * @og.rev 3.5.6.2 (2004/07/05) 先に配列に分解してからリクエスト変数の値を取得
332         *
333         * @param   hVals 固定部の値
334         */
335        public void setHeaderVals( final String hVals ) {
336                headerVals = getCSVParameter( hVals );
337        }
338
339        /**
340         * 【TAG】繰り返し部の終了後に表示する key 部分をCSV形式で複数指定します。
341         *
342         * @og.tag
343         * カンマで複数指定できます。
344         * 分解方法は、CSV変数を先に分解してから、getRequestParameter で値を取得します。
345         * こうしないとデータ自身にカンマを持っている場合に分解をミスる為です。
346         *
347         * @og.rev 3.5.6.2 (2004/07/05) 先に配列に分解してからリクエスト変数の値を取得
348         *
349         * @param   ftKeys 繰り返し部の終了後に表示する key
350         */
351        public void setFooterKeys( final String ftKeys ) {
352                footerKeys = getCSVParameter( ftKeys );
353        }
354
355        /**
356         * 【TAG】固定部のKEY に対応する値をCSV形式で複数指定します。
357         *
358         * @og.tag
359         * カンマで複数指定で、リクエスト情報でも設定できます。
360         * 分解方法は、CSV変数を先に分解してから、getRequestParameter で値を取得します。
361         * こうしないとデータ自身にカンマを持っている場合に分解をミスる為です。
362         *
363         * @og.rev 3.5.6.2 (2004/07/05) 先に配列に分解してからリクエスト変数の値を取得
364         * @og.rev 3.8.1.2 (2005/12/19) footer 関連の値とpageEndCut の関係を解除します。
365         *
366         * @param   ftVals 繰り返し部の終了後に表示する値
367         */
368        public void setFooterVals( final String ftVals ) {
369                footerVals = getCSVParameter( ftVals );
370        }
371
372        /**
373         * 【TAG】ボディー部(繰り返し部)がなくなったときに、それ以降を表示するかどうか[true/false]を指定します(初期値:true)。
374         *
375         * @og.tag
376         * true では、それ以降を出力しません。
377         * 初期値は "true" (なくなった時点で、出力しない。)です。
378         *
379         * @og.rev 3.8.1.2 (2005/12/19) footer 関連の値とpageEndCut の関係を解除します。
380         *
381         * @param   peCut 繰り返し部の終了後に継続処理するかどうか (true:処理しない/false:処理する)
382         */
383        public void setPageEndCut( final String peCut ) {
384                pageEndCut = nval( getRequestParameter( peCut ),pageEndCut );
385        }
386
387        /**
388         * 【TAG】雛型のHTMLファイルの保存してある ディレクトリを指定します。
389         *
390         * @og.tag
391         * この属性で指定されるディレクトリのファイルを読み取ります。
392         * 指定方法は、通常の fileURL 属性と同様に、先頭が、'/' (UNIX) または、2文字目が、
393         * ":" (Windows)の場合は、指定のURLそのままのディレクトリに、そうでない場合は、
394         * システムパラメータ の FILE_URL 属性で指定のフォルダの下に、作成されます。
395         * fileURL = "{@USER.ID}" と指定すると、FILE_URL 属性で指定のフォルダの下に、
396         * さらに、各個人ID別のフォルダを作成して、そこを操作します。
397         *
398         * @og.rev 4.0.0.0 (2005/01/31) StringUtil.urlAppend メソッドの利用
399         * @og.rev 4.0.0.0 (2007/11/20) 指定されたディレクトリ名の最後が"\"or"/"で終わっていない場合に、"/"を付加する。
400         *
401         * @param       url 雛型のHTMLファイルのディレクトリ
402         */
403        public void setFileURL( final String url ) {
404                String furl = nval( getRequestParameter( url ),null );
405                if( furl != null ) {
406                        char ch = furl.charAt( furl.length()-1 );
407                        if( ch != '/' && ch != '\\' ) { furl = furl + "/"; }
408                        fileURL = StringUtil.urlAppend( fileURL,furl );
409                }
410        }
411
412        /**
413         * 【TAG】HTMLファイルをEXCEL変換する場合に使用するBATファイルを指定します。
414         *
415         * @og.tag
416         * ファイルは、フルパスで指定してください。
417         * 指定がない場合は、変換処理は行いません。
418         * 通常は、dbdef2/def/Script/runExcelPrint.bat を呼び出してください。
419         * 初期値は、null(変換処理しない)です。
420         *
421         * @og.rev 3.8.0.4 (2005/08/08) 新規追加
422         *
423         * @param   programFile プログラムファイル名
424         */
425        public void setProgramFile( final String programFile ) {
426                this.programFile = nval( getRequestParameter( programFile ),this.programFile );
427        }
428
429        /**
430         * 【TAG】出力HTMLファイルの保存してあるディレクトリを指定します。
431         *
432         * @og.tag
433         * この属性で指定されるディレクトリにファイルを出力します。
434         * 指定方法は、通常の fileURL 属性と同様に、先頭が、'/' (UNIX) または、2文字目が、
435         * ":" (Windows)の場合は、指定のURLそのままのディレクトリに、そうでない場合は、
436         * システムパラメータ の FILE_URL 属性で指定のフォルダの下に、作成されます。
437         * fileURL = "{@USER.ID}" と指定すると、FILE_URL 属性で指定のフォルダの下に、
438         * さらに、各個人ID別のフォルダを作成して、そこに出力します。
439         *
440         * @og.rev 4.0.0.0 (2007/11/20) 指定されたディレクトリ名の最後が"\"or"/"で終わっていない場合に、"/"を付加する。
441         *
442         * @param       url 出力HTMLファイルのディレクトリ
443         */
444        public void setOutFileURL( final String url ) {
445                String furl = nval( getRequestParameter( url ),null );
446                if( furl != null ) {
447                        char ch = furl.charAt( furl.length()-1 );
448                        if( ch != '/' && ch != '\\' ) { furl = furl + "/"; }
449                        outFileURL = StringUtil.urlAppend( outFileURL,furl );
450                }
451        }
452
453        /**
454         * 【TAG】ファイルを作成するときの出力ファイル名をセットします。
455         *
456         * @og.tag ファイルを作成するときの出力ファイル名をセットします。
457         *
458         * @param   filename 出力ファイル名
459         */
460        public void setOutFilename( final String filename ) {
461                this.outFilename = nval( getRequestParameter( filename ),this.outFilename );
462        }
463
464        /**
465         * 【TAG】実際に書き出すクラス名の略称(DBTableReport_**** の ****)をセットします(初期値:HTML)。
466         *
467         * @og.tag
468         * これは、org.opengion.hayabusa.report 以下の DBTableReport_**** クラスの **** を
469         * 与えます。これらは、DBTableReport インターフェースを継承したサブクラスです。
470         * 初期値は、"HTML" です。
471         * 属性クラス定義の {@link org.opengion.hayabusa.report.DBTableReport DBTableReport} を参照願います。
472         *
473         * @param   reportClass クラス名(の略称)
474         * @see         org.opengion.hayabusa.report.DBTableReport  DBTableReportのサブクラス
475         */
476        public void setReportClass( final String reportClass ) {
477                this.reportClass = nval( getRequestParameter( reportClass ),this.reportClass );
478        }
479
480        /**
481         * 【TAG】結果をダイレクトにEXCEL起動するかどうか[true/false]を指定します(初期値:false[ファイル])。
482         *
483         * @og.tag 結果をダイレクトに EXCEL ファイルとして出力するかどうかをセットします。
484         *
485         * @param  flag ダイレクト(true)/ ファイル(その他)
486         */
487//      public void setDirect( final String flag ) {
488//              direct = nval( getRequestParameter( flag ),direct );
489//      }
490
491        /**
492         * シェルコマンドの文字列を作成します。
493         *
494         * 処理クラス(reportClass)が HTML の場合は、Shell を起動して、VBS で EXCEL化が必要。
495         *
496         * @og.rev 3.8.0.4 (2005/08/08) 新規追加
497         * @og.rev 3.8.0.8 (2005/10/03) デーモングループのデフォルト値設定
498         *
499         * @param       htmlFile        パーサ済みのHTMLファイル(拡張子なし)
500         * @param       listId  雛形ファイル(帳票ID)
501         *
502         * @return シェルコマンドの文字列
503         */
504        private String makeShellCommand( final String htmlFile,final String listId ) {
505                StringBuilder buf = new StringBuilder( HybsSystem.BUFFER_SMALL );
506
507                buf.append( programFile ).append( " " );                // 実行するコマンド
508                buf.append( "\"" );
509                buf.append( htmlFile ).append( "_*.html\" " );  // 入力HTMLファイル
510                buf.append( "\"xls\" " );                                               // プリンタ名
511                // ダミーファイルを指定する必要がある。
512                buf.append( "\"" );
513                buf.append( htmlFile ).append( ".xls\" " );             // ダミー出力ファイル
514                buf.append( listId );                                                   // モデルファイル名
515                buf.append( " NULL" );                                                  // ダミーデーモングループ
516
517                return buf.toString();
518        }
519
520        /**
521         * 実際のレポート出力処理を行います。
522         *
523         * 処理クラス(reportClass)が HTML の場合は、Shell を起動して、VBS で EXCEL化が必要。
524         *
525         * @og.rev 3.8.0.4 (2005/08/08) 新規追加
526         *
527         * @param       shellCmd        シェルを実行するコマンド文字列
528         */
529        private void programRun( final String shellCmd ) {
530                Shell shell = new Shell();
531                shell.setCommand( shellCmd,true );              // BATCHプロセスで実行する
532                shell.setWait( true );                                  // プロセスの終了を待つ
533                shell.setTimeout( TIMEOUT );                    // 3.6.1.0 (2005/01/05) Shell の タイムアウトを設定
534
535                int rtnCode = shell.exec();                             // 0 は正常終了を示す
536
537                if( rtnCode != 0 ) {
538                        String errMsg = "Shell Command exequte Error." + HybsSystem.CR
539                                                + "=============================="
540                                                + shellCmd + HybsSystem.CR
541                                                + shell.getStdoutData() + HybsSystem.CR
542                                                + shell.getStderrData() + HybsSystem.CR ;
543                        throw new HybsSystemException( errMsg );                // 3.5.5.4 (2004/04/15) 引数の並び順変更
544                }
545        }
546
547        /**
548         * Excel ファイルをダイレクトで返す forward 処理を行います。
549         *
550         * @og.rev 4.0.0.0 (2007/06/11) 新規追加
551         *
552         * @param       fwdUrl  実際に転送するファイルアドレス
553         * @param       fname   転送で返すファイル名
554         */
555//      private void directLoad( final String fwdUrl,final String fname ) {
556//              HttpServletResponse response = (HttpServletResponse)pageContext.getResponse();
557//
558//              try {
559//                      String url = response.encodeRedirectURL( fwdUrl );      // 3.5.4.9 (2004/02/25)
560//                      String filename = StringUtil.urlEncode( fname );
561//
562//                      (response).setHeader( "Content-Disposition",disposition + "; filename=\"" + filename + "\"" );
563//                      response.sendRedirect( url );
564//      //              pageContext.forward( url );
565//              } catch(IOException ex) {
566//                      String errMsg = "フォワードでIOエラーが発生しました。" + toString();
567//                      throw new HybsSystemException( errMsg,ex );
568////            } catch( ServletException ex) {
569////                    String errMsg = "フォワードでServletエラーが発生しました。" + toString();
570////                    throw new HybsSystemException( errMsg,ex );
571//              }
572//      }
573
574        /**
575         * タグの名称を、返します。
576         * 自分自身のクラス名より、自動的に取り出せないため、このメソッドをオーバーライドします。
577         *
578         * @og.rev 4.0.0.0 (2005/01/31) 新規追加
579         *
580         * @return  タグの名称
581         */
582        @Override
583        protected String getTagName() {
584                return "report" ;
585        }
586
587        /**
588         * シリアライズ用のカスタムシリアライズ書き込みメソッド
589         *
590         * @og.rev 4.0.0.0 (2006/09/31) 新規追加
591         * @serialData 一部のオブジェクトは、シリアライズされません。
592         *
593         * @param       strm    ObjectOutputStreamオブジェクト
594         * @throws IOException  入出力エラーが発生した場合
595         */
596        private void writeObject( final ObjectOutputStream strm ) throws IOException {
597                strm.defaultWriteObject();
598        }
599
600        /**
601         * シリアライズ用のカスタムシリアライズ読み込みメソッド
602         *
603         * ここでは、transient 宣言された内部変数の内、初期化が必要なフィールドのみ設定します。
604         *
605         * @og.rev 4.0.0.0 (2006/09/31) 新規追加
606         * @serialData 一部のオブジェクトは、シリアライズされません。
607         *
608         * @param       strm    ObjectInputStreamオブジェクト
609         * @see #release2()
610         * @throws IOException  シリアライズに関する入出力エラーが発生した場合
611         * @throws ClassNotFoundException       クラスを見つけることができなかった場合
612         */
613        private void readObject( final ObjectInputStream strm ) throws IOException , ClassNotFoundException {
614                strm.defaultReadObject();
615        }
616
617        /**
618         * このオブジェクトの文字列表現を返します。
619         * 基本的にデバッグ目的に使用します。
620         *
621         * @return このクラスの文字列表現
622         */
623        @Override
624        public String toString() {
625                return org.opengion.fukurou.util.ToString.title( this.getClass().getName() )
626                                .println( "VERSION"             ,VERSION        )
627                                .println( "headerKeys"          ,headerKeys             )
628                                .println( "headerVals"          ,headerVals             )
629                                .println( "footerKeys"          ,footerKeys             )
630                                .println( "footerVals"          ,footerVals             )
631                                .println( "pageEndCut"          ,pageEndCut             )
632                                .println( "fileURL"                     ,fileURL                )
633                                .println( "outFileURL"          ,outFileURL             )
634                                .println( "outFilename"         ,outFilename    )
635                                .println( "reportClass"         ,reportClass    )
636                                .println( "tableId"                     ,tableId                )
637                                .println( "listId"                      ,listId                 )
638                                .println( "programFile"         ,programFile    )
639                                .println( "REPORT_FILE_URL"     ,REPORT_URL             )
640                                .println( "SYSTEM_ID"           ,SYSTEM_ID              )
641                                .println( "TIMEOUT"                     ,TIMEOUT                )
642                                .println( "BASE_URL"            ,BASE_URL               )
643                                .println( "Other..."    ,getAttributes().getAttribute() )
644                                .fixForm().toString() ;
645        }
646}