home *** CD-ROM | disk | FTP | other *** search
- package lotus.domino.servlet;
-
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.IOException;
- import java.text.SimpleDateFormat;
- import java.util.Date;
- import java.util.Enumeration;
- import java.util.Hashtable;
- import java.util.Properties;
- import java.util.StringTokenizer;
- import javax.servlet.Servlet;
-
- public class ServletManager {
- private ServletManagerConfig i_config;
- private Hashtable i_invokerTable;
- protected static Hashtable c_servletTable = new Hashtable();
- protected static DominoSessionContext c_sessionContext;
- private StringListTable i_serviceTable;
- private Hashtable i_ssiTable;
- private String i_errorLog;
- private String i_configFilename;
- protected static String c_configPath;
- protected static Properties c_servletManagerProps = new Properties();
- public static final boolean debugOutput = false;
-
- private void loadNewConfiguration(String var1, String var2) {
- this.unloadConfiguration();
- this.i_config = new ServletManagerConfig();
- this.i_config.initialize(var1, var2);
- c_sessionContext = new DominoSessionContext();
- this.i_serviceTable = this.i_config.getServiceTable();
- this.i_ssiTable = this.i_config.getSSITable();
- this.i_invokerTable = this.i_config.getInvokerTable();
- }
-
- private void unloadConfiguration() {
- this.destroyServlets();
- }
-
- public static Hashtable getServletTable() {
- return c_servletTable;
- }
-
- public static DominoSessionContext getSessionContext() {
- return c_sessionContext;
- }
-
- public static String getConfigPath() {
- return c_configPath;
- }
-
- public static boolean getBoolProp(String var0, boolean var1) {
- String var2 = c_servletManagerProps.getProperty(var0);
- return var2 != null ? var2.equals("true") : var1;
- }
-
- public static long getLongProp(String var0, long var1) {
- String var3 = c_servletManagerProps.getProperty(var0);
- long var4 = var1;
- if (var3 != null && var3.trim().length() > 0) {
- try {
- var4 = Long.parseLong(var3);
- } catch (NumberFormatException var6) {
- }
- }
-
- return var4;
- }
-
- public static int getIntProp(String var0, int var1) {
- String var2 = c_servletManagerProps.getProperty(var0);
- int var3 = var1;
- if (var2 != null && var2.trim().length() > 0) {
- try {
- var3 = Integer.parseInt(var2);
- } catch (NumberFormatException var4) {
- }
- }
-
- return var3;
- }
-
- private void destroyServlets() {
- if (this.i_invokerTable != null) {
- Enumeration var1 = this.i_invokerTable.elements();
-
- while(var1.hasMoreElements()) {
- DominoServletInvoker var2 = (DominoServletInvoker)var1.nextElement();
- var2.destroy();
- }
- }
-
- }
-
- public int invokeSSI() {
- try {
- String var1 = NativeStub.extract("SERVLET_NAME");
- if (var1 == null) {
- return 500;
- } else {
- DominoServletInvoker var2 = (DominoServletInvoker)this.i_ssiTable.get(var1);
- return var2 == null ? 0 : var2.invokeSSI();
- }
- } catch (Throwable var3) {
- var3.printStackTrace(System.err);
- return 500;
- }
- }
-
- public int serverInit() {
- try {
- System.getProperty("os.name");
- String var1 = (new SimpleDateFormat("MMMddyyyy")).format(new Date());
- String var2 = System.getProperty("file.separator");
- String var3 = NativeStub.extract("SERVER_ROOT") + var2;
- this.i_configFilename = NativeStub.extract("INIT_STRING");
- if (File.separatorChar == '\\') {
- this.i_configFilename = this.i_configFilename.replace('/', '\\');
- }
-
- if (this.i_configFilename.equals("")) {
- this.i_configFilename = "servlet.cnf";
- System.err.println("Servlet initialization warning: no configuration filename was given so will assume it is " + this.i_configFilename);
- }
-
- if (this.i_configFilename.indexOf("/") == -1 && this.i_configFilename.indexOf("\\") == -1) {
- String var4 = NativeStub.extract("CONFIG_PATH");
- this.i_configFilename = var4 + this.i_configFilename;
- }
-
- this.i_errorLog = var3 + var2 + "servlet-log." + var1;
- NativeStub.set("SERVLET_LOG", this.i_errorLog);
- File var9 = new File(this.i_configFilename);
- if (!var9.exists()) {
- NativeStub.log_error("Servlet Initialization error: servlet configuration file (" + this.i_configFilename + ") does not exist");
- System.err.println(this.i_configFilename + " is not a valid configuration file, it doesn't exist");
- return 500;
- } else if (!var9.isFile()) {
- NativeStub.log_error("Servlet Initialization error: " + this.i_configFilename + "is not a valid configuration file");
- System.err.println(this.i_configFilename + " is not a valid configuration file, it's a directory");
- return 500;
- } else if (!var9.canRead()) {
- NativeStub.log_error("Servlet Initialization error: " + this.i_configFilename + "is not readable, check permissions");
- System.err.println("Server does not have read permissions to configuration file: " + this.i_configFilename);
- return 500;
- } else {
- c_configPath = var9.getParent();
- String var5 = c_configPath + "/" + "domino.properties";
-
- try {
- FileInputStream var6 = new FileInputStream(var5);
- c_servletManagerProps.load(var6);
- var6.close();
- } catch (IOException var7) {
- }
-
- this.loadNewConfiguration(this.i_configFilename, this.i_errorLog);
- return 200;
- }
- } catch (Throwable var8) {
- System.err.println("Exception was thrown during Server Initialization:");
- var8.printStackTrace(System.err);
- return 500;
- }
- }
-
- public int service() {
- int var1 = 0;
- Object var2 = null;
- Object var3 = null;
- Object var4 = null;
-
- try {
- String var5 = NativeStub.extract("SCRIPT_NAME");
- String var9 = this.i_serviceTable.get(var5);
- if (var9 == null) {
- System.err.println("Servlet Error: No servlet maps to " + var5);
- return 0;
- }
-
- NativeStub.set("CONTENT_TYPE", "text/html");
-
- for(StringTokenizer var6 = new StringTokenizer(var9, ","); var6.hasMoreTokens() && var1 == 0; var1 = var10.service()) {
- String var8 = var6.nextToken();
- var10 = (DominoServletInvoker)this.i_invokerTable.get(var8);
- if (var10 == null) {
- NativeStub.log_error("Servlet Error: couldn't find Servlet " + var8);
- return 500;
- }
- }
- } catch (Throwable var7) {
- NativeStub.log_error(var7.toString());
- System.err.println("Error in Servlet " + var2 + " while executing service function");
- var7.printStackTrace(System.err);
- return 500;
- }
-
- if (var1 == 0) {
- var1 = 200;
- }
-
- return var1;
- }
-
- public int serverTerm() {
- Enumeration var1 = c_servletTable.elements();
-
- while(var1.hasMoreElements()) {
- Servlet var2 = (Servlet)var1.nextElement();
- var2.destroy();
- }
-
- c_sessionContext.terminate();
- return 200;
- }
- }
-