📄 appsetting.java
字号:
package com.set.utils;
import java.util.*;
import java.text.*;
import com.set.appframe.data.GenericValueObject;
import com.set.appframe.business.SpringBeanFactory;
import com.set.appframe.exception.*;
/**
* AppSetting represents a collection of global settings that are shared by all
* components in an application
*
* @author Oliver Yip
* @version 1.0, 11/04/03
* @since 1.0
*/
public class AppSetting {
private static String RESNAME = "ApplicationResources";
private ResourceBundle bundle = null;
private static DateFormat dFormat = null;
private static DateFormat dtFormat = null;
/**
* constructs a <code>AppSetting</code> object.
*
* @param resName
* name of resource bundle for the application
*
*/
protected AppSetting(String resName) {
RESNAME = resName;
init();
}
/**
* specifies the locale to be used in the application
*
* @param l
* locale to be used in the application
*
*/
public void setLocale(Locale l) {
bundle = ResourceBundle.getBundle(RESNAME, l);
}
/**
* initializes application settings
*
*/
public void init() {
bundle = ResourceBundle.getBundle(RESNAME, Locale.getDefault());
dFormat = new SimpleDateFormat(getString("app.dateformat"));
dtFormat = new SimpleDateFormat(getString("app.datetimeformat"));
// dFormat = new SimpleDateFormat("yyyy-MM-dd");
// dtFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
}
/**
* returns a string from the application resource with a key
*
* @param k
* resource string key
* @return the resource string to retrieve
*
*/
public String getString(String k) {
return bundle.getString(k);
}
/**
* returns a string from the application resource with a key, and substitute
* in replace parameters to the resource string
*
* @param k
* resource string key
* @param param
* replace parameters to substitute in resource string
* @return the resource string to retrieve, with replace parameters
* substituted
*
*/
public String getString(String k, String[] param) {
return MessageFormat.format(bundle.getString(k), param);
}
/**
* returns the date format used in the application, based on application
* setting
*
* @return the date format used in the application
*
*/
public DateFormat getDateFormat() {
return dFormat;
}
/**
* formats a date value to a display string based on application setting
*
* @return formatted display string for the date
*
*/
public String dFormat(Date d) {
return dFormat.format(d);
}
/**
* returns the date/time format used in the application, based on the
* application setting
*
* @return the date/time format used in the application
*
*/
public DateFormat getDateTimeFormat() {
return dtFormat;
}
/**
* formats a date/time value to a display string based on application
* setting
*
* @return formatted display string for the date/time
*
*/
public String dtFormat(Date d) {
return dtFormat.format(d);
}
/**
* returns the current date/time in the application context.
*
* @return the current date/time format in the application context
*
*/
public Date getApplicationDate() {
return new Date();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -