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;
|
|
|
|
|
import javax.servlet.http.Cookie;
|
|
|
|
|
import javax.servlet.http.HttpServlet;
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
|
2016-12-22 16:24:46 +01:00
|
|
|
import zall.util.ZalleryEmail;
|
2012-06-13 17:59:22 +00:00
|
|
|
import zutil.db.DBConnection;
|
|
|
|
|
import zutil.log.LogUtil;
|
|
|
|
|
|
|
|
|
|
public class Zallery extends HttpServlet{
|
2017-10-19 15:46:38 +02:00
|
|
|
private static Logger logger = LogUtil.getLogger();
|
|
|
|
|
|
|
|
|
|
public static final String VERSION = "1.0.2";
|
|
|
|
|
|
|
|
|
|
public static String WEBSITE_NAME = "Example.com";
|
|
|
|
|
public static String WEBSITE_URL = "http://example.com";
|
2018-07-25 15:36:57 +02:00
|
|
|
public static String WEBSITE_EMAIL = "admin@example.com";
|
|
|
|
|
public static String WEBSITE_EMAIL_NICE = "Example.com Admin";
|
|
|
|
|
public static String SMTP_HOST = "localhost";
|
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
|
2017-10-19 15:46:38 +02:00
|
|
|
if ("C:\\\\data".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.");
|
2017-08-03 11:06:30 +02:00
|
|
|
|
2018-07-25 15:36:57 +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
|
|
|
|
|
|
|
|
WEBSITE_EMAIL = (String)context.lookup("java:comp/env/WEBSITE_EMAIL");
|
|
|
|
|
WEBSITE_EMAIL_NICE = (String)context.lookup("java:comp/env/WEBSITE_EMAIL_NICE");
|
|
|
|
|
SMTP_HOST = (String)context.lookup("java:comp/env/WEBSITE_EMAIL_NICE");
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static String getCookieValue(Cookie[] cookies, String name) {
|
|
|
|
|
if( cookies == null )
|
|
|
|
|
return null;
|
|
|
|
|
for(Cookie cookie : cookies) {
|
|
|
|
|
if ( name.equals(cookie.getName()) )
|
|
|
|
|
return cookie.getValue();
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static String getWebsiteName() {
|
|
|
|
|
return WEBSITE_NAME;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static String getWebsiteURL() {
|
|
|
|
|
return WEBSITE_URL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// /mywebapp/servlet/MyServlet/a/b;c=123?d=789
|
|
|
|
|
public static String getUrl(HttpServletRequest req) {
|
|
|
|
|
String reqUri = req.getRequestURI().toString();
|
|
|
|
|
String queryString = req.getQueryString(); // d=789
|
|
|
|
|
if (queryString != null) {
|
|
|
|
|
reqUri += "?"+queryString;
|
|
|
|
|
}
|
|
|
|
|
return reqUri;
|
|
|
|
|
}
|
2012-06-13 17:59:22 +00:00
|
|
|
}
|