[jboss-svn-commits] JBL Code SVN: r8252 - labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/util

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Dec 12 08:54:55 EST 2006


Author: b_georges
Date: 2006-12-12 08:54:53 -0500 (Tue, 12 Dec 2006)
New Revision: 8252

Modified:
   labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/util/SecureFtpImpl.java
Log:
Documented and formated

Modified: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/util/SecureFtpImpl.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/util/SecureFtpImpl.java	2006-12-12 13:34:35 UTC (rev 8251)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/util/SecureFtpImpl.java	2006-12-12 13:54:53 UTC (rev 8252)
@@ -29,12 +29,13 @@
  * 
  */
 
-public class SecureFtpImpl implements RemoteFileSystem {
+public class SecureFtpImpl implements RemoteFileSystem
+{
 
 	private static final String TMP_SUFFIX = ".rosettaPart";
-        
-        private static final String SECURE_CHANNEL = "sftp";
 
+	private static final String SECURE_CHANNEL = "sftp";
+
 	private ConfigTree m_oParms;
 
 	private String m_sFtpServer, m_sUser, m_sPasswd;
@@ -63,25 +64,44 @@
 	@SuppressWarnings("unused")
 	private boolean m_bConnected;
 
-	public SecureFtpImpl(ConfigTree p_oP, boolean p_bConnect) throws Exception {
+	/*
+	 * Constructor
+	 * 
+	 * @param p_oP Is a config treeThe used to initialize the object
+	 * 
+	 * @param connect If true create a new sftp session
+	 * 
+	 */
+	public SecureFtpImpl(ConfigTree p_oP, boolean p_bConnect) throws Exception
+	{
 		m_oParms = p_oP;
 		initialize(p_bConnect);
 	}
 
+	/*
+	 * Constructor
+	 * 
+	 * @param attribs The key/value pairs used to initialize the object
+	 * 
+	 * @param connect If true create a new sftp session using attribs
+	 * 
+	 */
 	public SecureFtpImpl(List<KeyValuePair> attribs, boolean connect)
-			throws Exception {
+			throws Exception
+	{
 		m_oParms = new ConfigTree("fromProps");
 		for (KeyValuePair oCurr : attribs)
 			m_oParms.setAttribute(oCurr.getKey(), oCurr.getValue());
 		initialize(connect);
 	}
 
-	private void initialize(boolean bConnect) throws Exception {
+	private void initialize(boolean bConnect) throws Exception
+	{
 		checkParms();
-		if (bConnect) {
+		if (bConnect)
+		{
 			session = m_oJSch.getSession(m_sUser, m_sFtpServer, m_iPort);
 
-			// username and password will be given via UserInfo interface.
 			UserInfo ui = new SecureFtpUserInfo("");
 			session.setUserInfo(ui);
 
@@ -104,7 +124,8 @@
 
 	}
 
-	private void checkParms() throws Exception {
+	private void checkParms() throws Exception
+	{
 		m_sFtpServer = m_oParms.getAttribute(PARMS_FTP_SERVER);
 		if (null == m_sFtpServer)
 			throw new Exception("No FTP server specified");
@@ -128,10 +149,10 @@
 		String sAux = m_oParms.getAttribute(PARMS_PORT);
 		m_iPort = (null == sAux) ? 22 : Integer.parseInt(sAux);
 
-		//boolean bAscii = false;
+		// boolean bAscii = false;
 		sAux = m_oParms.getAttribute(PARMS_ASCII);
-		//if (null != sAux)
-		//	bAscii = Boolean.parseBoolean(sAux);
+		// if (null != sAux)
+		// bAscii = Boolean.parseBoolean(sAux);
 
 		m_bPassive = false;
 		sAux = m_oParms.getAttribute(PARMS_PASSIVE);
@@ -147,7 +168,8 @@
 	 * 
 	 * @see org.jboss.soa.esb.util.RemoteFileSystem#deleteRemoteFile(java.lang.String)
 	 */
-	public void deleteRemoteFile(String p_sFile) throws Exception {
+	public void deleteRemoteFile(String p_sFile) throws Exception
+	{
 		m_oSftpChannel.rm(getRemoteDir() + "/" + new File(p_sFile).getName());
 	}
 
@@ -158,25 +180,33 @@
 	 * 
 	 * @see org.jboss.soa.esb.util.RemoteFileSystem#remoteDelete(java.io.File)
 	 */
-	public void remoteDelete(File p_oFile) throws Exception {
+	public void remoteDelete(File p_oFile) throws Exception
+	{
 		m_oSftpChannel.rm(fileToFtpString(p_oFile));
 	}
 
 	/*
-	 * (non-Javadoc)
+	 * Returns a list of Filenames for the directory specified in p_Suffix
 	 * 
+	 * @param p_sSuffix The remote directory path from the SFTP-Server
+	 * 
 	 * @see org.jboss.soa.esb.util.RemoteFileSystem#getFileListFromRemoteDir(java.lang.String)
 	 */
-	public String[] getFileListFromRemoteDir(String p_sSuffix) throws Exception {
+	public String[] getFileListFromRemoteDir(String p_sSuffix) throws Exception
+	{
 		String sSuffix = (null == p_sSuffix) ? "*" : "*" + p_sSuffix;
 		List<String> lFileList = new ArrayList<String>();
 		Vector vFileList = m_oSftpChannel.ls(sSuffix);
-		if (vFileList != null) {
-			for (int i = 0; i < vFileList.size(); i++) {
+		if (vFileList != null)
+		{
+			for (int i = 0; i < vFileList.size(); i++)
+			{
 				Object obj = vFileList.elementAt(i);
-				if (obj instanceof LsEntry) {
+				if (obj instanceof LsEntry)
+				{
 					SftpATTRS oSftAttr = ((LsEntry) obj).getAttrs();
-					if (!oSftAttr.isDir()) {
+					if (!oSftAttr.isDir())
+					{
 						lFileList.add(((LsEntry) obj).getFilename());
 					}
 				}
@@ -186,30 +216,40 @@
 	}
 
 	/*
-	 * (non-Javadoc)
+	 * Set the new directory to p_SDir
 	 * 
+	 * @param p_sDir The remote directory path name we want to "cd" to.
+	 * 
 	 * @see org.jboss.soa.esb.util.RemoteFileSystem#setRemoteDir(java.lang.String)
 	 */
-	public void setRemoteDir(String p_sDir) throws Exception {
+	public void setRemoteDir(String p_sDir) throws Exception
+	{
 		m_oSftpChannel.cd(p_sDir);
 	}
 
 	/*
-	 * (non-Javadoc)
+	 * Rename the Remote Directory name p_sFrom with p_sTo
 	 * 
+	 * @param p_sFrom The remote directory name we want to rename
+	 * 
+	 * @param p_sTo The new remote directory name
+	 * 
 	 * @see org.jboss.soa.esb.util.RemoteFileSystem#renameInRemoteDir(java.lang.String,
 	 *      java.lang.String)
 	 */
 	public void renameInRemoteDir(String p_sFrom, String p_sTo)
-			throws Exception {
+			throws Exception
+	{
 
 		String sRmtFrom = new File(p_sFrom).getName();
 		String sRmtTo = new File(p_sTo).getName();
 
-		try {
+		try
+		{
 			m_oSftpChannel.rename(getRemoteDir() + "/" + sRmtFrom,
 					getRemoteDir() + "/" + sRmtTo);
-		} catch (Exception e) {
+		} catch (Exception e)
+		{
 			String sMess = this.getClass().getSimpleName()
 					+ " can't rename in remote directory <" + e.getMessage()
 					+ ">";
@@ -218,16 +258,23 @@
 	}
 
 	/*
-	 * (non-Javadoc)
+	 * Rename the Remote File name p_sFrom with p_sTo
 	 * 
+	 * @param p_oFrom The remote file name we want to rename
+	 * 
+	 * @param p_oTo The new remote file name
+	 * 
 	 * @see org.jboss.soa.esb.util.RemoteFileSystem#remoteRename(java.io.File,
 	 *      java.io.File)
 	 */
-	public void remoteRename(File p_oFrom, File p_oTo) throws Exception {
-		try {
+	public void remoteRename(File p_oFrom, File p_oTo) throws Exception
+	{
+		try
+		{
 			m_oSftpChannel.rename(fileToFtpString(p_oFrom),
 					fileToFtpString(p_oTo));
-		} catch (Exception e) {
+		} catch (Exception e)
+		{
 			String sMess = this.getClass().getSimpleName()
 					+ " can't rename in remote directory <" + e.getMessage()
 					+ ">";
@@ -236,12 +283,17 @@
 	}
 
 	/*
-	 * (non-Javadoc)
+	 * Upload the local File p_ofile to p_sRemoteName
 	 * 
+	 * @param p_oFile The local file name we want to upload
+	 * 
+	 * @param p_sRemoteName The remote file name [can be the same as p_oFile of course]
+	 * 
 	 * @see org.jboss.soa.esb.util.RemoteFileSystem#uploadFile(java.io.File,
 	 *      java.lang.String)
 	 */
-	public void uploadFile(File p_oFile, String p_sRemoteName) throws Exception {
+	public void uploadFile(File p_oFile, String p_sRemoteName) throws Exception
+	{
 		String sRemoteOK = getRemoteDir() + "/" + p_sRemoteName;
 		String sRemoteTmp = sRemoteOK + TMP_SUFFIX;
 		// m_oSftpChannel.setType(m_oXferType);
@@ -250,45 +302,59 @@
 	}
 
 	/*
-	 * (non-Javadoc)
+	 * Download the remote File p_sFile to p_sFile.
 	 * 
+	 * @param p_sFile The remote file name we want to download
+	 * 
+	 * @param p_sFinalName The local file name
+	 * 
 	 * @see org.jboss.soa.esb.util.RemoteFileSystem#downloadFile(java.lang.String,
 	 *      java.lang.String)
 	 */
 	public void downloadFile(String p_sFile, String p_sFinalName)
-			throws Exception {
-		 File oLocalDir = new File(m_sLocalDir);
-	     File oLclFile= File.createTempFile("Rosetta_",TMP_SUFFIX,oLocalDir);
+			throws Exception
+	{
+		File oLocalDir = new File(m_sLocalDir);
+		File oLclFile = File.createTempFile("Rosetta_", TMP_SUFFIX, oLocalDir);
 
-	     try { oLclFile.delete(); }
-	     catch (Exception e) {}
-	     //TODO check if we have to set the Transfer Type with JSch impl => m_oXferType
-	     m_oSftpChannel.get(fileToFtpString(oLclFile),p_sFile);
+		try
+		{
+			oLclFile.delete();
+		} catch (Exception e)
+		{
+		}
+		// TODO check if we have to set the Transfer Type with JSch impl =>
+		// m_oXferType
+		m_oSftpChannel.get(fileToFtpString(oLclFile), p_sFile);
 
-	     File oNew = new File(oLocalDir,p_sFinalName);
-	     if (oNew.exists()) oNew.delete();
-	     oLclFile.renameTo(oNew);
+		File oNew = new File(oLocalDir, p_sFinalName);
+		if (oNew.exists())
+			oNew.delete();
+		oLclFile.renameTo(oNew);
 	}
 
 	/*
-	 * (non-Javadoc)
+	 * Returns the current remote directory
 	 * 
 	 * @see org.jboss.soa.esb.util.RemoteFileSystem#getRemoteDir()
 	 */
-	public String getRemoteDir() {
+	public String getRemoteDir()
+	{
 		return m_sRemoteDir;
 	}
 
 	/*
-	 * (non-Javadoc)
+	 * Terminates the sftp session.
 	 * 
 	 * @see org.jboss.soa.esb.util.RemoteFileSystem#quit()
 	 */
-	public void quit() {
+	public void quit()
+	{
 		m_oSftpChannel.quit();
 	}
 
-	public static String fileToFtpString(File p_oF) {
+	public static String fileToFtpString(File p_oF)
+	{
 		return (null == p_oF) ? null : p_oF.toString().replace("\\", "/");
 	}
 




More information about the jboss-svn-commits mailing list