goja.mvc.PageViewKit Maven / Gradle / Ivy
The newest version!
/**
* Copyright (c) 2015-2016, BruceZCQ ([email protected]).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package goja.mvc;
import java.io.File;
/**
* PageViewKit
* |--
* | |-- META-INF
* | |-- WEB-INF
* |-- classes
* |-- errorpages
* | |-- 403.jsp
* | |-- 404.jsp
* | `-- 500.jsp
* |-- lib
* `-- pageviews
* |-- login
* | |-- login.jsp
* `-- ..jsp
* |-- admin
* | |-- ..
* | `-- ..
* `-- ..
*
*
* web.xml:
*
* 403
* /WEB-INF/errorpages/403.jsp
*
*
* 404
* /WEB-INF/errorpages/404.jsp
*
*
* 500
* /WEB-INF/errorpages/500.jsp
*
*
*
* @author BruceZCQ
*/
final public class PageViewKit {
/**
* 工程的WEB-INF目录
*/
public static final String WEBINF_DIR = File.separator + "WEB-INF" + File.separator;
/**
* 工程的根目录
*/
public static final String ROOT_DIR = "/";
/**
* jsp文件后缀
*/
public static final String JSP = ".jsp";
/**
* html 文件后缀
*/
public static final String HTML = ".html";
private static final String ERROR_PAGE_PATH = "errorpages" + File.separator;
private static final String PAGE_VIEW_PATH = "pageviews" + File.separator;
/**
* 404 Error PageView
*/
public static String get404PageView() {
return getErrorCodePageView("404");
}
/**
* 403 Error PageView
*/
public static String get403PageView() {
return getErrorCodePageView("403");
}
/**
* 500 Error PageView
*/
public static String get500PageView() {
return getErrorCodePageView("500");
}
private static String getErrorCodePageView(String errorCode) {
return getPageView(WEBINF_DIR, ERROR_PAGE_PATH, errorCode, JSP);
}
/**
* 获取web-inf下面的页面
*
* @param pageName 页面名称
*/
public static String getJSPPageViewFromWebInf(String pageName) {
return getPageView(WEBINF_DIR, PAGE_VIEW_PATH, pageName, JSP);
}
/**
* 获取web-inf下面的pageviews目录中pathRefRootViews子目录下面的页面
*
* @param pathRefRootViews 目录: 加入到/WEB-INF/pageviews/pathRefRootViews下
* @param pageName 页面名称
*/
public static String getJSPPageViewFromWebInf(String pathRefRootViews, String pageName) {
return getPageView(WEBINF_DIR, PAGE_VIEW_PATH + pathRefRootViews, pageName, JSP);
}
/**
* 获取根目录下面的页面
*
* @param pageName 页面名称
*/
public static String getJSPPageViewFromRoot(String pageName) {
return getPageView(ROOT_DIR, PAGE_VIEW_PATH, pageName, JSP);
}
/**
* 获取根目录下面的pageviews目录中pathRefRootViews子目录下面的页面
*
* @param pathRefRootViews 目录: 加入到/pageviews/pathRefRootViews下
* @param pageName 页面名称
*/
public static String getJSPPageViewFromRoot(String pathRefRootViews, String pageName) {
return getPageView(ROOT_DIR, PAGE_VIEW_PATH + pathRefRootViews, pageName, JSP);
}
/**
* 获取web-inf下面的静态页面
*
* @param pageName 页面名称
*/
public static String getHTMLPageViewFromWebInf(String pageName) {
return getPageView(WEBINF_DIR, PAGE_VIEW_PATH, pageName, HTML);
}
/**
* 获取web-inf下面的pageviews目录中pathRefRootViews子目录下面的静态页面
*
* @param pathRefRootViews 目录: 加入到/WEB-INF/pageviews/pathRefRootViews下
* @param pageName 页面名称
*/
public static String getHTMLPageViewFromWebInf(String pathRefRootViews, String pageName) {
return getPageView(WEBINF_DIR, PAGE_VIEW_PATH + pathRefRootViews, pageName, HTML);
}
/**
* 获取根目录下面的静态页面
*
* @param pageName 页面名称
*/
public static String getHTMLPageViewFromRoot(String pageName) {
return getHTMLPageView(ROOT_DIR, PAGE_VIEW_PATH, pageName);
}
/**
* 获取根目录下的pageviews目录中pathRefRootViews子目录下面的静态页面
*
* @param pathRefRootViews 目录: 加入到/pageviews/pathRefRootViews下
* @param pageName 页面名称
*/
public static String getHTMLPageViewFromRoot(String pathRefRootViews, String pageName) {
return getHTMLPageView(ROOT_DIR, PAGE_VIEW_PATH + pathRefRootViews, pageName);
}
/**
* 获取静态页面
*
* @param dir 所在目录
* @param viewPath view路径
* @param pageName view名字
*/
public static String getHTMLPageView(String dir, String viewPath, String pageName) {
return getPageView(dir, viewPath, pageName, HTML);
}
/**
* 获取页面
*
* @param dir 所在目录
* @param viewPath view路径
* @param pageName view名字
*/
public static String getJSPPageView(String dir, String viewPath, String pageName) {
return getPageView(dir, viewPath, pageName, JSP);
}
/**
* 获取页面
*
* @param dir 所在目录
* @param viewPath view路径
* @param pageName view名字
* @param fileExtension view后缀
*/
public static String getPageView(String dir, String viewPath, String pageName, String fileExtension) {
if (!dir.endsWith("/")) {
dir = dir + "/";
}
if (!viewPath.endsWith("/")) {
viewPath = viewPath + "/";
}
return dir + viewPath + pageName + fileExtension;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy