/**
* $Id: NetWareFile.java,v 1.20 2005/11/30 11:26:35 ss150821 Exp $
* Copyright 2002 Sun Microsystems, Inc. All
* rights reserved. Use of this product is subject
* to license terms. Federal Acquisitions:
* Commercial Software -- Government Users
* Subject to Standard License Terms and
* Conditions.
*
* Sun, Sun Microsystems, the Sun logo, and Sun ONE
* are trademarks or registered trademarks of Sun Microsystems,
* Inc. in the United States and other countries.
*/
package com.sun.portal.netfile.servlet.java1;
import java.util.*;
import com.sun.portal.log.common.PortalLogger;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.io.*;
import java.text.SimpleDateFormat;
class NetWareFile extends FtpFile {
private String s_empty_string = "";
private char c_eol = '\n';
private final int MAX_COLUMNS = 8;
private static Logger logger = PortalLogger.getLogger (NetWareFile.class);
NetWareFile(NetFileLogManager log_Mgr, String s_machine_encoding) {
super(log_Mgr, s_machine_encoding);
}
String[] getFTPDir(
String username,
String password,
String machname,
String VMSname,
String dirS,
NetFileResource nfr_user_locale_i18n_bucket) throws NetFileException {
// logger.info("Expanding Netware directory");
logger.info("PSSRNF_CSPNSJ1192");
String textouting = s_empty_string;
int txt = 0;
StringBuffer buftxt = new StringBuffer(400);
String prwrkd = s_empty_string;
String col_type = s_empty_string;
String col_junk1 = s_empty_string;
String col_size = s_empty_string;
String col_month = s_empty_string;
String col_day = s_empty_string;
String col_time = s_empty_string;
String type = s_empty_string;
String date = s_empty_string;
FullFtpClient ffc;
try {
ffc = new FullFtpClient(machname, s_machine_encoding);
try {
ffc.login(username, password);
} catch (IOException ioe) {
throw new NetFileException(
NetFileException.KEY_IDENTIFIER_PREFIX + "error12");
}
ffc.cd(VMSname + dirS);
prwrkd = ffc.pwd();
ffc.setMachineToAccess(machname);
// Do an 'ls'
BufferedReader theList = new BufferedReader(new InputStreamReader(
ffc.list(),
s_machine_encoding));
String theLine;
while ((theLine = theList.readLine()) != null) {
buftxt.append(theLine).append(c_eol);
}
textouting = buftxt.toString();
theList.close();
ffc.closeServer();
} catch (IOException ex) {
// logger.log(Level.SEVERE, "Exception in getting the netware file listing",ex);
logger.log(Level.SEVERE, "PSSRNF_CSPNSJ1193");
throw new NetFileException(NetFileException.KEY_IDENTIFIER_PREFIX
+ "error20");
}
if (textouting.indexOf("Permission denied") > 0) {
throw new NetFileException(NetFileException.KEY_IDENTIFIER_PREFIX
+ "error6");
}
ArrayList cache = new ArrayList();
cache.clear();
StringTokenizer pars = new StringTokenizer(textouting, "\n");
/** Output looks like this. parse it.
* ftp> dir
* 200 PORT command okay.
* 150 Opening data connection for (192.18.178.58,36872).
* total 0
* - [RWCEAFMS] supervisor 890 May 07 22:33 vol$log.err
* - [RWCEAFMS] supervisor 607 May 07 22:33 tts$log.err
* - [RWCEAFMS] supervisor 65536 May 12 19:32 backout.tts
* d [RWCEAFMS] supervisor 512 Jun 13 12:37 login
* d [RWCEAFMS] icebox81 512 May 02 22:40 ndps
* 226 Transfer complete.
* 1687 bytes received in 0.01 seconds (163.70 Kbytes/s)
* ftp>
**/
String tmp = s_empty_string;
while (pars.hasMoreElements()) {
tmp = (String) pars.nextElement();
/* grep for the 'total' word in the 'ls' output */
/**
* Bug 4521436
*
* while (tmp.startsWith(nfr_user_locale_i18n_bucket.getString("total"))) {
* while (pars.hasMoreElements()) {
* tmp = (String)pars.nextElement();
* cache.addElement(tmp);
* }
* }
*
*/
if (pars.countTokens() == 0) {
return new String[] {};
}
while (tmp.startsWith(nfr_user_locale_i18n_bucket
.getString("total"))) {
while (pars.hasMoreTokens()) {
tmp = pars.nextToken();
cache.add(tmp);
}
}
// end of code change for Bug 4521436
}
Object[] rowdata = new Object[300];
int i_number_of_files = cache.size();
if (i_number_of_files == 0) {
return new String[] {};
}
String[] sa_file_listing = new String[i_number_of_files * 4];
// logger.info("netware file listing size="+i_number_of_files);
Object[] params2 = { new Integer(i_number_of_files) };
logger.log(Level.INFO, "PSSRNF_CSPNSJ1194", params2);
int i_index = 0;
if (cache.size() > 0) {
for (int row = 0; row < cache.size(); row++) {
String str_cache = (String) cache.get(row);
StringTokenizer parsnew = new StringTokenizer(str_cache, " ");
String col_name = s_empty_string;
int parscntnew = parsnew.countTokens();
for (int j = 0; j < parscntnew; j++) {
rowdata[j] = parsnew.nextToken();
}
/* Format of ftpd from Sun Solaris
* drwxrwxrwt 8 sys sys 2717 May
* 7 17:11 tmp
* Format of ftpd from Novell Netware
* d [RWCEAFMS] admin 512 May 03
**/
/*
* - [RWCEAFMS] supervisor 890 May 07 22:33 vol$log.err
* - [RWCEAFMS] supervisor 607 May 07 22:33 tts$log.err
*/
col_type = rowdata[0].toString();
col_junk1 = rowdata[1].toString();
col_size = rowdata[3].toString();
col_month = rowdata[4].toString();
col_day = rowdata[5].toString();
col_time = rowdata[6].toString();
// This is for the spaced files(directories)
if (parscntnew > MAX_COLUMNS - 1) {
for (int l = MAX_COLUMNS - 1; l < parscntnew; l++) {
col_name = col_name + rowdata[l].toString() + " ";
}
} else {
col_name = col_name + rowdata[MAX_COLUMNS - 1].toString();
}
col_name = col_name.trim();
if ((col_name.equals(".")) || (col_name.equals(".."))) {
} else {
type = col_type.substring(0, 1);
date = getModifiedDateFormat(col_month, col_day, col_time);
sa_file_listing[i_index++] = type;
sa_file_listing[i_index++] = col_name;
sa_file_listing[i_index++] = col_size;
sa_file_listing[i_index++] = date;
// logger.info( "type="+type);
Object[] params3 = { type };
logger.log(Level.INFO, "PSSRNF_CSPNSJ1195", params3);
// logger.info( "name="+col_name);
Object[] params4 = { col_name };
logger.log(Level.INFO, "PSSRNF_CSPNSJ1196", params4);
// logger.info( "size="+col_size);
Object[] params5 = { col_size };
logger.log(Level.INFO, "PSSRNF_CSPNSJ1197", params5);
// logger.info( "date="+date);
Object[] params6 = { date };
logger.log(Level.INFO, "PSSRNF_CSPNSJ1198", params6);
txt++;
}
}
}
// logger.info("returning from expanding netware directory");
logger.info("PSSRNF_CSPNSJ1199");
return sa_file_listing;
}
private String getModifiedDateFormat(String month, String date, String time) {
GregorianCalendar calendar = new GregorianCalendar(TimeZone
.getDefault());
calendar.set(Calendar.MONTH, getMonthCode(month));
calendar.set(Calendar.DATE, Integer.parseInt(date));
if (time.indexOf(":") != -1) {
int colonIndex = time.indexOf(":");
String hourStr = time.substring(0, colonIndex);
String minuteStr = time.substring(colonIndex + 1).trim();
calendar.set(Calendar.HOUR_OF_DAY, Integer.parseInt(hourStr));
calendar.set(Calendar.MINUTE, Integer.parseInt(minuteStr));
} else {
calendar.set(Calendar.YEAR, Integer.parseInt(time.trim()));
}
Date d = calendar.getTime();
SimpleDateFormat sdf = new SimpleDateFormat("MMM dd yy, hh:mm a");
sdf.setCalendar(new GregorianCalendar(TimeZone.getDefault()));
return sdf.format(d);
}
/* Checks if the machine type is Unix FTP or NetWare Ftp */
boolean getFTPType(String machname) {
FullFtpClient fc;
String ftpResponse;
String novellResponse = "NetWare";
boolean novellServer = false;
try {
fc = new FullFtpClient(machname, s_machine_encoding);
ftpResponse = fc.getResponseString();
fc.closeServer();
/* Verify if the server is a Unix FTP server
* or a Novell FTP Server
*/
if (ftpResponse.indexOf(novellResponse) != -1) {
novellServer = true;
} else {
novellServer = false;
}
} catch (Exception e) {
// logger.severe("getFTPType: Exception: "+e);
logger.log(Level.SEVERE, "PSSRNF_CSPNSJ1200", e);
}
return novellServer;
}
}
|