📄 genericparamutil.java
字号:
return ret;
}
/**
* @param param is the name of variable
* @return true if the value of param is not empty
*/
public static boolean getParameterBoolean(GenericRequest request, String param) {
String inputStr = getParameter(request, param);
if (inputStr.length() == 0) return false;
return true;
}
public static byte getParameterByte(GenericRequest request, String param)
throws BadInputException {
String inputStr = getParameter(request, param, true);
byte ret;
try {
ret = Byte.parseByte(inputStr);
} catch (NumberFormatException e) {
Locale locale = I18nUtil.getLocaleInRequest(request);
String localizedMessage = MVNCoreResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_parse", new Object[] {DisableHtmlTagFilter.filter(param), "byte"});
throw new BadInputException(localizedMessage);
}
return ret;
}
public static double getParameterDouble(GenericRequest request, String param)
throws BadInputException {
double ret;
String inputStr = StringUtil.getEmptyStringIfNull(getParameter(request, param, true));
try {
ret = Double.parseDouble(inputStr);
} catch (NumberFormatException e) {
Locale locale = I18nUtil.getLocaleInRequest(request);
String localizedMessage = MVNCoreResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_parse", new Object[] {DisableHtmlTagFilter.filter(param), "double"});
throw new BadInputException(localizedMessage);
}
return ret;
}
public static String getParameterUrl(GenericRequest request, String param)
throws BadInputException {
String ret = getParameter(request, param);
if ( ret.length() > 0 ) {
if ( !ret.startsWith("http://") &&
!ret.startsWith("https://") &&
!ret.startsWith("ftp://") ) {
Locale locale = I18nUtil.getLocaleInRequest(request);
String localizedMessage = MVNCoreResourceBundle.getString(locale, "mvncore.exception.BadInputException.not_url", new Object[] {DisableHtmlTagFilter.filter(param)});
throw new BadInputException(localizedMessage);
}
}
return ret;
}
public static String getParameterPassword(GenericRequest request, String param, int minLength, int option)
throws BadInputException {
if (minLength < 1) minLength = 1;
String ret = request.getParameter(param);
if (ret == null) ret = "";
ret = ret.trim();
if ( ret.length() < minLength ) {
Locale locale = I18nUtil.getLocaleInRequest(request);
String localizedMessage = MVNCoreResourceBundle.getString(locale, "mvncore.exception.BadInputException.password_too_short", new Object[] {new Integer(minLength)});
throw new BadInputException(localizedMessage);
}
/** @todo implement this feature */
if (option == 1) {//char and number
} else if (option == 2) {// lower char, upper char and number
}
return ret;
}
public static String getParameterEmail(GenericRequest request, String param)
throws BadInputException {
String email = getParameterSafe(request, param, true);
MailUtil.checkGoodEmail(email);
return email;
}
/**
* 获取表单数据,并格式化为日期型
*/
public static java.sql.Date getParameterDate(GenericRequest request, String param)
throws BadInputException {
//String inputStr = getParameter(request, param, true);
String inputStr = getParameter(request, param, false);
if(inputStr.equals("")) inputStr = "1/1/2000";
java.util.Date ret;
try {
ret = dateFormat.parse(inputStr);
} catch (java.text.ParseException e) {
Locale locale = I18nUtil.getLocaleInRequest(request);
String localizedMessage = MVNCoreResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_parse", new Object[]{DisableHtmlTagFilter.filter(param), "Date"});
throw new BadInputException(localizedMessage);
}
return new java.sql.Date(ret.getTime());
}
/**
*
*/
public static java.util.Date getParameterDateUtil(GenericRequest request, String param)
throws BadInputException {
String inputStr = getParameter(request, param, true);
java.util.Date ret;
try {
ret = dateFormat.parse(inputStr);
} catch (java.text.ParseException e) {
Locale locale = I18nUtil.getLocaleInRequest(request);
String localizedMessage = MVNCoreResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_parse", new Object[]{DisableHtmlTagFilter.filter(param), "Date"});
throw new BadInputException(localizedMessage);
}
return ret;
}
/**
*
*/
public static java.sql.Date getParameterDate(GenericRequest request, String paramDay, String paramMonth, String paramYear)
throws BadInputException {
int day = getParameterInt(request, paramDay);
int month = getParameterInt(request, paramMonth);
int year = getParameterInt(request, paramYear);
StringBuffer buffer = new StringBuffer();
buffer.append(day).append("/").append(month).append("/").append(year);
String inputStr = buffer.toString();
java.util.Date ret;
try {
ret = dateFormat.parse(inputStr);
} catch (java.text.ParseException e) {
Locale locale = I18nUtil.getLocaleInRequest(request);
String localizedMessage = MVNCoreResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_parse", new Object[]{DisableHtmlTagFilter.filter(inputStr), "Date"});
throw new BadInputException(localizedMessage);
}
return new java.sql.Date(ret.getTime());
}
//获取表单--时区
public static double getParameterTimeZone(GenericRequest request, String param)
throws BadInputException {
double timeZone = getParameterDouble(request, param);
if (timeZone < -12 || timeZone > 13) {
timeZone = 0;
}
return timeZone;
}
public static String getAttribute(HttpSession session, String name) {
String ret = (String)session.getAttribute(name);
if (ret == null) ret = "";
return ret.trim();
}
/**
* Note: sometime in the dispatched request, we dont receive HttpServletRequest
* but receive ServletRequest, such as com.caucho.server.webapp.DispatchRequest
*
* @param request ServletRequest
* @param name String
* @return String
*/
public static String getAttribute(GenericRequest request, String name) {
String ret = (String)request.getAttribute(name);
if (ret == null) ret = "";
return ret.trim();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -