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.HybsDateUtil;
024 import org.opengion.fukurou.util.StringUtil;
025
026 /**
027 * ä¼é?è¦æ±‚ã«å¯¾ã—ã¦ã®ãƒ??ã‚¿ã‚’ãƒ•ã‚¡ã‚¤ãƒ«ã«æ›¸è¾¼ã¿ã—ã¾ã™ã?
028 * ä½?—ã€æ›¸ãè¾¼ã¾ã‚Œã‚‹ãƒ??ã‚¿ã«ã¤ã?¦ã¯ã€æ—§ä¼é?シスãƒ?ƒ ã®å½¢å¼ã¨äº’æ›æ€§ã‚’æŒãŸã›ã‚‹ãŸã‚ã?
029 * ãƒ??ã‚¿ã®å‰?0Byteã«ç©ºç™½ã§åŸ‹ã‚ã€ã•らã«å…¨ä½“ã§æ¨™æº–ã§ã¯500Byteã«ãªã‚‹ã‚ˆã?«è¡Œæœ«ã«ã‚‚空白埋ã‚ã‚’ã—ã¾ã™ã?
030 * 500byte以外ã«ã—ãŸã??åˆã?ã€æ›¸ãè¾¼ã¿ãƒ‘ラメータã®ç¬¬?’å¼•æ•°ã«æ•´æ•°ã§æŒ?®šã—ã¦ãã ã•ã„ã€?
031 *
032 * å…ˆé?ãƒ??ã‚¿ã«é™ã£ã¦ã¯ã€ã‚¹ãƒšã?ス以外ã§åŸ‹ã‚る事もå¯èƒ½ã§ã™ã?
033 * ãã?å ´åˆã?実行対象ã®ç¬¬?’引数ã‹ã‚‰é ?•ªã«
034 * 状æ³ã‚³ãƒ¼ãƒ?1byte)ã€ãƒ‡ãƒ¼ã‚¿ã‚³ãƒ¼ãƒ?1byte)ã€??りå?(2byte)ã€ãƒ†ã‚スト種別(4byte) é€ã‚Šå…?2byte)
035 * を指定ã—ã¦ãã ã•ã„ã€?
036 * é€ã‚Šå…?‚’æŒ?®šã—ãŸå?åˆã?ãƒ?‚ストã?後ã«8byteスペã?ス+é€ã‚Šå…?26byteスペã?ス+連番ã€?‚’ä»˜åŠ ã—ãŸä¸Šã§
037 * 行末ã®ç©ºç™½åŸ‹ã‚を行ã„ã¾ã™ï¼ˆå¾Œã‚70byteã¨ã?†æŒ?®šã§ã¯ãªã??ã§æ³¨æ„ï¼?
038 *
039 * 書込ã¿ã™ã‚‹ãƒ•ァイルåã?ã€å®Ÿè¡Œå¯¾è±¡ã§æŒ?®šã—ã¾ã™ã?ファイルåã?çµ¶å¯¾ãƒ‘ã‚¹ã§æŒ?®šã—ã¦ä¸‹ã•ã??
040 * ã¾ãŸã?書込ã™ã‚‹ãƒ?‚ストファイルã®ã‚¨ãƒ³ã‚³ãƒ¼ãƒ‰ã?æ›¸è¾¼ãƒ‘ãƒ©ãƒ¡ãƒ¼ã‚¿ãƒ¼ã§æŒ?®šã™ã‚‹ã“ã¨ãŒã§ãã¾ã™ã?
041 * æŒ?®šã—ãªã??åˆã?UTF-8ãŒé©ç”¨ã•れã¾ã™ã?
042 *
043 * @og.group ä¼é?シスãƒ?ƒ
044 *
045 * @version 5.0
046 * @author Hiroki.Nakamura
047 * @since JDK1.6
048 */
049 public class TransferExec_SAMCB implements TransferExec {
050
051 // 書込ファイルオブジェク�
052 // private File fileWrite = null; // 5.5.2.4 (2012/05/16) ãƒãƒ¼ã‚«ãƒ«å¤‰æ•°åŒ?
053
054 // 書込ファイルã®ã‚¨ãƒ³ã‚³ãƒ¼ãƒ?
055 // private String fileEncode = null; // 5.5.2.4 (2012/05/16) ãƒãƒ¼ã‚«ãƒ«å¤‰æ•°åŒ?
056
057 /**
058 * ãƒ•ã‚¡ã‚¤ãƒ«ã«æ›¸è¾¼ã¿ã—ã¾ã™ã?
059 *
060 * @param vals ä¼é?ãƒ??ã‚¿(é…å?)
061 * @param config ä¼é?è¨å®šã‚ªãƒ–ジェクãƒ?
062 * @param tran トランザクションオブジェク�
063 *
064 * @og.rev 5.5.3.3 (2012/06/15) close処ç?
065 * @og.rev 5.8.1.1 (2014/11/14) ãƒ‘ãƒ©ãƒ¡ãƒ¼ã‚¿ã§æ¡æ•°æŒ?®šå¯èƒ½ã«ã™ã‚‹
066 * @og.rev 5.8.1.2 (2014/11/21) 剿–¹,後方ã®ã‚¹ãƒšã?ス埋ã‚ã®ç®?‰€ã®äº’æ›æ€§ã‚’上ã’ã‚?
067 */
068 @Override
069 public void execute( final String[] vals, final TransferConfig config, final Transaction tran ) {
070 String fileEncode = "UTF-8";
071
072 // 5.8.1.2
073 String[] obj = StringUtil.csv2Array( config.getExecObj(), ' ' );
074 // File fileWrite = new File( config.getExecObj() );
075 File fileWrite = new File( obj[0] );
076 String preText = "";
077 String suffText = "";
078 preText += ( obj.length > 1 ) ? obj[1] : ""; // 状æ³ã‚³ãƒ¼ãƒ?
079 preText += ( obj.length > 2 ) ? obj[2] : ""; // �?タコー�
080 preText += ( obj.length > 3 ) ? StringUtil.stringFill( obj[3], 8, fileEncode ) : ""; // ホス�O
081 preText += ( obj.length > 4 ) ? StringUtil.stringFill( obj[4], 4, fileEncode ) : ""; // ãƒ?‚スト種別
082 preText = StringUtil.stringFill( preText, 14, fileEncode );
083 if(obj.length > 1){
084 preText += HybsDateUtil.getDate( "yyMMddHHmmss" );
085 preText += HybsDateUtil.getDate( "MMdd" );
086 }
087 preText += ( obj.length > 4 ) ? StringUtil.stringFill( obj[4], 4, fileEncode ) : ""; // ãƒ?‚スト種別
088
089 suffText += ( obj.length > 5 ) ? StringUtil.stringFill( "", 8, fileEncode ) + StringUtil.stringFill( obj[5], 28, fileEncode ) : ""; // é€ã‚Šå…?
090
091 // 5.8.1.1 (2014/11/14) fillByte追�
092 int fillByte = 500;
093 String execPrm = config.getExecPrm();
094 if( execPrm != null && execPrm.length() > 0 ){
095 String[] prm = StringUtil.csv2Array( execPrm, ' ' );
096 fileEncode = prm[0];
097 if( prm.length > 1 ) {
098 fillByte = Integer.parseInt( prm[1] );
099 }
100 }
101
102 // String fileEncode = config.getExecPrm();
103 // if( fileEncode == null || fileEncode.length() == 0 ) {
104 // fileEncode = "UTF-8";
105 // }
106
107 PrintWriter writer = FileUtil.getPrintWriter( fileWrite,fileEncode );
108 String line = null;
109 // 5.8.1.2 (2014/11/21) iãŒæ¬²ã—ã„ã®ã§æ›¸ã方を変更ã™ã‚‹
110 // for( String s : vals ) {
111 for (int i = 0; i < vals.length; i++){
112 // å‰?0Byteを空白埋ã‚
113 // 5.8.1.2 (2014/11/21) 剿–¹ã‚’スペã?ス以外ã§åŸ‹ã‚られるよã?«ã™ã‚‹
114 // String preSpace = StringUtil.stringFill( "", 30, fileEncode );
115 String preSpace = StringUtil.stringFill( preText, 30, fileEncode );
116 // 全体ã§500Byteã«ãªã‚‹ã‚ˆã?«å¾Œã‚ã«ç©ºç™½åŸ‹ã‚
117 // 5.8.1.1 500Byte以外もæŒ?®šå¯èƒ½ã¨ã™ã‚‹
118 // line = StringUtil.stringFill( preSpace + s, 500, fileEncode );
119 // line = StringUtil.stringFill( preSpace + s, fillByte, fileEncode );
120 // 5.8.1.2 (2014/11/21)
121 if(obj.length > 5){
122 line = StringUtil.stringFill( preSpace + vals[i] + suffText + StringUtil.intFill( Integer.toString( i ), 14 ), fillByte, fileEncode );
123 }
124 else{
125 line = StringUtil.stringFill( preSpace + vals[i] + suffText, fillByte, fileEncode );
126 }
127
128 writer.println( line );
129 }
130 writer.close(); // 5.5.3.3 (2012/06/15)
131 }
132 }