zallery/src/zall/Zallery.java

114 lines
3.6 KiB
Java
Raw Normal View History

2012-06-13 17:59:22 +00:00
package zall;
import java.io.File;
import java.io.IOException;
import java.util.List;
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.RequestDispatcher;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import zall.bean.Folder;
import zall.bean.Image;
import zall.bean.Media;
import zall.bean.User;
import zall.manager.AuthenticationManager;
import zall.util.ZalleryEmail;
2018-07-23 16:55:28 +02:00
import zall.util.UserMessage;
import zall.util.UserMessage.MessageType;
2012-06-13 17:59:22 +00:00
import zutil.db.DBConnection;
import zutil.log.LogUtil;
public class Zallery extends HttpServlet{
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";
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
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.");
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 += "/";
ZalleryEmail.setSMTPHost( (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);
}
}
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
}