Splitt out configuration to external context file
This commit is contained in:
parent
300ce27c07
commit
7390cb8b7a
4 changed files with 100 additions and 115 deletions
3
.gitignore
vendored
Normal file → Executable file
3
.gitignore
vendored
Normal file → Executable file
|
|
@ -1,5 +1,2 @@
|
||||||
/build
|
/build
|
||||||
/WebContent/WEB-INF/web.xml
|
|
||||||
/WebContent/WEB-INF/web_debug.xml
|
|
||||||
/WebContent/WEB-INF/web_server.xml
|
|
||||||
/WebContent/WEB-INF/lib/Zutil.jar
|
/WebContent/WEB-INF/lib/Zutil.jar
|
||||||
11
WebContent/WEB-INF/context.sample.xml
Executable file
11
WebContent/WEB-INF/context.sample.xml
Executable file
|
|
@ -0,0 +1,11 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<Context>
|
||||||
|
|
||||||
|
<Environment type="java.lang.String" name="WEBSITE_NAME" value="Gallery" />
|
||||||
|
<Environment type="java.lang.String" name="WEBSITE_URL" value="http://example.com/zallery/" />
|
||||||
|
<Environment type="java.lang.String" name="SMTP_HOST" value="127.0.0.1" />
|
||||||
|
<Environment type="java.lang.String" name="DATA_PATH" value="C:\\data" />
|
||||||
|
|
||||||
|
</Context>
|
||||||
|
|
||||||
|
|
||||||
160
WebContent/WEB-INF/web_sample.xml → WebContent/WEB-INF/web.xml
Normal file → Executable file
160
WebContent/WEB-INF/web_sample.xml → WebContent/WEB-INF/web.xml
Normal file → Executable file
|
|
@ -1,91 +1,71 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
|
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
<display-name>Zallery</display-name>
|
xmlns="http://java.sun.com/xml/ns/javaee"
|
||||||
|
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
|
||||||
<welcome-file-list>
|
id="WebApp_ID" version="2.5">
|
||||||
<welcome-file>gallery</welcome-file>
|
<display-name>Zallery</display-name>
|
||||||
</welcome-file-list>
|
|
||||||
|
|
||||||
<servlet>
|
<servlet>
|
||||||
<servlet-name>Zallery</servlet-name>
|
<servlet-name>Zallery</servlet-name>
|
||||||
<servlet-class>zall.Zallery</servlet-class>
|
<servlet-class>zall.Zallery</servlet-class>
|
||||||
<init-param>
|
<load-on-startup>1</load-on-startup>
|
||||||
<param-name>WEBSITE_NAME</param-name>
|
</servlet>
|
||||||
<param-value>Gallery</param-value>
|
<servlet-mapping>
|
||||||
</init-param>
|
<servlet-name>Zallery</servlet-name>
|
||||||
<init-param>
|
<url-pattern>/gallery</url-pattern>
|
||||||
<param-name>WEBSITE_URL</param-name>
|
<url-pattern>/media</url-pattern>
|
||||||
<param-value>http://example.com/Zallery/</param-value>
|
<url-pattern>/slideshow</url-pattern>
|
||||||
</init-param>
|
<url-pattern>/login</url-pattern>
|
||||||
<init-param>
|
<url-pattern>/logout</url-pattern>
|
||||||
<param-name>SMTP_HOST</param-name>
|
<url-pattern>/upload</url-pattern>
|
||||||
<param-value>127.0.0.1</param-value>
|
<url-pattern>/profile</url-pattern>
|
||||||
</init-param>
|
<url-pattern>/users</url-pattern>
|
||||||
<init-param>
|
<url-pattern>/register</url-pattern>
|
||||||
<param-name>THEME</param-name>
|
</servlet-mapping>
|
||||||
<param-value></param-value>
|
|
||||||
</init-param>
|
<servlet>
|
||||||
<init-param>
|
<servlet-name>Content</servlet-name>
|
||||||
<param-name>DATA_PATH</param-name>
|
<servlet-class>zall.ZalleryContent</servlet-class>
|
||||||
<param-value>C:\\data</param-value>
|
</servlet>
|
||||||
</init-param>
|
<servlet-mapping>
|
||||||
<load-on-startup>1</load-on-startup>
|
<servlet-name>Content</servlet-name>
|
||||||
</servlet>
|
<url-pattern>/content</url-pattern>
|
||||||
<servlet-mapping>
|
</servlet-mapping>
|
||||||
<servlet-name>Zallery</servlet-name>
|
|
||||||
<url-pattern>/gallery</url-pattern>
|
<servlet>
|
||||||
<url-pattern>/media</url-pattern>
|
<servlet-name>Ajax</servlet-name>
|
||||||
<url-pattern>/slideshow</url-pattern>
|
<servlet-class>zall.ZalleryAjax</servlet-class>
|
||||||
<url-pattern>/login</url-pattern>
|
</servlet>
|
||||||
<url-pattern>/logout</url-pattern>
|
<servlet-mapping>
|
||||||
<url-pattern>/upload</url-pattern>
|
<servlet-name>Ajax</servlet-name>
|
||||||
<url-pattern>/profile</url-pattern>
|
<url-pattern>/ajax</url-pattern>
|
||||||
<url-pattern>/users</url-pattern>
|
</servlet-mapping>
|
||||||
<url-pattern>/register</url-pattern>
|
|
||||||
</servlet-mapping>
|
<servlet>
|
||||||
|
<servlet-name>Upload</servlet-name>
|
||||||
<servlet>
|
<servlet-class>zall.UploadServlet</servlet-class>
|
||||||
<servlet-name>Content</servlet-name>
|
<init-param>
|
||||||
<servlet-class>zall.ZalleryContent</servlet-class>
|
<param-name>TEMP_PATH</param-name>
|
||||||
</servlet>
|
<param-value>SYSTEM</param-value>
|
||||||
<servlet-mapping>
|
</init-param>
|
||||||
<servlet-name>Content</servlet-name>
|
<init-param>
|
||||||
<url-pattern>/content</url-pattern>
|
<param-name>ALLOWED_EXTENSIONS</param-name>
|
||||||
</servlet-mapping>
|
<param-value>png,jpg,jpeg,gif,tif,bmp,avi,wmv,mov,mp4,mpeg,flv,m4v,divx,xvid</param-value>
|
||||||
|
</init-param>
|
||||||
<servlet>
|
</servlet>
|
||||||
<servlet-name>Ajax</servlet-name>
|
<servlet-mapping>
|
||||||
<servlet-class>zall.ZalleryAjax</servlet-class>
|
<servlet-name>Upload</servlet-name>
|
||||||
</servlet>
|
<url-pattern>/uploadserv</url-pattern>
|
||||||
<servlet-mapping>
|
</servlet-mapping>
|
||||||
<servlet-name>Ajax</servlet-name>
|
|
||||||
<url-pattern>/ajax</url-pattern>
|
<servlet>
|
||||||
</servlet-mapping>
|
<servlet-name>transcoder</servlet-name>
|
||||||
|
<servlet-class>zall.ZalleryTranscoder</servlet-class>
|
||||||
<servlet>
|
<load-on-startup>1</load-on-startup>
|
||||||
<servlet-name>Upload</servlet-name>
|
</servlet>
|
||||||
<servlet-class>zall.UploadServlet</servlet-class>
|
|
||||||
<init-param>
|
<welcome-file-list>
|
||||||
<param-name>TEMP_PATH</param-name>
|
<welcome-file>gallery</welcome-file>
|
||||||
<param-value>C:\\temp</param-value>
|
</welcome-file-list>
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ALLOWED_EXTENSIONS</param-name>
|
|
||||||
<param-value>png,jpg,jpeg,gif,tif,bmp,avi,wmv,mov,mp4,mpeg,flv,m4v,divx,xvid</param-value>
|
|
||||||
</init-param>
|
|
||||||
</servlet>
|
|
||||||
<servlet-mapping>
|
|
||||||
<servlet-name>Upload</servlet-name>
|
|
||||||
<url-pattern>/uploadserv</url-pattern>
|
|
||||||
</servlet-mapping>
|
|
||||||
|
|
||||||
<servlet>
|
|
||||||
<servlet-name>transcoder</servlet-name>
|
|
||||||
<servlet-class>zall.ZalleryTranscoder</servlet-class>
|
|
||||||
<load-on-startup>1</load-on-startup>
|
|
||||||
</servlet>
|
|
||||||
|
|
||||||
<welcome-file-list>
|
|
||||||
<welcome-file>gallery</welcome-file>
|
|
||||||
</welcome-file-list>
|
|
||||||
</web-app>
|
</web-app>
|
||||||
41
src/zall/Zallery.java
Normal file → Executable file
41
src/zall/Zallery.java
Normal file → Executable file
|
|
@ -6,6 +6,9 @@ import java.util.List;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import javax.naming.Context;
|
||||||
|
import javax.naming.InitialContext;
|
||||||
|
import javax.naming.NamingException;
|
||||||
import javax.servlet.RequestDispatcher;
|
import javax.servlet.RequestDispatcher;
|
||||||
import javax.servlet.ServletConfig;
|
import javax.servlet.ServletConfig;
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
|
|
@ -31,7 +34,6 @@ public class Zallery extends HttpServlet{
|
||||||
|
|
||||||
public static String WEBSITE_NAME = "Example.com";
|
public static String WEBSITE_NAME = "Example.com";
|
||||||
public static String WEBSITE_URL = "http://example.com";
|
public static String WEBSITE_URL = "http://example.com";
|
||||||
public static String THEME = "";
|
|
||||||
public static String ROOT_PATH = "";
|
public static String ROOT_PATH = "";
|
||||||
public static String DATA_PATH = "";
|
public static String DATA_PATH = "";
|
||||||
|
|
||||||
|
|
@ -41,30 +43,25 @@ public class Zallery extends HttpServlet{
|
||||||
* <br>- WEBSITE_URL
|
* <br>- WEBSITE_URL
|
||||||
* <br>- SMTP_HOST
|
* <br>- SMTP_HOST
|
||||||
* <br>- DATA_PATH
|
* <br>- DATA_PATH
|
||||||
* <br>- THEME
|
|
||||||
* <br>- FB_APPID
|
|
||||||
* <br>- FB_APPSEC
|
|
||||||
*/
|
*/
|
||||||
public void init(ServletConfig config) throws ServletException {
|
public void init(ServletConfig config) throws ServletException {
|
||||||
super.init(config);
|
super.init(config);
|
||||||
|
// java:comp/env
|
||||||
ROOT_PATH = config.getServletContext().getRealPath("/");
|
ROOT_PATH = config.getServletContext().getRealPath("/");
|
||||||
if( config.getInitParameter("WEBSITE_NAME") != null )
|
try {
|
||||||
WEBSITE_NAME = config.getInitParameter("WEBSITE_NAME");
|
Context context = new InitialContext();
|
||||||
if( config.getInitParameter("WEBSITE_URL") != null ){
|
WEBSITE_NAME = (String)context.lookup("java:comp/env/WEBSITE_NAME");
|
||||||
WEBSITE_URL = config.getInitParameter("WEBSITE_URL");
|
WEBSITE_URL = (String)context.lookup("java:comp/env/WEBSITE_URL");
|
||||||
if( WEBSITE_URL.charAt(WEBSITE_URL.length()-1) != '/')
|
if( WEBSITE_URL.charAt(WEBSITE_URL.length()-1) != '/')
|
||||||
WEBSITE_URL += "/";
|
WEBSITE_URL += "/";
|
||||||
}
|
Email.setServer( (String)context.lookup("java:comp/env/SMTP_HOST") );
|
||||||
if( config.getInitParameter("SMTP_HOST") != null )
|
DATA_PATH = (String)context.lookup("java:comp/env/DATA_PATH");
|
||||||
Email.setServer( config.getInitParameter("SMTP_HOST") );
|
|
||||||
if( config.getInitParameter("DATA_PATH") != null )
|
LogUtil.setLevel("zall", Level.FINEST);
|
||||||
DATA_PATH = config.getInitParameter("DATA_PATH");
|
//LogUtil.setLevel("zutil", Level.FINEST);
|
||||||
else
|
} catch (NamingException e) {
|
||||||
throw new ServletException("Missing DATA_PATH parameter!");
|
throw new ServletException(e);
|
||||||
if( config.getInitParameter("THEME") != null )
|
}
|
||||||
THEME = config.getInitParameter("THEME");
|
|
||||||
LogUtil.setLevel("zall", Level.FINEST);
|
|
||||||
//LogUtil.setLevel("zutil", Level.FINEST);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void destroy(){
|
public void destroy(){
|
||||||
|
|
@ -272,7 +269,7 @@ public class Zallery extends HttpServlet{
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void include(String url, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
|
protected void include(String url, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
|
||||||
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(THEME+"/"+url);
|
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/"+url);
|
||||||
if (dispatcher != null)
|
if (dispatcher != null)
|
||||||
dispatcher.include(request, response);
|
dispatcher.include(request, response);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue