| java.lang.Object org.nemesis.forum.webapp.front.Tools
Tools | public class Tools (Code) | | author: dlaurent |
Method Summary | |
public static String | dateToText(Date date) Returns a String describing the amount of time between now (current
system time) and the passed in date time. | public static long | getLastVisited(HttpServletRequest request, HttpServletResponse response, boolean updateLastVisitedTime) Returns the time in milliseconds that the user last visited the system.
Parameters: request - the HttpServletRequest object, known as "request" on a JSP page. Parameters: response - the HttpServletRequest object, known as "response" on a JSP page. Parameters: updateLastVisitedTime - Set to true if you wish to updatethe user's last visited time to the current time; set to false otherwise. | public static long | getLastVisited(HttpServletRequest request, HttpServletResponse response) Returns the time in milliseconds that the user last visited .
Parameters: request - the HttpServletRequest object, known as "request" on a JSP page. Parameters: response - the HttpServletRequest object, known as "response" on a JSP page. | public static Authorization | getUserAuthorization(HttpServletRequest request, HttpServletResponse response, boolean checkCookie) Returns an Authorization token for the user. | public static Authorization | getUserAuthorization(HttpServletRequest request, HttpServletResponse response) Returns an Authorization token for the user. | public static boolean | isNewMessage(Message message, long lastVisited) Returns true if the message has been created or updated since
the last time the user visisted.
Parameters: message - the message to check. Parameters: lastVisted - the time the user last visisted the forum. | public static String | quoteOriginal(String body, String delimiter, int lineLength) Formats the unfiltered body of a message to make it appear in the "quote
original" format. | public static void | removeUserAuthorization(HttpServletRequest request, HttpServletResponse response) Invalidates the cookie that otherwise lets a user auto-login. | public static Authorization | setUserAuthorization(HttpServletRequest request, HttpServletResponse response, String username, String password, boolean autoLogin) Validates the user and optionally enables auto-login by creating an
auto-login cookie. |
AUTH_TOKEN | final public static String AUTH_TOKEN(Code) | | Name of the authentication token (is stored in the user's session)
|
AUTOLOGIN_COOKIE | final public static String AUTOLOGIN_COOKIE(Code) | | Name of the cookie used to store user info for auto-login purposes
|
LASTVISITED_COOKIE | final public static String LASTVISITED_COOKIE(Code) | | Name of the cookie used to store last visited timestamp
|
LASTVISITED_TOKEN | final public static String LASTVISITED_TOKEN(Code) | | Name of the last visited token (is stored in the user's session)
|
dateToText | public static String dateToText(Date date)(Code) | | Returns a String describing the amount of time between now (current
system time) and the passed in date time. Example output is "5 hours
ago" or "Yesterday at 3:30 pm"
Parameters: date - the Date to compare the current time with. a description of the difference in time, ie: "5 hours ago"or "Yesterday at 3:30pm" |
getLastVisited | public static long getLastVisited(HttpServletRequest request, HttpServletResponse response, boolean updateLastVisitedTime)(Code) | | Returns the time in milliseconds that the user last visited the system.
Parameters: request - the HttpServletRequest object, known as "request" on a JSP page. Parameters: response - the HttpServletRequest object, known as "response" on a JSP page. Parameters: updateLastVisitedTime - Set to true if you wish to updatethe user's last visited time to the current time; set to false otherwise. The time (in milliseconds) that the suer last visited . |
getLastVisited | public static long getLastVisited(HttpServletRequest request, HttpServletResponse response)(Code) | | Returns the time in milliseconds that the user last visited .
Parameters: request - the HttpServletRequest object, known as "request" on a JSP page. Parameters: response - the HttpServletRequest object, known as "response" on a JSP page. The time (in milliseconds) that the suer last visited . |
getUserAuthorization | public static Authorization getUserAuthorization(HttpServletRequest request, HttpServletResponse response, boolean checkCookie)(Code) | | Returns an Authorization token for the user. The following steps are
performed to determine the token:
- Check the session for the existence of a authorization token.
If one is found, it is returned as we assume that the user has logged
in and is authorized.
- Check the authorization cookie for a username and password. If found,
attempt to create a authorization token using that data. If
successful, save the token to the session and return it.
NOTE: This check can be skipped by setting
checkCookie to false.
Parameters: request - the HttpServletRequest object, known as "request" in aJSP page. Parameters: response - the HttpServletResponse object, known as "response" ina JSP page. Parameters: checkCookie - a boolean that indicates whether or not we wantto use a cookie for authorization. the authorization token if authenticated, otherwisenull . See Also: Authorization |
getUserAuthorization | public static Authorization getUserAuthorization(HttpServletRequest request, HttpServletResponse response)(Code) | | Returns an Authorization token for the user. This is a convenience method
that that calls the other getUserAuthorization method with
checkCookie set to true.
Parameters: request - the HttpServletRequest object, known as "request" in aJSP page. Parameters: response - The HttpServletResponse object, known as "response" ina JSP page. The authorization token if authenticated, otherwisenull . |
isNewMessage | public static boolean isNewMessage(Message message, long lastVisited)(Code) | | Returns true if the message has been created or updated since
the last time the user visisted.
Parameters: message - the message to check. Parameters: lastVisted - the time the user last visisted the forum. true if the message has been created or updated since the user'slast visit. |
quoteOriginal | public static String quoteOriginal(String body, String delimiter, int lineLength)(Code) | | Formats the unfiltered body of a message to make it appear in the "quote
original" format. This is simply the body of the message with the
delimiter appended to the beginning of each line. The delimiter
is most often "> " by convention. A desired length for each line in the
returned String can be specified to aid in formatting.
This method uses message.getUnfilteredBody() in order to get the body of
the message. This usually yields better results for the formatting
required by this method. However, it also has the potential of being
a security risk if malicious HTML code is embedded in the body. Therefore,
you should always filter HTML from the result of this method before
showing it in an environment where HTML is interpreted. If you are
showing the results of this method in an HTML <textarea>, there is
no need to worry about malicious HTML.
Parameters: message - the message to quote. Parameters: delimiter - a String that will start each line of the quotedmessage. For example, "> "; Parameters: lineLength - the desired length of each line in the quoted message. the unfiltered body of the message in the "quote original" format. |
removeUserAuthorization | public static void removeUserAuthorization(HttpServletRequest request, HttpServletResponse response)(Code) | | Invalidates the cookie that otherwise lets a user auto-login.
Parameters: request - The HttpServletRequest object, known as "request" in a JSP page. Parameters: response - The HttpServletResponse object, known as "response" in a JSP page. |
setUserAuthorization | public static Authorization setUserAuthorization(HttpServletRequest request, HttpServletResponse response, String username, String password, boolean autoLogin) throws NotFoundException, UnauthorizedException(Code) | | Validates the user and optionally enables auto-login by creating an
auto-login cookie.
Parameters: request - the HttpServletRequest object, known as "request" in a JSP page. Parameters: response - the HttpServletResponse object, known as "response" in a JSP page. Parameters: username - the username. Parameters: password - the password. Parameters: autoLogin - if true create a cookie that enables auto-login. throws: UserNotFoundException - throws: UnauthorizedException - The authorization token if authenticated, otherwisenull |
|
|