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.taglib;
017
018 import org.opengion.hayabusa.common.HybsSystem;
019 import org.opengion.hayabusa.common.HybsSystemException;
020 import org.opengion.hayabusa.db.DBTableModel;
021 import org.opengion.hayabusa.report.DBTableReport;
022 import org.opengion.fukurou.util.FileUtil;
023 import org.opengion.fukurou.util.Shell;
024
025 import org.opengion.fukurou.util.StringUtil ;
026 import static org.opengion.fukurou.util.StringUtil.nval ;
027
028 import java.io.File;
029 import java.io.IOException;
030 import java.io.ObjectOutputStream;
031 import java.io.ObjectInputStream;
032
033 /**
034 * 検索結果の DBTableModelオブジェクトをレポã?ト形式に変換するタグですã?
035 *
036 * ãƒ??タ(DBTableModel)と、コントローラ(DBTableReport クラス)を与えてã€?
037 * 外部からコントロールすることで、各種形式で ãƒ??タ(DBTableModel)を表示させることã�?
038 * 可能ですã?
039 *
040 * @og.formSample
041 * ●形式ï¼?lt;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 */
071 public 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) またã?ã€?¼’文字目がã?
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) またã?ã€?¼’文字目がã?
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 }