001: /*
002: * fopes
003: *
004: * Enhydra super-servlet
005: *
006: */
007:
008: package fops;
009:
010: import com.lutris.appserver.server.*;
011: import com.lutris.appserver.server.httpPresentation.*;
012: import com.lutris.appserver.server.session.*;
013: import com.lutris.logging.Logger;
014: import com.lutris.util.*;
015:
016: import java.io.*;
017:
018: /**
019: * The application object.
020: *
021: * Application-wide data would go here.
022: */
023: public class Fopes extends StandardApplication {
024:
025: File userConfigFile;
026:
027: protected String DEFAULT_FILE = "userconfig.xml";
028: protected String FOP_BASE_DIR = "Config";
029:
030: String fopBaseDir;
031:
032: /*
033: * A few methods you might want to add to.
034: * See StandardApplication for more details.
035: */
036: public void startup(Config appConfig) throws ApplicationException {
037: super .startup(appConfig);
038:
039: if (logChannel != null) {
040: logChannel.write(Logger.INFO,
041: "Welcome to FopApplet Enhydra Application!");
042: }
043:
044: // Here is where you would read application-specific settings from
045: // your config file.
046:
047: String tempString = null;
048: String file = null;
049: File tempFile = null;
050:
051: // FopBaseDir parameter initialization
052:
053: try {
054: fopBaseDir = appConfig.getString("FopBaseDir");
055: tempFile = new File(fopBaseDir + File.separator
056: + FOP_BASE_DIR);
057: if (!tempFile.exists() || !tempFile.isDirectory()) {
058: // in case a relative path is given (relative from configuration file)
059: tempString = appConfig.getConfigFile().getFile()
060: .getParent();
061: fopBaseDir = tempString + File.separator + fopBaseDir;
062: tempFile = new File(fopBaseDir + File.separator
063: + FOP_BASE_DIR);
064:
065: if (!tempFile.exists() || !tempFile.isDirectory()) {
066: fopBaseDir = null;
067: if (logChannel != null) {
068: logChannel
069: .write(
070: Logger.INFO,
071: "FopBaseDir application parameter not initialized - will be red from UserConfigFile!");
072: }
073: }
074: }
075: } catch (ConfigException e) {
076: fopBaseDir = null;
077: if (logChannel != null) {
078: logChannel
079: .write(
080: Logger.INFO,
081: "FopBaseDir application parameter not initialized - will be red from UserConfigFile!");
082: }
083: }
084:
085: // UserConfigFilePath parameter initialization
086:
087: try {
088: file = appConfig.getString("UserConfigFilePath");
089: userConfigFile = new File(file);
090:
091: if (!userConfigFile.exists()) {
092: // in case a relative path is given (relative from configuration file)
093: tempString = appConfig.getConfigFile().getFile()
094: .getParent();
095: file = tempString + File.separator + file;
096: userConfigFile = new File(file);
097:
098: if (!userConfigFile.exists()) {
099: try {
100: tempString = this .getClass().getClassLoader()
101: .getResource(DEFAULT_FILE).getPath();
102: file = tempString;
103: userConfigFile = new File(file);
104: } catch (NullPointerException exc) {
105: file = DEFAULT_FILE;
106: userConfigFile = new File(file);
107: if (logChannel != null) {
108: logChannel
109: .write(Logger.INFO,
110: "UserConfigFilePath application parameter isn't properly initialized!");
111: }
112: }
113: }
114: }
115: } catch (ConfigException e) {
116: try {
117: tempString = this .getClass().getClassLoader()
118: .getResource(DEFAULT_FILE).getPath();
119: file = tempString;
120: userConfigFile = new File(file);
121: } catch (NullPointerException exc) {
122: file = DEFAULT_FILE;
123: userConfigFile = new File(file);
124: if (logChannel != null) {
125: logChannel
126: .write(Logger.INFO,
127: "UserConfigFilePath application parameter isn't properly initialized!");
128: }
129: }
130: }
131:
132: }
133:
134: public boolean requestPreprocessor(HttpPresentationComms comms)
135: throws Exception {
136: return super .requestPreprocessor(comms);
137: }
138:
139: /**
140: * This is an optional function, used only by the Multiserver's graphical
141: * administration. This bit of HTML appears in the status page for this
142: * application. You could add extra status info, for example
143: * a list of currently logged in users.
144: *
145: * @return HTML that is displayed in the status page of the Multiserver.
146: */
147: public String toHtml() {
148: return "This is <I>fopes</I>";
149: }
150:
151: public File getUserConfigFile() {
152: return userConfigFile;
153: }
154:
155: public String getFopBaseDir() {
156: return fopBaseDir;
157: }
158: }
|