Package com.oopsclick.silk.utils
Class Role
- java.lang.Object
-
- com.oopsclick.silk.utils.Role
-
public class Role extends java.lang.Object
The Class Role is a utility to operate role tags stored in a session variable. The roles are separated by commas. The roles are case sensitive.- Author:
- Italo Osorio
-
-
Constructor Summary
Constructors Constructor Description Role(java.lang.String sessionVariable, javax.servlet.http.HttpSession session)
Instantiates a new uploaded instance having silkRoleList as the session variable.Role(javax.servlet.http.HttpSession session)
Instantiates a new Role instance having silkRoleList as the session variable.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(java.lang.String... roleList)
Add one or multiple comma separated roles tags to the session variable.void
addIfRoleExist(java.lang.String search, java.lang.String role)
Will add the role if the provided role exists.void
change(java.lang.String source, java.lang.String target)
Exchanges or switch one role for another.void
clean()
Cleans the session variable of any role.boolean
exists(java.lang.String role)
Return true if a role exists in the session variableint
getSize()
Returns the number of roles loaded in the variable.java.lang.String
getVariable()
Return the session variable used to store the rolesvoid
remove(java.lang.String... roleList)
Removes the role tag, on list of tags, from the role list in the session variable.void
removeIfRoleExist(java.lang.String search, java.lang.String role)
Will remove the role if the provided role exists.void
set()
Saves the variable's roles into the HTTP session.void
toggle(java.lang.String role, boolean condition)
Toggles (on/off) the role based on the provided logic conditions.java.lang.String
toString()
Return the loaded roles separated by commas.
-
-
-
Constructor Detail
-
Role
public Role(javax.servlet.http.HttpSession session)
Instantiates a new Role instance having silkRoleList as the session variable.- Parameters:
session
- The HTTP Session
-
Role
public Role(java.lang.String sessionVariable, javax.servlet.http.HttpSession session)
Instantiates a new uploaded instance having silkRoleList as the session variable.- Parameters:
sessionVariable
- The session variable's namesession
- The HTTP Session
-
-
Method Detail
-
getVariable
public java.lang.String getVariable()
Return the session variable used to store the roles- Returns:
- The session variable's name.
-
add
public void add(java.lang.String... roleList)
Add one or multiple comma separated roles tags to the session variable.- Parameters:
roleList
- The role tag or a list or tags.
-
remove
public void remove(java.lang.String... roleList)
Removes the role tag, on list of tags, from the role list in the session variable.- Parameters:
roleList
- The role tag or a list or tags.
-
change
public void change(java.lang.String source, java.lang.String target)
Exchanges or switch one role for another.- Parameters:
source
- The role tag to be replace.target
- The role tag to use instead.
-
addIfRoleExist
public void addIfRoleExist(java.lang.String search, java.lang.String role)
Will add the role if the provided role exists.- Parameters:
search
- The role to searchrole
- The role to add
-
removeIfRoleExist
public void removeIfRoleExist(java.lang.String search, java.lang.String role)
Will remove the role if the provided role exists.- Parameters:
search
- The role to searchrole
- The role to remove
-
toggle
public void toggle(java.lang.String role, boolean condition)
Toggles (on/off) the role based on the provided logic conditions. True if on and false is off.- Parameters:
role
- The role to toggle.condition
- The logical condition.
-
exists
public boolean exists(java.lang.String role)
Return true if a role exists in the session variable- Parameters:
role
- The role to verify.- Returns:
- True if the role exist.
-
clean
public void clean()
Cleans the session variable of any role.
-
set
public void set()
Saves the variable's roles into the HTTP session.
-
getSize
public int getSize()
Returns the number of roles loaded in the variable.- Returns:
- Roles total.
-
toString
public java.lang.String toString()
Return the loaded roles separated by commas.- Overrides:
toString
in classjava.lang.Object
-
-