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.fukurou.transfer;
017    
018    import java.io.File;
019    import java.io.PrintWriter;
020    
021    import org.opengion.fukurou.db.Transaction;
022    import org.opengion.fukurou.util.FileUtil;
023    import org.opengion.fukurou.util.StringUtil;
024    
025    /**
026     * 伝é?要求に対してのãƒ??タをファイルに書込みしますã?
027     * ä½?�—、書き込まれるãƒ??タにつã�?�¦は、旧伝é?シスãƒ?ƒ の形式と互換性を持たせるためã?
028     * ãƒ??タのå‰?0Byteに空白で埋め、さらに全体で500Byteになるよã�?�«行末にも空白埋めをしますã?
029     *
030     * 書込みするファイル名ã?、実行対象でæŒ?®šしますã?ファイル名ã?絶対パスでæŒ?®šして下さã�??
031     * またã?書込するãƒ?‚­ストファイルのエンコードã?書込パラメーターが指定することができますã?
032     * æŒ?®šしなã�??合ã?シスãƒ?ƒ リソースの"DB_ENCODE"でæŒ?®šされた値が適用されますã?
033     *
034     * @og.group 伝é?シスãƒ?ƒ 
035     *
036     * @version  5.0
037     * @author   Hiroki.Nakamura
038     * @since    JDK1.6
039     */
040    public class TransferExec_SAMCB implements TransferExec {
041    
042            // 書込ファイルオブジェクãƒ?
043    //      private File fileWrite = null;                  // 5.5.2.4 (2012/05/16) ローカル変数åŒ?
044    
045            // 書込ファイルのエンコーãƒ?
046    //      private String fileEncode = null;               // 5.5.2.4 (2012/05/16) ローカル変数åŒ?
047    
048            /**
049             * ファイルに書込みしますã?
050             *
051             * @param vals 伝é?ãƒ??タ(配å?)
052             * @param config 伝é?設定オブジェクãƒ?
053             * @param tran トランザクションオブジェクãƒ?
054             *
055             * @og.rev 5.5.3.3 (2012/06/15) close処ç�?
056             */
057            @Override
058            public void execute( final String[] vals, final TransferConfig config, final Transaction tran ) {
059                    File fileWrite = new File( config.getExecObj() );
060    
061                    String fileEncode = config.getExecPrm();
062                    if( fileEncode == null || fileEncode.length() == 0 ) {
063                            fileEncode = "UTF-8";
064                    }
065    
066                    PrintWriter writer = FileUtil.getPrintWriter( fileWrite,fileEncode );
067                    String line = null;
068                    for( String s : vals ) {
069                            // å‰?0Byteを空白埋め
070                            String preSpace = StringUtil.stringFill( "", 30, fileEncode );
071                            // 全体で500Byteになるよã�?�«後ろに空白埋め
072                            line = StringUtil.stringFill( preSpace + s, 500, fileEncode );
073                            writer.println( line );
074                    }
075                    writer.close(); // 5.5.3.3 (2012/06/15)
076            }
077    }