01: /*
02: * ChainBuilder ESB
03: * Visual Enterprise Integration
04: *
05: * Copyright (C) 2006 Bostech Corporation
06: *
07: * This program is free software; you can redistribute it and/or modify
08: * it under the terms of the GNU General Public License as published by
09: * the Free Software Foundation; either version 2 of the License, or
10: * (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public License
18: * along with this program; if not, write to the Free Software
19: * Foundation, Inc.,59 Temple Place, Suite 330, Boston, MA 02111-1307
20: * USA
21: *
22: *
23: * $Id: SetTransferMode.java 11093 2007-12-21 18:22:22Z mpreston $
24: */
25: package com.bostechcorp.cbesb.runtime.ftp.interpreter;
26:
27: import java.io.IOException;
28: import java.util.HashMap;
29: import java.util.Iterator;
30: import java.util.Map;
31:
32: import org.apache.commons.logging.Log;
33: import org.apache.commons.logging.LogFactory;
34: import org.apache.commons.net.ftp.FTP;
35: import org.apache.commons.net.ftp.FTPClient;
36:
37: /**
38: * Sets the transfer mode to the specified value.
39: *
40: * @author j.zhang
41: * @version 1.0.0
42: */
43: public class SetTransferMode extends AbstractCommandExpression {
44:
45: protected final transient Log logger = LogFactory
46: .getLog(getClass());
47:
48: /**
49: * The Map of parameters.
50: */
51: private Map paramMap = new HashMap<String, String>();
52: private static final String FTP_TRANSFER_MODE_ASCII = "ascii";
53: private static final String FTP_TRANSFER_MODE_BINARY = "binary";
54:
55: @Override
56: /* (non-Javadoc)
57: * @see com.bostechcorp.cbesb.runtime.ftp.AbstractCommandExpression#interpret(java.util.Map)
58: */
59: public void interpret(Map<String, String> paramMap) {
60: this .paramMap = paramMap;
61: }
62:
63: @Override
64: /* (non-Javadoc)
65: * @see com.bostechcorp.cbesb.runtime.ftp.AbstractCommandExpression#execute(org.apache.commons.net.ftp.FTPClient)
66: */
67: public Object execute(FtpExecContext context) {
68: FTPClient ftp = context.getFtpclient();
69: logger.debug("setTransferMode:");
70: Iterator iterator = paramMap.values().iterator();
71: while (iterator.hasNext()) {
72: String transferMode = (String) iterator.next();
73: try {
74: if (FTP_TRANSFER_MODE_ASCII.equals(transferMode)) {
75: ftp.setFileType(FTP.ASCII_FILE_TYPE);
76: } else if (FTP_TRANSFER_MODE_BINARY
77: .equals(transferMode)) {
78: ftp.setFileType(FTP.BINARY_FILE_TYPE);
79: } else {
80: // logger.error("Unsupport ftpTransferMode [" + transferMode + "]! Set to the default value: \"binary\".");
81: ftp.setFileType(FTP.BINARY_FILE_TYPE);
82: }
83: } catch (IOException ioe) {
84: // ioe.printStackTrace();
85: return ioe;
86: }
87: }
88: return true;
89: }
90:
91: }
|