zallery/src/zall/Zallery.java

80 lines
2.7 KiB
Java
Raw Normal View History

2012-06-13 17:59:22 +00:00
package zall;
import java.util.logging.Level;
import java.util.logging.Logger;
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;
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;
@WebServlet(value = "/init", loadOnStartup = 1)
2012-06-13 17:59:22 +00:00
public class Zallery extends HttpServlet{
private static Logger logger = LogUtil.getLogger();
2018-07-25 15:41:29 +02:00
public static final String VERSION = "2.0.0";
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 = "";
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("/");
try {
Context context = new InitialContext();
// 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")))
throw new ServletException("Zallery has not been properly configured, set proper configuration in Zallery.xml context file.");
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");
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");
LogUtil.setLevel("zall", Level.FINEST);
//LogUtil.setLevel("zutil", Level.FINEST);
} catch (NamingException e) {
throw new ServletException(e);
}
}
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
}