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
|
||||
/WebContent/WEB-INF/web.xml
|
||||
/WebContent/WEB-INF/web_debug.xml
|
||||
/WebContent/WEB-INF/web_server.xml
|
||||
/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"?>
|
||||
<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">
|
||||
<display-name>Zallery</display-name>
|
||||
|
||||
<welcome-file-list>
|
||||
<welcome-file>gallery</welcome-file>
|
||||
</welcome-file-list>
|
||||
|
||||
<servlet>
|
||||
<servlet-name>Zallery</servlet-name>
|
||||
<servlet-class>zall.Zallery</servlet-class>
|
||||
<init-param>
|
||||
<param-name>WEBSITE_NAME</param-name>
|
||||
<param-value>Gallery</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>WEBSITE_URL</param-name>
|
||||
<param-value>http://example.com/Zallery/</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>SMTP_HOST</param-name>
|
||||
<param-value>127.0.0.1</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>THEME</param-name>
|
||||
<param-value></param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>DATA_PATH</param-name>
|
||||
<param-value>C:\\data</param-value>
|
||||
</init-param>
|
||||
<load-on-startup>1</load-on-startup>
|
||||
</servlet>
|
||||
<servlet-mapping>
|
||||
<servlet-name>Zallery</servlet-name>
|
||||
<url-pattern>/gallery</url-pattern>
|
||||
<url-pattern>/media</url-pattern>
|
||||
<url-pattern>/slideshow</url-pattern>
|
||||
<url-pattern>/login</url-pattern>
|
||||
<url-pattern>/logout</url-pattern>
|
||||
<url-pattern>/upload</url-pattern>
|
||||
<url-pattern>/profile</url-pattern>
|
||||
<url-pattern>/users</url-pattern>
|
||||
<url-pattern>/register</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
<servlet>
|
||||
<servlet-name>Content</servlet-name>
|
||||
<servlet-class>zall.ZalleryContent</servlet-class>
|
||||
</servlet>
|
||||
<servlet-mapping>
|
||||
<servlet-name>Content</servlet-name>
|
||||
<url-pattern>/content</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
<servlet>
|
||||
<servlet-name>Ajax</servlet-name>
|
||||
<servlet-class>zall.ZalleryAjax</servlet-class>
|
||||
</servlet>
|
||||
<servlet-mapping>
|
||||
<servlet-name>Ajax</servlet-name>
|
||||
<url-pattern>/ajax</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
<servlet>
|
||||
<servlet-name>Upload</servlet-name>
|
||||
<servlet-class>zall.UploadServlet</servlet-class>
|
||||
<init-param>
|
||||
<param-name>TEMP_PATH</param-name>
|
||||
<param-value>C:\\temp</param-value>
|
||||
</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>
|
||||
<?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"
|
||||
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">
|
||||
<display-name>Zallery</display-name>
|
||||
|
||||
|
||||
<servlet>
|
||||
<servlet-name>Zallery</servlet-name>
|
||||
<servlet-class>zall.Zallery</servlet-class>
|
||||
<load-on-startup>1</load-on-startup>
|
||||
</servlet>
|
||||
<servlet-mapping>
|
||||
<servlet-name>Zallery</servlet-name>
|
||||
<url-pattern>/gallery</url-pattern>
|
||||
<url-pattern>/media</url-pattern>
|
||||
<url-pattern>/slideshow</url-pattern>
|
||||
<url-pattern>/login</url-pattern>
|
||||
<url-pattern>/logout</url-pattern>
|
||||
<url-pattern>/upload</url-pattern>
|
||||
<url-pattern>/profile</url-pattern>
|
||||
<url-pattern>/users</url-pattern>
|
||||
<url-pattern>/register</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
<servlet>
|
||||
<servlet-name>Content</servlet-name>
|
||||
<servlet-class>zall.ZalleryContent</servlet-class>
|
||||
</servlet>
|
||||
<servlet-mapping>
|
||||
<servlet-name>Content</servlet-name>
|
||||
<url-pattern>/content</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
<servlet>
|
||||
<servlet-name>Ajax</servlet-name>
|
||||
<servlet-class>zall.ZalleryAjax</servlet-class>
|
||||
</servlet>
|
||||
<servlet-mapping>
|
||||
<servlet-name>Ajax</servlet-name>
|
||||
<url-pattern>/ajax</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
<servlet>
|
||||
<servlet-name>Upload</servlet-name>
|
||||
<servlet-class>zall.UploadServlet</servlet-class>
|
||||
<init-param>
|
||||
<param-name>TEMP_PATH</param-name>
|
||||
<param-value>SYSTEM</param-value>
|
||||
</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>
|
||||
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.Logger;
|
||||
|
||||
import javax.naming.Context;
|
||||
import javax.naming.InitialContext;
|
||||
import javax.naming.NamingException;
|
||||
import javax.servlet.RequestDispatcher;
|
||||
import javax.servlet.ServletConfig;
|
||||
import javax.servlet.ServletException;
|
||||
|
|
@ -31,7 +34,6 @@ public class Zallery extends HttpServlet{
|
|||
|
||||
public static String WEBSITE_NAME = "Example.com";
|
||||
public static String WEBSITE_URL = "http://example.com";
|
||||
public static String THEME = "";
|
||||
public static String ROOT_PATH = "";
|
||||
public static String DATA_PATH = "";
|
||||
|
||||
|
|
@ -41,30 +43,25 @@ public class Zallery extends HttpServlet{
|
|||
* <br>- WEBSITE_URL
|
||||
* <br>- SMTP_HOST
|
||||
* <br>- DATA_PATH
|
||||
* <br>- THEME
|
||||
* <br>- FB_APPID
|
||||
* <br>- FB_APPSEC
|
||||
*/
|
||||
public void init(ServletConfig config) throws ServletException {
|
||||
super.init(config);
|
||||
// java:comp/env
|
||||
ROOT_PATH = config.getServletContext().getRealPath("/");
|
||||
if( config.getInitParameter("WEBSITE_NAME") != null )
|
||||
WEBSITE_NAME = config.getInitParameter("WEBSITE_NAME");
|
||||
if( config.getInitParameter("WEBSITE_URL") != null ){
|
||||
WEBSITE_URL = config.getInitParameter("WEBSITE_URL");
|
||||
if( WEBSITE_URL.charAt(WEBSITE_URL.length()-1) != '/')
|
||||
WEBSITE_URL += "/";
|
||||
}
|
||||
if( config.getInitParameter("SMTP_HOST") != null )
|
||||
Email.setServer( config.getInitParameter("SMTP_HOST") );
|
||||
if( config.getInitParameter("DATA_PATH") != null )
|
||||
DATA_PATH = config.getInitParameter("DATA_PATH");
|
||||
else
|
||||
throw new ServletException("Missing DATA_PATH parameter!");
|
||||
if( config.getInitParameter("THEME") != null )
|
||||
THEME = config.getInitParameter("THEME");
|
||||
LogUtil.setLevel("zall", Level.FINEST);
|
||||
//LogUtil.setLevel("zutil", Level.FINEST);
|
||||
try {
|
||||
Context context = new InitialContext();
|
||||
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 += "/";
|
||||
Email.setServer( (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(){
|
||||
|
|
@ -272,7 +269,7 @@ public class Zallery extends HttpServlet{
|
|||
}
|
||||
|
||||
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)
|
||||
dispatcher.include(request, response);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue