2012-06-13 17:59:22 +00:00
|
|
|
package zall;
|
|
|
|
|
|
|
|
|
|
import java.util.logging.Level;
|
|
|
|
|
import java.util.logging.Logger;
|
|
|
|
|
|
2016-12-20 16:53:03 +01:00
|
|
|
import javax.naming.Context;
|
|
|
|
|
import javax.naming.InitialContext;
|
|
|
|
|
import javax.naming.NamingException;
|
2012-06-13 17:59:22 +00:00
|
|
|
import javax.servlet.ServletConfig;
|
|
|
|
|
import javax.servlet.ServletException;
|
2018-07-26 16:23:01 +02:00
|
|
|
import javax.servlet.annotation.WebServlet;
|
2012-06-13 17:59:22 +00:00
|
|
|
import javax.servlet.http.Cookie;
|
|
|
|
|
import javax.servlet.http.HttpServlet;
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
|
|
|
|
|
import zutil.db.DBConnection;
|
|
|
|
|
import zutil.log.LogUtil;
|
|
|
|
|
|
2018-07-26 16:23:01 +02:00
|
|
|
@WebServlet(value = "/init", loadOnStartup = 1)
|
2012-06-13 17:59:22 +00:00
|
|
|
public class Zallery extends HttpServlet{
|
2017-10-19 15:46:38 +02:00
|
|
|
private static Logger logger = LogUtil.getLogger();
|
|
|
|
|
|
2018-07-25 15:41:29 +02:00
|
|
|
public static final String VERSION = "2.0.0";
|
2017-10-19 15:46:38 +02:00
|
|
|
|
2018-07-25 15:41:29 +02:00
|
|
|
public static String WEBSITE_NAME = "";
|
|
|
|
|
public static String WEBSITE_URL = "";
|
2018-07-25 15:46:44 +02:00
|
|
|
public static String ADMIN_EMAIL = "";
|
|
|
|
|
public static String ADMIN_EMAIL_NICE = "";
|
2018-07-25 15:41:29 +02:00
|
|
|
public static String SMTP_HOST = "";
|
2017-10-19 15:46:38 +02:00
|
|
|
public static String ROOT_PATH = "";
|
|
|
|
|
public static String DATA_PATH = "";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Config Options:
|
|
|
|
|
* <br>- WEBSITE_NAME
|
|
|
|
|
* <br>- WEBSITE_URL
|
|
|
|
|
* <br>- SMTP_HOST
|
|
|
|
|
* <br>- DATA_PATH
|
|
|
|
|
*/
|
|
|
|
|
public void init(ServletConfig config) throws ServletException {
|
|
|
|
|
super.init(config);
|
|
|
|
|
// java:comp/env
|
|
|
|
|
ROOT_PATH = config.getServletContext().getRealPath("/");
|
2016-12-20 16:53:03 +01:00
|
|
|
try {
|
|
|
|
|
Context context = new InitialContext();
|
2017-08-03 11:06:30 +02:00
|
|
|
// Check if Zallery has been properly configured
|
2018-07-25 15:41:29 +02:00
|
|
|
if ("PATH TO DATA FOLDER".equals(context.lookup("java:comp/env/DATA_PATH")))
|
2017-10-19 15:46:38 +02:00
|
|
|
throw new ServletException("Zallery has not been properly configured, set proper configuration in Zallery.xml context file.");
|
2017-08-03 11:06:30 +02:00
|
|
|
|
2018-07-25 15:46:44 +02:00
|
|
|
WEBSITE_NAME = (String)context.lookup("java:comp/env/WEBSITE_NAME");
|
|
|
|
|
WEBSITE_URL = (String)context.lookup("java:comp/env/WEBSITE_URL");
|
2016-12-20 16:53:03 +01:00
|
|
|
if( WEBSITE_URL.charAt(WEBSITE_URL.length()-1) != '/')
|
|
|
|
|
WEBSITE_URL += "/";
|
2018-07-25 15:36:57 +02:00
|
|
|
|
2018-07-25 15:46:44 +02:00
|
|
|
ADMIN_EMAIL = (String)context.lookup("java:comp/env/ADMIN_EMAIL");
|
|
|
|
|
ADMIN_EMAIL_NICE = (String)context.lookup("java:comp/env/ADMIN_EMAIL_NICE");
|
|
|
|
|
SMTP_HOST = (String)context.lookup("java:comp/env/SMTP_HOST");
|
|
|
|
|
DATA_PATH = (String)context.lookup("java:comp/env/DATA_PATH");
|
2016-12-20 16:53:03 +01:00
|
|
|
|
|
|
|
|
LogUtil.setLevel("zall", Level.FINEST);
|
|
|
|
|
//LogUtil.setLevel("zutil", Level.FINEST);
|
|
|
|
|
} catch (NamingException e) {
|
|
|
|
|
throw new ServletException(e);
|
|
|
|
|
}
|
2017-10-19 15:46:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void destroy(){
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static DBConnection getDB() throws ServletException{
|
|
|
|
|
try {
|
|
|
|
|
return new DBConnection("jdbc/mysql");
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
throw new ServletException(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-13 17:59:22 +00:00
|
|
|
}
|