|
楼主 |
发表于 2003-4-7 09:34:43
|
显示全部楼层
2、把nas包下的Configuration 变为以下代码:
package nas;
import java.io.*;
import java.util.StringTokenizer;
import java.util.Vector;
import netline.nastools.nasUtilities;
public class Configuration
{
nasUtilities nu;
private String htmlPath;
private String stylePath;
private String imagePath;
private String javascriptPath;
private String dataPath;
private String npSqlPath;
private String npSqlDriver;
private String npSqlUser;
private String npSqlPass;
private String baseDC;
private String host;
private int quotaWarn;
private String default_encoding;
private boolean can_select_encoding;
private Vector available_encodings;
public Configuration()
{
nu = new nasUtilities();
htmlPath = null;
stylePath = null;
imagePath = null;
javascriptPath = null;
dataPath = null;
npSqlPath = null;
npSqlDriver = null;
npSqlUser = null;
npSqlPass = null;
baseDC = null;
host = null;
quotaWarn = -1;
default_encoding = "UTF-8";
can_select_encoding = false;
available_encodings = new Vector();
}
public void getSystemConfiguration()
throws Exception
{
File file = new File(System.getProperty("user.dir") + "/config/system.cfg");
if(!file.exists())
{
System.out.println("!ERR! " + nu.getDateAndTime() + " LOAD CONF -> COULDN'T FIND FILE --> system.cfg !!NOTHING WILL WORK!!");
}
FileReader filereader = new FileReader(file);
BufferedReader bufferedreader = new BufferedReader(filereader);
for(String s = ""; (s = bufferedreader.readLine()) != null;)
{
if(s.startsWith("HTML-SPO="))
{
htmlPath = seperateValue(s);
} else
if(s.startsWith("IMAGE-LINK="))
{
imagePath = seperateValue(s);
} else
if(s.startsWith("STYLESHEET-LINK="))
{
stylePath = seperateValue(s);
} else
if(s.startsWith("JAVASCRIPT-LINK="))
{
javascriptPath = seperateValue(s);
} else
if(s.startsWith("DATA-SRC="))
{
dataPath = seperateValue(s);
if(!(new File(dataPath)).isDirectory())
{
(new File(dataPath)).mkdir();
}
} else
if(s.startsWith("NP-PSQL-PATH="))
{
npSqlPath = seperateValue(s);
} else
if(s.startsWith("NP-SQL-DRIVER="))
{
npSqlDriver = seperateValue(s);
} else
if(s.startsWith("NP-PSQL-USER="))
{
npSqlUser = seperateValue(s);
} else
if(s.startsWith("NP-PSQL-PASS="))
{
npSqlPass = seperateValue(s);
} else
if(s.startsWith("DEFAULT-ENCODING"))
{
String s3 = seperateValue(s);
if(s3.toUpperCase().indexOf("AUTO") != -1)
{
default_encoding = System.getProperty("file.encoding");
} else
{
try
{
String s7 = new String("test".getBytes(), s3);
default_encoding = s3;
}
catch(UnsupportedEncodingException unsupportedencodingexception)
{
System.out.println("!ERR! No valid default encoding: " + s3 + ", use system default: " + System.getProperty("file.encoding"));
}
}
} else
if(s.startsWith("USER-CAN-SELECT-ENCODING"))
{
String s4 = seperateValue(s);
if(s4.trim().toUpperCase().equals("TRUE"))
{
can_select_encoding = true;
} else
{
can_select_encoding = false;
}
} else
if(s.startsWith("AVAILABLE-ENCODINGS") && can_select_encoding)
{
String s5 = seperateValue(s);
StringTokenizer stringtokenizer = new StringTokenizer(s5, ",");
boolean flag = false;
if(stringtokenizer.countTokens() >= 1)
{
while(stringtokenizer.hasMoreTokens())
{
String s8 = stringtokenizer.nextToken();
try
{
String s9 = new String("test".getBytes(), s8);
if(s8.equals(default_encoding))
{
available_encodings.insertElementAt(s8, 0);
flag = true;
} else
{
available_encodings.add(s8);
}
}
catch(UnsupportedEncodingException unsupportedencodingexception1)
{
System.out.println("!ERR! Ignore no valid encoding: " + s8);
}
}
}
if(!flag)
{
available_encodings.insertElementAt(default_encoding, 0);
}
}
}
try
{
File file1 = new File("/etc/openldap/ldap.conf");
if(!file1.exists())
{
System.out.println("!ERR! " + nu.getDateAndTime() + " LOAD CONF -> COULDN'T FIND FILE --> /etc/openldap/ldap.conf !!LDAP-FUNCTIONS WI" +
"LL NOT WORK!!"
);
} else
{
filereader = new FileReader(file1);
bufferedreader = new BufferedReader(filereader);
for(String s1 = ""; (s1 = bufferedreader.readLine()) != null;)
{
if(s1.toUpperCase().startsWith("BASE"))
{
baseDC = s1.substring(5, s1.length()).trim();
} else
if(s1.toUpperCase().startsWith("HOST"))
{
host = s1.substring(5, s1.length()).trim();
}
}
}
}
catch(Exception exception)
{
System.out.println("!ERR! Configuration / getSystemConfiguration -> COULDN'T GET BASE-DC --> " + exception.getMessage());
}
try
{
File file2 = new File("/etc/imapd.conf");
if(file2.exists())
{
filereader = new FileReader(file2);
bufferedreader = new BufferedReader(filereader);
for(String s2 = ""; (s2 = bufferedreader.readLine()) != null;)
{
if(s2.toUpperCase().startsWith("QUOTAWARN:"))
{
String s6 = s2.substring(11, s2.length()).trim();
try
{
quotaWarn = (new Integer(s6)).intValue();
}
catch(NumberFormatException numberformatexception) { }
}
}
}
}
catch(Exception exception1)
{
System.out.println("!ERR! Configuration / getSystemConfiguration -> COULDN'T GET QUOTA-WARN --> " + exception1.getMessage());
}
bufferedreader.close();
filereader.close();
}
public String getBaseDC()
{
return baseDC;
}
public String getHost()
{
return host;
}
public int getQuotaWarn()
{
return quotaWarn;
}
public String getHtmlSpo()
{
return htmlPath;
}
public String getStyleLink()
{
return stylePath;
}
public String getImageLink()
{
return imagePath;
}
public String getJavascriptLink()
{
return javascriptPath;
}
public String getDataSrc()
{
return dataPath;
}
private String seperateValue(String s)
{
try
{
if(s.indexOf("=") != -1)
{
return s.substring(s.indexOf("\"") + 1, s.lastIndexOf("\""));
} else
{
return null;
}
}
catch(Exception exception)
{
System.out.println("!ERR! Configuration/readConfiguration -> err parsing line --> " + s);
}
return null;
}
public String getNpSqlPath()
{
return npSqlPath;
}
public String getNpSqlDriver()
{
return npSqlDriver;
}
public String getNpSqlUser()
{
return npSqlUser;
}
public String getNpSqlPass()
{
return npSqlPass;
}
public String getDefaultEncoding()
{
return default_encoding;
}
public boolean userCanSelectEncoding()
{
return can_select_encoding;
}
public Vector getAvailableEncodings()
{
return available_encodings;
}
} |
|