%--
This is cleaned up and modified version of the related richedit files.
The jsp code used for FTP testing refactored so it can be run as java class.
--%>
<%@ page language="java" %>
<%@ page import="idetix.util.StringUtils,revize.publish.FileLoader,revize.publish.FileLoaderException,revize.formWizard.*"%>
<%@ include file="/util/cacheControl.jsp" %>
<%
//System.out.println("ftpoperation: " + request.getQueryString());
String[] status = {"",""};
FTPOperationJsp ftp = new FTPOperationJsp();
//status = new FTPTesting().process(request,ftp); //run from FTPTesting class
status = process(request,ftp); //run from this jsp
String action = status[0];
String strStatus = status[1];
%>
FTP Validation Results
FTP Validation Results
<%=strStatus.replaceAll("\\\\n"," ")%>
<%!
/**
* The code in this method was originally in line code from ftpoperations.jsp used
* by the richedit Revize form wizard. It was changed run as a method so it could
* be run from either a jsp page or from the FTPTesting.java class.
*
* The major change was to eliminate looping through an array of ftp servers since
* form should only be submitted to a single server and eliminated page forwarding.
*
* @param request HttpServletRequest of web page
* @param ftp reference to FTPOperation instance
* @return String Array [0]="reject", "warn" or "save" [1]=detail status message
*/
public String[] process(HttpServletRequest request, FTPOperationJsp ftp)
{
int NO_OP = 0;
int FILENAMES_NOT_SAME = 1;
int FILENAMES_SAME = 2;
String strStatus = "";
String stackTraceString = "";
int noOfConnectionsFailed = 0; // keep count of no. of ftp connections failed
int NoOfconnectionsTried = 0; // keep count of ftp connections tried
FileLoader loader = null;
// variables used in FTPOperation and this class
String strOrgLocation = StringUtils.getParameter(request,"orglocation");
String strLocation = request.getParameter("location");
String strPort = StringUtils.getParameter(request,"port");
while (true)
{
String[] inRequest = {
StringUtils.getParameter(request,"host"),
strOrgLocation,
strLocation,
StringUtils.getParameter(request,"user"),
StringUtils.getParameter(request,"password"),
strPort,
StringUtils.getParameter(request,"headerlist"),
StringUtils.getParameter(request,"prevheaderlist")
};
// sets class variables: strHost, strOrgLocation, strLocation, strUser, strPassword,
// strPort, strHeaderList, strPrevHeaderList, strStatus
ftp.setVariables(inRequest);
ftp.handlePort(strPort);
try
{
NoOfconnectionsTried++;
//ftp.strStatus += NoOfconnectionsTried + ") " + strHost + " : ";
if (loader != null)
loader.close(); // bye to FTP session
loader = null;
ftp.initiateFTP();
loader = ftp.getLoader();
if (loader == null) //connection is successfully established
{
strStatus += "ERROR :: Unable to establish ftp connection.\\n\\n";
break;
}
//----- new form addition
if (0 == strOrgLocation.compareTo(""))
{
ftp.splitLocation(strLocation);// split the given location into strFolder & strFile
if( true == ftp.downloadTest() )
{ //download was successful i.e. file already exist hence error
strStatus += "ERROR :: File with Specified Name Already Exists. Please choose another file name.\\n\\n";
noOfConnectionsFailed++;
}
else
{ //file with given name does not exist hence try uploading
loader.close(); // bye to FTP session
loader = null;
ftp.initiateFTP();
ftp.uploadFile();
}
}
//----- edit of previous form
else
{
int operationType = NO_OP;
ftp.splitLocation(strOrgLocation);
if (false == ftp.downloadTest())
{ // ERROR::org file does not exist
strStatus += "ERROR :: Original File Download Fail. Your file at the Ftp location has either \\n"
+ "been deleted or repaced or renamed. \\n"
+ "You should either restore the original file at its FTP location and then save\\n"
+ "or first save without any form and then make a form with a new file name.\\n\\n";
noOfConnectionsFailed++;
strOrgLocation = "";
continue;
}
else
{ // original file exist
loader.close(); // bye to FTP session
loader = null;
ftp.initiateFTP();
if (0 != strOrgLocation.compareTo(strLocation))
{
// original and given location/filename are not same
// hence check if given filename is already occupied
// if occupied then flash error else do processing
ftp.splitLocation(strLocation); //split folder and filename
if (true == ftp.downloadTest())
{
// download was successful i.e. file already exist hence error
strStatus += "ERROR :: File with Specified Name Already Exists. Please choose another file name\\n\\n";
noOfConnectionsFailed++;
}
else
{
// file with given name does not exist hence
// do processing
operationType = FILENAMES_NOT_SAME;
}
}
else
{
// do processing. if new file is reqd then
// create
operationType = FILENAMES_SAME;
}
if (operationType != NO_OP)
{
byte[] fOrgFile;
try
{
fOrgFile = ftp.downloadOrgFile();
if (fOrgFile != null && fOrgFile.length > 0)
{
ftp.performFileManipulation(operationType, fOrgFile);
}
else
{
strStatus += "ERROR :: Original File Download Fail\\n\\n";
noOfConnectionsFailed++;
}
}
catch (FileLoaderException e)
{
strStatus += "ERROR :: Operation Failure\\n\\n";
strStatus += "Stack Trace : \\n";
stackTraceString += StringUtils.convertStackTraceToString(e);
noOfConnectionsFailed++;
}
}
}
}
if (loader != null)
loader.close(); // bye to FTP session
loader = null;
}
catch (FileLoaderException e)
{
strStatus += "ERROR :: Operation Failure\\n\\n";
strStatus += "Stack Trace : \\n";
stackTraceString += StringUtils.convertStackTraceToString(e);
noOfConnectionsFailed++;
}
break;
}
if (strStatus.indexOf("ERROR") == -1)
strStatus += "SUCCESS\\n\\n";
else if (stackTraceString.length() > 0)
strStatus += "