自定义configuration帮助类获取路径

import com.sungoin.platform.common.util.SpringHelper;
import com.sungoin.platform.system.po.Agency;
import com.sungoin.platform.system.po.Company;
import java.io.File;
import java.util.ResourceBundle;
import javax.servlet.ServletContext;

//SpringHelper在另外个博客里面,ResourceBundle.getBundle("application");是放在resources文件下的properties文件
public class Configuration { private static final ResourceBundle application = ResourceBundle.getBundle("application"); private static final ResourceBundle payment = ResourceBundle.getBundle("payment"); /** * 取系统配置文件(application.properties)信息 * @param key * @return */ public static String getProperty(String key) { return application.getString(key); } /** * 取支付配置文件(payment.properties)信息 * @param key * @return */ public static String getPayProperty(String key) { return payment.getString(key); } public static String getWebAppPath() { ServletContext sc = SpringHelper.getServletContext(); String apppath = sc.getRealPath("/"); if (apppath.endsWith(File.separator)) { apppath = apppath.substring(0, apppath.length() - 1); } return apppath; } public static String getWebInfPath() { return getWebAppPath() + File.separator + "WEB-INF"; } public static String getTempDirName() { return getProperty(Constants.UPLOAD_DIR_NAME); } public static String getTempDirPath() { return getWebAppPath() + File.separator + getProperty(Constants.TEMP_DIR_NAME); } public static String getUploadRootName() { return getProperty(Constants.UPLOAD_DIR_NAME); } public static String getUploadRootPath() { return getWebAppPath() + File.separator + getProperty(Constants.UPLOAD_DIR_NAME); } public static String getCompanyUploadName(Company company) { return getUploadRootName() + "/company/" + company.getId(); } public static String getCompanyUploadPath(Company company) { return getUploadRootPath() + "/company/" + company.getId(); } public static String getAgencyUploadName(Agency agency) { return getUploadRootName() + "/agency/" + agency.getId(); } public static String getAgencyUploadPath(Agency agency) { return getUploadRootPath() + "/agency/" + agency.getId(); } public static String getMailService() { return application.getString("mailService"); } public static String getRegisterActiveUrl() { return application.getString("registerActiveUrl"); } public static String getDefaultAgencyId() { return application.getString("default.agency.id"); } public static String getInvoiceSubmitUrl() { return application.getString("invoice.submit.url"); } public static String getCRMEndpoint() { return application.getString("crm.endpoint"); } }
posted @ 2014-07-17 11:26  柠檬Cool  阅读(598)  评论(0)    收藏  举报