Added getLongParameter().
git-svn-id: https://samskivert.googlecode.com/svn/trunk@1355 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: ParameterUtil.java,v 1.12 2003/09/17 18:50:07 ray Exp $
|
// $Id: ParameterUtil.java,v 1.13 2003/12/16 01:11:50 mdb Exp $
|
||||||
//
|
//
|
||||||
// samskivert library - useful routines for java programs
|
// samskivert library - useful routines for java programs
|
||||||
// Copyright (C) 2001 Michael Bayne
|
// Copyright (C) 2001 Michael Bayne
|
||||||
@@ -140,6 +140,24 @@ public class ParameterUtil
|
|||||||
return parseIntParameter(value, invalidDataMessage);
|
return parseIntParameter(value, invalidDataMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetches the supplied parameter from the request and converts it to
|
||||||
|
* a long. If the parameter does not exist, <code>defval</code> is
|
||||||
|
* returned. If the parameter is not a well-formed integer, a data
|
||||||
|
* validation exception is thrown with the supplied message.
|
||||||
|
*/
|
||||||
|
public static long getLongParameter (
|
||||||
|
HttpServletRequest req, String name, long defval,
|
||||||
|
String invalidDataMessage)
|
||||||
|
throws DataValidationException
|
||||||
|
{
|
||||||
|
String value = getParameter(req, name, false);
|
||||||
|
if (StringUtil.blank(value)) {
|
||||||
|
return defval;
|
||||||
|
}
|
||||||
|
return parseLongParameter(value, invalidDataMessage);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches the supplied parameter from the request. If the parameter
|
* Fetches the supplied parameter from the request. If the parameter
|
||||||
* does not exist, a data validation exception is thrown with the
|
* does not exist, a data validation exception is thrown with the
|
||||||
@@ -270,6 +288,20 @@ public class ParameterUtil
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal method to parse long values.
|
||||||
|
*/
|
||||||
|
protected static long parseLongParameter (
|
||||||
|
String value, String invalidDataMessage)
|
||||||
|
throws DataValidationException
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
return Long.parseLong(value);
|
||||||
|
} catch (NumberFormatException nfe) {
|
||||||
|
throw new DataValidationException(invalidDataMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal method to parse a float value.
|
* Internal method to parse a float value.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user