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.report2;
017    
018    import java.io.File;
019    
020    import org.opengion.hayabusa.db.DBTableModel;
021    
022    /**
023     * 帳票処ç�?¦�求を管ç�?�™るキューオブジェクトですã?
024     * こã?オブジェクトでは、帳票の定義及ã?ãƒ??タと、å?ç�?¸­に発生したエラーメãƒ?‚»ージを管ç�?�—ますã?
025     * またã?こã?キューを生成したオブジェクトもこã?オブジェクトにセãƒ?ƒˆされますã?
026     *
027     * @og.group 帳票シスãƒ?ƒ 
028     *
029     * @version  4.0
030     * @author   Hiroki.Nakamura
031     * @since    JDK1.6
032     */
033    public class ExecQueue {
034    
035            /** 実行方æ³?{@value} */
036            protected static final String OUT_ODS_ONLY              = "1";
037            /** 実行方æ³?{@value} */
038            protected static final String OUT_PRINT_ONLY    = "2";
039            /** 実行方æ³?{@value} */
040            protected static final String OUT_ODS_PRINT             = "3";
041            /** 実行方æ³?{@value} */
042            protected static final String OUT_ODS_PDF               = "P";
043            /** 実行方æ³?{@value} */
044            protected static final String OUT_ODS_PRINT_PDF = "Q";
045            /** 実行方æ³?{@value} */
046            protected static final String OUT_ODS_EXCEL             = "E";
047            /** 実行方æ³?{@value} */
048            protected static final String OUT_ODS_ODS               = "S"; // 4.3.3.4 (2008/11/01) 追åŠ?
049            /** 実行方æ³?{@value} */
050            protected static final String IN_INPUT_ONLY             = "5";
051            /** 実行方æ³?{@value} */
052            protected static final String IN_EXEC_ONLY              = "6";
053            /** 実行方æ³?{@value} */
054            protected static final String IN_INPUT_EXEC             = "7";
055            /** 実行方æ³?{@value} */
056            protected static final String RFID_PRINT                = "A";
057            /** 実行方æ³?{@value} */
058            protected static final String RFID_ALLPRINT             = "B";
059            /** 実行方æ³?{@value} */
060            protected static final String RFID_ALLERASE             = "C";
061            /** 実行方æ³?{@value} */
062            protected static final String RFID_SEQERASE             = "D";
063    
064            /** æœ?¤§シート数 {@value} */
065            protected static final int MAX_SHEETS_PER_FILE  = 256; // 5.1.2.0 (2010/01/01)
066    
067            private String          ykno            = null;
068            private String          systemId        = null;
069            private DBTableModel body               = null;
070            private DBTableModel header             = null;
071            private DBTableModel footer             = null;
072            private String          listId          = null;
073            private String          pdfPasswd       = null;
074            private String          lang            = null;
075            private String          threadId        = null;
076            private String          templateName = null;
077            private String          outputType      = null;
078            private String          printerName     = null;
079            private String          outputName      = null;
080            private boolean         fglocal         = false;
081            private boolean         fgcut           = false;
082            private QueueManager manager    = null;
083            private String          prgdir          = null;         // 4.3.3.0 (2008/10/01) 板金RFID対応ã?
084            private String          prgfile         = null;         // 4.3.3.0 (2008/10/01)
085            private String          prtid           = null;         // 4.3.3.0 (2008/10/01)
086    
087            private int                     pageCnt         = 0;            // 5.1.2.0 (2010/01/01) 処ç�?�—たã?ージ数
088            private int                     rowCnt          = 0;            // 5.1.2.0 (2010/01/01) 処ç�?�—た行数
089            private boolean         isDataEnd       = false;        // 5.1.2.0 (2010/01/01) 全ãƒ??タがå?ç�?�•れたã�?(メソãƒ?ƒ‰名と同じ変数名変更)
090    
091            private boolean         useSheetName = false;   // 5.7.6.2 (2014/05/16) PAGEBREAKカラãƒ??値をã?シート名として使ã�?�‹どã�?�‹ã€?
092    
093            private final StringBuilder errMsg = new StringBuilder();
094    
095            /**
096             * 要æ±?Oをセãƒ?ƒˆしますã?
097             *
098             * @param ykno 要æ±?O
099             */
100            public void setYkno( final String ykno ) {
101                    this.ykno = ykno;
102            }
103    
104            /**
105             * 要æ±?Oを取得しますã?
106             *
107             * @return      要æ±?O
108             */
109            public String getYkno() {
110                    return ykno;
111            }
112    
113            /**
114             * シスãƒ?ƒ IDをセãƒ?ƒˆしますã?
115             *
116             * @param systemId シスãƒ?ƒ ID
117             */
118            public void setSystemId( final String systemId ) {
119                    this.systemId = systemId;
120            }
121    
122            /**
123             * シスãƒ?ƒ IDを取得しますã?
124             *
125             * @return  Stringシスãƒ?ƒ ID
126             */
127            public String getSystemId() {
128                    return systemId;
129            }
130    
131            /**
132             * ボディー部åˆ??DBTableModelをセãƒ?ƒˆしますã?
133             *
134             * @param body DBTableModelオブジェクãƒ?
135             */
136            public void setBody( final DBTableModel body ) {
137                    this.body = body;
138            }
139    
140            /**
141             * ボディー部åˆ??DBTableModelを取得しますã?
142             *
143             * @return      ボディー部åˆ??DBTableModelオブジェクãƒ?
144             */
145            public DBTableModel getBody() {
146                    return body;
147            }
148    
149            /**
150             * ヘッãƒ??部åˆ??DBTableModelをセãƒ?ƒˆしますã?
151             *
152             * @param header DBTableModelオブジェクãƒ?
153             */
154            public void setHeader( final DBTableModel header ) {
155                    this.header = header;
156            }
157    
158            /**
159             * ヘッãƒ??部åˆ??DBTableModelを取得しますã?
160             *
161             * @return      ヘッãƒ??部åˆ??DBTableModelオブジェクãƒ?
162             */
163            public DBTableModel getHeader() {
164                    return header;
165            }
166    
167            /**
168             * フッター部åˆ??DBTableModelをセãƒ?ƒˆしますã?
169             *
170             * @param footer DBTableModelオブジェクãƒ?
171             */
172            public void setFooter( final DBTableModel footer ) {
173                    this.footer = footer;
174            }
175    
176            /**
177             * フッター部åˆ??DBTableModelを取得しますã?
178             *
179             * @return      フッター部åˆ??DBTableModelオブジェクãƒ?
180             */
181            public DBTableModel getFooter() {
182                    return footer;
183            }
184    
185            /**
186             * 帳票IDをセãƒ?ƒˆしますã?
187             *
188             * @param listId 帳票ID
189             */
190            public void setListId( final String listId ) {
191                    this.listId = listId;
192            }
193    
194            /**
195             * 帳票IDを取得しますã?
196             *
197             * @return 帳票ID
198             */
199            public String getListId() {
200                    return listId;
201            }
202    
203            /**
204             * PDFパスワードをセãƒ?ƒˆしますã?
205             *
206             * @param pdfPasswd PDFパスワーãƒ?
207             */
208            public void setPdfPasswd( final String pdfPasswd ) {
209                    this.pdfPasswd = pdfPasswd;
210            }
211    
212            /**
213             * PDFパスワードを取得しますã?
214             *
215             * @return PDFパスワーãƒ?
216             */
217            public String getPdfPasswd() {
218                    return pdfPasswd;
219            }
220    
221            /**
222             * è¨?ªžをセãƒ?ƒˆしますã?
223             *
224             * @param lang è¨?ª?
225             */
226            public void setLang( final String lang ) {
227                    this.lang = lang;
228            }
229    
230            /**
231             * è¨?ªžを取得しますã?
232             *
233             * @return è¨?ª?
234             */
235            public String getLang() {
236                    return lang;
237            }
238    
239            /**
240             * 雛形ファイル名をセãƒ?ƒˆしますã?
241             *
242             * @param templateName 雛形ファイルå�?
243             */
244            public void setTemplateName( final String templateName ) {
245                    this.templateName = templateName;
246            }
247    
248            /**
249             * 雛形ファイル名を取得しますã?
250             *
251             * @return 帳票雛形ファイルå�?
252             */
253            public String getTemplateName() {
254                    return templateName;
255            }
256    
257            /**
258             * 実行方法をセãƒ?ƒˆしますã?
259             *
260             * @param outputType 実行方æ³?
261             */
262            public void setOutputType( final String outputType ) {
263                    this.outputType = outputType;
264            }
265    
266            /**
267             * 出力タイプを取得しますã?
268             *
269             * @return 出力タイãƒ?
270             */
271            public String getOutputType() {
272                    return outputType;
273            }
274    
275            /**
276             * プリンター名をセãƒ?ƒˆしますã?
277             *
278             * @param  printerName プリンターå�?
279             */
280            public void setPrinterName( final String printerName ) {
281                    this.printerName = printerName;
282            }
283    
284            /**
285             * プリンター名を取得しますã?
286             *
287             * @return プリンタå�?
288             */
289            public String getPrinterName() {
290                    return printerName;
291            }
292    
293            /**
294             * 処ç�?¦�求を処ç�?�™るスレãƒ?ƒ‰IDをセãƒ?ƒˆしますã?
295             *
296             * @param threadId スレãƒ?ƒ‰ID
297             */
298            public void setThreadId( final String threadId ) {
299                    this.threadId = threadId;
300            }
301    
302            /**
303             * 処ç�?¦�求を処ç�?�™るスレãƒ?ƒ‰IDを取得しますã?
304             *
305             * @return スレãƒ?ƒ‰ID
306             */
307            public String getThreadId() {
308                    return threadId;
309            }
310    
311            /**
312             * 出力ファイル名をセãƒ?ƒˆしますã?
313             *
314             * @param outputName 出力ファイルå�?
315             */
316            public void setOutputName( final String outputName ) {
317                    this.outputName = outputName;
318            }
319    
320            /**
321             * 出力ファイル名を設定しますã?
322             * GE50に設定されてã�?�ªã�??合ã?第四引数(要求番号)を利用するã€?
323             * そã?場合ã?タイプに応じた拡張子が自動設定されるã€?
324             *
325             * ".xls" : OUT_ODS_EXCEL
326             * ".pdf" : OUT_ODS_PDF , OUT_ODS_PRINT_PDF
327             * ".ods" : OUT_ODS_ODS
328             * ".xml" : RFID_PRINT , RFID_ALLPRINT , RFID_ALLERASE , RFID_SEQERASE
329             *
330             * @og.rev 4.3.3.4 (2008/11/01) ODS出力対å¿?
331             * @og.rev 5.4.3.0 (2011/12/26) RFIDãƒ?ƒ•ォルト対å¿?
332             * @og.rev 5.4.4.1 (2012/02/03) RFID拡張子変更
333             *
334             * @param       outputDir       出力ディレクトリå�?
335             * @param       outputFile      出力ファイルå�?
336             * @param       type            タイãƒ?
337             * @param       yokyu           要求番号(ファイル名がæŒ?®šされてã�?�ªã�??合ã?ファイルå�?
338             *
339             */
340            public void setOutputName( final String outputDir, final String outputFile, final String type, final String yokyu ){
341                    StringBuilder filePath = new StringBuilder();
342                    filePath.append( outputDir + File.separator );
343    
344                    if( outputFile == null || outputFile.length() == 0 ){ // ファイル名がæŒ?®šされてã�?�ªã�??合ã?要求番号を利用するã€?
345                            if( OUT_ODS_EXCEL.equals( type ) ){
346                                    filePath.append( yokyu );
347                                    filePath.append( ".xls" );
348                            }
349                            else if( OUT_ODS_PDF.equals( type ) || OUT_ODS_PRINT_PDF.equals( type ) ){
350                                    filePath.append( yokyu );
351                                    filePath.append( ".pdf" );
352                            }
353                            // 4.3.3.4 (2008/11/01) 追åŠ?
354                            else if( OUT_ODS_ODS.equals ( type ) ){
355                                    filePath.append( yokyu );
356                                    filePath.append( ".ods" );
357                            }
358                            // 5.4.3.0 (2011/12/26) 追åŠ?
359                            // 5.4.4.2 (2012/02/03) .txtではなã�?xml
360                            else if( ExecQueue.RFID_PRINT.equals( type ) || ExecQueue.RFID_ALLPRINT.equals( type )
361                                            || ExecQueue.RFID_ALLERASE.equals( type ) || ExecQueue.RFID_SEQERASE.equals( type ) ) {
362                                    filePath.append( yokyu );
363                                    filePath.append( ".xml" ); //txt-xml
364                            }
365                    }
366                    else {
367                            filePath.append( outputFile );
368                    }
369    
370                    this.outputName = filePath.toString();
371            }
372    
373            /**
374             * 出力ファイル名を取得しますã?
375             *
376             * @og.rev 5.1.2.0 (2010/01/01) 256シートをè¶?�ˆるå?合に対応ã?2ファイル目以降ã?、_1、_2?¥?¥?¥をファイル名ã?後ろにつける
377             *
378             * @return 出力å?ファイルå�?
379             */
380            public String getOutputName() {
381                    if( pageCnt <= MAX_SHEETS_PER_FILE ) {
382                            return outputName;
383                    }
384                    else {
385                            StringBuilder fileName = new StringBuilder();
386    
387                            int idx = outputName.lastIndexOf( '.' );
388                            String name = outputName.substring( 0, idx );
389                            String suffix = outputName.substring( idx );
390                            int addNo = (int)Math.ceil( (double)pageCnt/(double)MAX_SHEETS_PER_FILE ) - 1;
391    
392                            fileName.append( name ).append( "_" ).append( addNo ).append( suffix );
393    
394                            return fileName.toString();
395                    }
396            }
397    
398            /**
399             * 実行ファイルãƒ?‚£レクトリを指定しますã?
400             *
401             * @og.rev 4.3.3.0 (2008/10/01) 板金RFID対å¿?
402             *
403             * @param dir ãƒ?‚£レクトリ
404             */
405            public void setPrgDir( final String dir ) {
406                    this.prgdir = dir;
407            }
408    
409            /**
410             * 実行ファイルãƒ?‚£レクトリを取得しますã?
411             *
412             * @og.rev 4.3.3.0 (2008/10/01) 板金RFID対å¿?
413             *
414             * @return プログラãƒ?ƒ‡ィレクトリ
415             */
416            public String getPrgDir() {
417                    return prgdir;
418            }
419    
420            /**
421             * 実行ファイル名をセãƒ?ƒˆしますã?
422             *
423             * @og.rev 4.3.3.0 (2008/10/01) 板金RFID対å¿?
424             * @param       file    ファイルå�?
425             */
426            public void setPrgFile( final String file ) {
427                    this.prgfile = file;
428            }
429    
430            /**
431             * 実行ファイル名を取得しますã?
432             *
433             * @og.rev 4.3.3.0 (2008/10/01) 板金RFID対å¿?
434             *
435             * @return プログラãƒ?ƒ•ァイルå�?
436             */
437            public String getPrgFile() {
438                    return prgfile;
439            }
440    
441            /**
442             * プリンタIDをセãƒ?ƒˆしますã?
443             *
444             * @og.rev 4.3.3.0 (2008/10/01) 板金RFID対å¿?
445             * @param       id      プリンタID
446             */
447            public void setPrtId( final String id ) {
448                    this.prtid = id;
449            }
450    
451            /**
452             * プリンタIDを取得しますã?
453             *
454             * @og.rev 4.3.3.0 (2008/10/01) 板金RFID対å¿?
455             *
456             * @return プリンタID
457             */
458            public String getPrtId() {
459                    return prtid;
460            }
461    
462            /**
463             * ローカルリソース使用フラグをセãƒ?ƒˆしまã�?初期値:false)ã€?
464             *
465             * @param       fglocal ローカルリソース使用フラグ[true:使用する/false:使用しない]
466             */
467            public void setFglocal( final boolean fglocal ) {
468                    this.fglocal = fglocal;
469            }
470    
471            /**
472             * ローカルリソース使用フラグを取得しますã?
473             *
474             * @return ロールリソース使用フラグ[true:使用する/false:使用しない]
475             */
476            public boolean isFglocal() {
477                    return fglocal;
478            }
479    
480            /**
481             * ペã?ジエンドカãƒ?ƒˆフラグをセãƒ?ƒˆしまã�?初期値:false)ã€?
482             *
483             * @param fgcut ペã?ジエンドカãƒ?ƒˆの使用可否[true:使用/false:通常]
484             */
485            public void setFgcut( final boolean fgcut ) {
486                    this.fgcut = fgcut;
487            }
488    
489            /**
490             * ペã?ジエンドカãƒ?ƒˆフラグを取得しますã?
491             *
492             * @return ペã?ジエンドカãƒ?ƒˆフラグ
493             */
494            public boolean isFgcut() {
495                    return fgcut;
496            }
497    
498            /**
499             * PAGEBREAKカラãƒ??値をã?シート名として使ã�?�‹どã�?�‹をセãƒ?ƒˆしまã�?初期値:false)ã€?
500             *
501             * @og.rev 5.7.6.2 (2014/05/16) 新規追åŠ?
502             *
503             * @param useSheetName PAGEBREAKカラãƒ??シート名使用可否[true:使用/false:使用しない]
504             */
505            public void setUseSheetName( final boolean useSheetName ) {
506                    this.useSheetName = useSheetName;
507            }
508    
509            /**
510             * PAGEBREAKカラãƒ??値をã?シート名として使ã�?�‹どã�?�‹を取得しますã?
511             *
512             * @og.rev 5.7.6.2 (2014/05/16) 新規追åŠ?
513             *
514             * @return PAGEBREAKカラãƒ??シート名使用可否[true:使用/false:使用しない]
515             */
516            public boolean isUseSheetName() {
517                    return useSheetName;
518            }
519    
520            /**
521             * キューマネージャーをセãƒ?ƒˆしますã?
522             *
523             * @param manager キューマネージャー
524             */
525            public void setManager( final QueueManager manager ) {
526                    this.manager = manager;
527            }
528    
529            /**
530             * 帳票処ç�?ƒ‡ータをセãƒ?ƒˆしますã?
531             * 既にãƒ??ブルモãƒ?ƒ«がセãƒ?ƒˆされてã�?‚‹場合ã?、å?セãƒ?ƒˆしませんã€?
532             *
533             */
534            public void setData() {
535                    if( body == null && manager != null ) {
536                            manager.set( this );
537                    }
538            }
539    
540            /**
541             * キューを実行中の状態に更新しますã?
542             *
543             */
544            public void setExecute() {
545                    if( manager != null ) {
546                            manager.execute( this );
547                    }
548            }
549    
550            /**
551             * キューを完äº?¸ˆã?状態に更新しますã?
552             *
553             */
554            public void setComplete() {
555                    if( manager != null ) {
556                            manager.complete( this );
557                    }
558            }
559    
560            /**
561             * キューをエラーの状態に更新しますã?
562             */
563            public void setError() {
564                    if( manager != null ) {
565                            manager.error( this );
566                    }
567            }
568    
569            /**
570             * エラーメãƒ?‚»ージをセãƒ?ƒˆしますã?
571             *
572             * @param msg エラーメãƒ?‚»ージ
573             */
574            public void addMsg( final String msg ) {
575                    errMsg.append( msg );
576            }
577    
578            /**
579             * エラーメãƒ?‚»ージを取得しますã?
580             *
581             * @return エラーメãƒ?‚»ージ
582             */
583            public String getMsg() {
584                    return errMsg.toString();
585            }
586    
587            /**
588             * 処ç�?�—たã?ージ数を引数のåˆ?� けカウントアãƒ??しますã?
589             *
590             * @og.rev 5.1.2.0 (2010/01/01) 新規追åŠ?
591             *
592             * @param pgs カウントアãƒ??するペã?ジ数
593             */
594            public void addExecPageCnt( final int pgs ) {
595                    pageCnt += pgs;
596            }
597    
598            /**
599             * 処ç�?�—たã?ージ数を返しますã?
600             *
601             * @og.rev 5.1.2.0 (2010/01/01) 新規追åŠ?
602             *
603             * @return 処ç�?�—たã?ージ数
604             */
605            public int getExecPagesCnt() {
606                    return pageCnt;
607            }
608    
609            /**
610             * 処ç�?�—た行数をセãƒ?ƒˆしますã?
611             *
612             * @og.rev 5.1.2.0 (2010/01/01) 新規追åŠ?
613             *
614             * @param rws 処ç�?�—た行数
615             */
616            public void setExecRowCnt( final int rws ) {
617                    rowCnt = rws;
618            }
619    
620            /**
621             * 処ç�?�—た行数を返しますã?
622             *
623             * @og.rev 5.1.2.0 (2010/01/01) 新規追åŠ?
624             *
625             * @return 処ç�?�—た行数
626             */
627            public int getExecRowCnt() {
628                    return rowCnt;
629            }
630    
631            /**
632             * 全ての行が処ç�?�•れたかをセãƒ?ƒˆしまã�?初期値:false)ã€?
633             *
634             * これは、å?ç�?µ�果がã?256シートをè¶?�ˆてã�?�Ÿ場合ã?再度残りのãƒ??タにつã�?�¦
635             * 処ç�?‚’行うかどã�?�‹の判定するために、利用しますã?
636             *
637             * @og.rev 5.1.2.0 (2010/01/01) 新規追åŠ?
638             *
639             * @param flag 全ての行が処ç�?�•れたã�?
640             */
641            public void setEnd( final boolean flag ) {
642                    isDataEnd = flag;
643            }
644    
645            /**
646             * 全ての行が処ç�?�•れてã�?‚‹かを返しますã?
647             *
648             * これは、å?ç�?µ�果がã?256シートをè¶?�ˆてã�?�Ÿ場合ã?再度残りのãƒ??タにつã�?�¦
649             * 処ç�?‚’行うかどã�?�‹の判定するために、利用しますã?
650             *
651             * @og.rev 5.1.2.0 (2010/01/01) 新規追åŠ?
652             *
653             * @return 全ての行が処ç�?�•れたã�?
654             */
655            public boolean isEnd() {
656                    return isDataEnd;
657            }
658    }