| java.lang.Object com.Yasna.forum.util.SkinUtils
SkinUtils | public class SkinUtils (Code) | | A collection of utility methods for use in Yazd WebSkins. Because these
methods make skin development much easier, skin authors should study them
carefully.
Three major areas of funtionality are provided:
- Methods that simplify Authorization tasks:
-
SkinUtils.getUserAuthorization(HttpServletRequest,HttpServletResponse)
-
SkinUtils.getUserAuthorization(HttpServletRequest,HttpServletResponse,boolean)
-
SkinUtils.setUserAuthorization(HttpServletRequest,HttpServletResponse,String,String,boolean)
-
SkinUtils.removeUserAuthorization(HttpServletRequest,HttpServletResponse)
-
SkinUtils.isSystemAdmin(Authorization)
-
SkinUtils.isForumAdmin(Authorization)
-
SkinUtils.isForumAdmin(Authorization,Forum)
-
SkinUtils.isGroupAdmin(Authorization)
-
SkinUtils.isGroupAdmin(Authorization,Group)
- Methods that get and set Session and cookie values.
-
SkinUtils.getCookie(HttpServletRequest,String)
-
SkinUtils.getCookieValue(HttpServletRequest,String)
-
SkinUtils.invalidateCookie(HttpServletRequest,HttpServletResponse,String)
-
SkinUtils.remove(HttpServletRequest,HttpServletResponse,String)
-
SkinUtils.retrieve(HttpServletRequest,HttpServletResponse,String)
-
SkinUtils.retrieve(HttpServletRequest,HttpServletResponse,String,boolean)
-
SkinUtils.store(HttpServletRequest,HttpServletResponse,String,String)
-
SkinUtils.store(HttpServletRequest,HttpServletResponse,String,String,int)
-
#store(HttpServletRequest, HttpServletResponse, String, String, int boolean)
- Other methods.
All methods conform to the Servlet 1.1 and JSP 1.0 specs for maximum
compatibility with application servers. This may yield deprecation warnings
if you compile with a newer Servlet/JSP spec; these should be ignored. This
class will periodically be updated to the newer specs as app servers mature.
|
Method Summary | |
public static String | dateToText(Date date, Locale locale, TimeZone timezone) Returns a String describing the amount of time between now (current
system time) and the passed in date time. | public static Cookie | getCookie(HttpServletRequest request, String name) Returns the specified Cookie object, or null if the cookie does not exist.
Parameters: request - The HttpServletRequest object, known as "request" in aJSP page. Parameters: name - the name of the cookie. | public static String | getCookieValue(HttpServletRequest request, String name) Returns the value of the specified cookie as a String. | public static long | getLastVisited(HttpServletRequest request, HttpServletResponse response) Returns the time in milliseconds that the user last visited Yazd. | public static long | getLastVisited(HttpServletRequest request, HttpServletResponse response, boolean updateLastVisitedTime) Returns the time in milliseconds that the user last visited the Yazd 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 Authorization | getUserAuthorization(HttpServletRequest request, HttpServletResponse response, boolean checkYazdCookie) Returns an Authorization token for the user. | public static Authorization | getUserAuthorization(HttpServletRequest request, HttpServletResponse response) Returns an Authorization token for the user. | public static void | invalidateCookie(HttpServletRequest request, HttpServletResponse response, String cookieName) Invalidate the specified cookie and delete it from the response object. | public static boolean | isForumAdmin(Authorization authToken) Returns true if the user is a forum adminstrator of any forum in the
system. | public static boolean | isForumAdmin(Authorization authToken, Forum forum) Returns true if the user is a forum adminstrator of the given forum.
Parameters: authToken - the authentication token of the user Parameters: forum - the forum to check administrator status on. | public static boolean | isForumModerator(Authorization authToken) Returns true if the user is a forum moderator of any forum in the
system. | public static boolean | isForumModerator(Authorization authToken, Forum forum) Returns true if the user is a forum moderator of the given forum.
Parameters: authToken - the authentication token of the user Parameters: forum - the forum to check moderator status on. | public static boolean | isGroupAdmin(Authorization authToken) Returns true if the user is a group administrator of any group in the
system. | public static boolean | isGroupAdmin(Authorization authToken, Group group) Returns true if the user is a group administrator of the given group.
Parameters: authToken - the authentication token of the user Parameters: group - the group to check administrator status on. | public static boolean | isNewMessage(ForumMessage 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 boolean | isSystemAdmin(Authorization authToken) Returns true if the user is a system administrator. | 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 | remove(HttpServletRequest request, HttpServletResponse response, String id) Removes a user stored value. | public static void | removeUserAuthorization(HttpServletRequest request, HttpServletResponse response) Invalidates the cookie that otherwise lets a user auto-login. | public static String | retrieve(HttpServletRequest request, HttpServletResponse response, String id) Retrieves a user stored value. | public static String | retrieve(HttpServletRequest request, HttpServletResponse response, String id, boolean remove) Retrieves a user stored value. | 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. | public static void | store(HttpServletRequest request, HttpServletResponse response, String id, String value) Persists a value for the length of the user's session. | public static void | store(HttpServletRequest request, HttpServletResponse response, String id, String value, int secsToLive) | public static void | store(HttpServletRequest request, HttpServletResponse response, String id, String value, int secsToLive, boolean restoreInSession) This method should be used in a jsp skin to store an arbritary value.
For example, we could persist the name of a user so that on a form page
where they enter their name, that field could be auto-filled in with
the stored value.
To indicate that the data should only be persisted for a session, pass
in 0 as the timeToLive .
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: id - The name or identifier of the data you want to persist. Parameters: value - The value you wish to store. Parameters: secsToLive - The length (in seconds) this value will persist. |
YAZD_AUTH_TOKEN | final public static String YAZD_AUTH_TOKEN(Code) | | Name of the authentication token (is stored in the user's session)
|
YAZD_AUTOLOGIN_COOKIE | final public static String YAZD_AUTOLOGIN_COOKIE(Code) | | Name of the cookie used to store user info for auto-login purposes
|
YAZD_LASTVISITED_COOKIE | final public static String YAZD_LASTVISITED_COOKIE(Code) | | Name of the cookie used to store last visited timestamp
|
YAZD_LASTVISITED_PROP | final public static String YAZD_LASTVISITED_PROP(Code) | | Name of the "use last visited" property (is stored in yazd.properties)
|
YAZD_LASTVISITED_TOKEN | final public static String YAZD_LASTVISITED_TOKEN(Code) | | Name of the last visited token (is stored in the user's session)
|
dateToText | public static String dateToText(Date date, Locale locale, TimeZone timezone)(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" |
getCookie | public static Cookie getCookie(HttpServletRequest request, String name)(Code) | | Returns the specified Cookie object, or null if the cookie does not exist.
Parameters: request - The HttpServletRequest object, known as "request" in aJSP page. Parameters: name - the name of the cookie. the Cookie object if it exists, otherwise null. |
getCookieValue | public static String getCookieValue(HttpServletRequest request, String name)(Code) | | Returns the value of the specified cookie as a String. If the cookie
does not exist, the method returns null.
Parameters: request - the HttpServletRequest object, known as "request" in aJSP page. Parameters: name - the name of the cookie the value of the cookie, or null if the cookie does not exist. |
getLastVisited | public static long getLastVisited(HttpServletRequest request, HttpServletResponse response, boolean updateLastVisitedTime)(Code) | | Returns the time in milliseconds that the user last visited the Yazd 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 Yazd. |
getUserAuthorization | public static Authorization getUserAuthorization(HttpServletRequest request, HttpServletResponse response, boolean checkYazdCookie)(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 Yazd authorization token.
If one is found, it is returned as we assume that the user has logged
in and is authorized.
- Check the Yazd authorization cookie for a username and password. If found,
attempt to create a Yazd authorization token using that data. If
successful, save the token to the session and return it.
NOTE: This check can be skipped by setting
checkYazdCookie 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: checkYazdCookie - a boolean that indicates whether or not we wantto use a cookie for authorization. the authorization token if authenticated, otherwisenull . See Also: Authorization |
invalidateCookie | public static void invalidateCookie(HttpServletRequest request, HttpServletResponse response, String cookieName)(Code) | | Invalidate the specified cookie and delete it from the response object.
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: cookieName - The name of the cookie you want to delete. |
isForumAdmin | public static boolean isForumAdmin(Authorization authToken)(Code) | | Returns true if the user is a forum adminstrator of any forum in the
system. For example, if there are 3 forums in the system and the user
is an adminstrator of any one or more of them, this method will return
true.
Use the method isForumAdmin( Authorization, Forum) to
check an individual forum for administrator status.)
Parameters: authToken - the authentication token of the user true if the user is a forum administrator of any forum in the system. See Also: SkinUtils.isForumAdmin(AuthorizationForum) |
isForumAdmin | public static boolean isForumAdmin(Authorization authToken, Forum forum)(Code) | | Returns true if the user is a forum adminstrator of the given forum.
Parameters: authToken - the authentication token of the user Parameters: forum - the forum to check administrator status on. true if the user is a forum administrator of the given forum. |
isForumModerator | public static boolean isForumModerator(Authorization authToken)(Code) | | Returns true if the user is a forum moderator of any forum in the
system. For example, if there are 3 forums in the system and the user
is a moderator of any one or more of them, this method will return
true.
Use the method isForumModerator( Authorization, Forum) to
check an individual forum for moderator status.)
Parameters: authToken - the authentication token of the user true if the user is a forum moderator of any forum in the system. See Also: SkinUtils.isForumModerator(AuthorizationForum) |
isForumModerator | public static boolean isForumModerator(Authorization authToken, Forum forum)(Code) | | Returns true if the user is a forum moderator of the given forum.
Parameters: authToken - the authentication token of the user Parameters: forum - the forum to check moderator status on. true if the user is a forum moderator of the given forum. |
isGroupAdmin | public static boolean isGroupAdmin(Authorization authToken)(Code) | | Returns true if the user is a group administrator of any group in the
system. For example, if there are 3 groups in the system and the user
is an adminstrator of any one or more of them, this method will return
true.
Use the method isGroupAdmin( Authorization, Group) to check
an individual group for administrator status.)
See Also: SkinUtils.isGroupAdmin(AuthorizationGroup) |
isGroupAdmin | public static boolean isGroupAdmin(Authorization authToken, Group group)(Code) | | Returns true if the user is a group administrator of the given group.
Parameters: authToken - the authentication token of the user Parameters: group - the group to check administrator status on. true if the user is a group administrator of the given group. |
isNewMessage | public static boolean isNewMessage(ForumMessage 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. |
isSystemAdmin | public static boolean isSystemAdmin(Authorization authToken)(Code) | | Returns true if the user is a system administrator.
Parameters: authToken - the authentication token of the user true if the user is a system administrator, false otherwise. |
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. |
remove | public static void remove(HttpServletRequest request, HttpServletResponse response, String id)(Code) | | Removes a user stored value. Values are set using the store(...)
methods.
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: id - the id or name of the stored value you wish to remove from persistence. |
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. |
retrieve | public static String retrieve(HttpServletRequest request, HttpServletResponse response, String id)(Code) | | Retrieves a user stored value. Values are set using the store(...)
methods.
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: id - The id or name of the stored value. The value of the specified id, otherwise null . |
retrieve | public static String retrieve(HttpServletRequest request, HttpServletResponse response, String id, boolean remove)(Code) | | Retrieves a user stored value. Values are set using the store(...)
methods. If remove is true, the value is also removed
from persistence.
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: id - The id or name of the stored value. The value of the specified id, otherwise null . |
setUserAuthorization | public static Authorization setUserAuthorization(HttpServletRequest request, HttpServletResponse response, String username, String password, boolean autoLogin) throws UserNotFoundException, 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 |
store | public static void store(HttpServletRequest request, HttpServletResponse response, String id, String value, int secsToLive, boolean restoreInSession)(Code) | | This method should be used in a jsp skin to store an arbritary value.
For example, we could persist the name of a user so that on a form page
where they enter their name, that field could be auto-filled in with
the stored value.
To indicate that the data should only be persisted for a session, pass
in 0 as the timeToLive .
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: id - The name or identifier of the data you want to persist. Parameters: value - The value you wish to store. Parameters: secsToLive - The length (in seconds) this value will persist. Any value of 0 orless indicates this data should only persist for a session. |
|
|