org.opencms.jsp
Class CmsJspTagUserTracking

java.lang.Object
  extended by javax.servlet.jsp.tagext.TagSupport
      extended by org.opencms.jsp.CmsJspTagUserTracking
All Implemented Interfaces:
java.io.Serializable, javax.servlet.jsp.tagext.IterationTag, javax.servlet.jsp.tagext.JspTag, javax.servlet.jsp.tagext.Tag

public class CmsJspTagUserTracking
extends javax.servlet.jsp.tagext.TagSupport

Implementation of the <cms:usertracking/> tag.

This tag can be used to mark OpenCms files as visited or subscribe/unsubscribe them to/from users or groups.

It is also possible to check if single resources are visited/subscribed by the current user.

See also the CmsSubscriptionManager for more information about subscription or visitation.

Since:
8.0
See Also:
Serialized Form

Field Summary
static java.lang.String SESSION_PREFIX_SUBSCRIBED
          Prefix for the visited session attributes.
static java.lang.String SESSION_PREFIX_VISITED
          Prefix for the visited session attributes.
 
Fields inherited from class javax.servlet.jsp.tagext.TagSupport
id, pageContext
 
Fields inherited from interface javax.servlet.jsp.tagext.IterationTag
EVAL_BODY_AGAIN
 
Fields inherited from interface javax.servlet.jsp.tagext.Tag
EVAL_BODY_INCLUDE, EVAL_PAGE, SKIP_BODY, SKIP_PAGE
 
Constructor Summary
CmsJspTagUserTracking()
           
 
Method Summary
 int doStartTag()
           
protected static java.lang.String generateSessionKey(java.lang.String prefix, java.lang.String fileName, boolean subFolder, CmsUser user, java.util.List<CmsGroup> groups)
          Returns a unique session key depending on the values of the given parameters.
 java.lang.String getAction()
          Returns the action that should be performed, i.e. mark as visited or subscribe/unsubscribe.
 java.lang.String getCurrentuser()
          Returns the current user flag.
 java.lang.String getFile()
          Returns the file name to track.
 java.lang.String getGroup()
          Returns the group name that is used for the tracking.
 java.lang.String getIncludegroups()
          Returns the include groups flag.
 java.lang.String getOnline()
          Returns the online flag.
 java.lang.String getSubfolder()
          Returns the subfolder flag.
 java.lang.String getUser()
          Returns the user name that is used for the tracking.
protected static boolean isResourceSubscribed(CmsObject cms, java.lang.String fileName, boolean subFolder, CmsUser user, java.util.List<CmsGroup> groups, javax.servlet.http.HttpServletRequest req)
          Returns if the given resource is subscribed to the user or groups.
protected static boolean isResourceVisited(CmsObject cms, java.lang.String fileName, boolean subFolder, CmsUser user, javax.servlet.http.HttpServletRequest req)
          Returns if the given resource was visited by the user.
 void release()
           
protected static void removeSessionAttributes(java.lang.String[] prefixes, javax.servlet.http.HttpServletRequest req)
          Removes all session attributes starting with the given prefixes.
 void setAction(java.lang.String action)
          Sets the action that should be performed, i.e. mark as visited or subscribe/unsubscribe.
 void setCurrentuser(java.lang.String currentUser)
          Sets the current user flag.
 void setFile(java.lang.String file)
          Sets the file name to track.
 void setGroup(java.lang.String group)
          Sets the group name that is used for the tracking.
 void setIncludegroups(java.lang.String includeGroups)
          Sets the include groups flag.
 void setOnline(java.lang.String online)
          Sets the online flag.
 void setSubfolder(java.lang.String subfolder)
          Sets the subfolder flag.
 void setUser(java.lang.String user)
          Sets the user name that is used for the tracking.
static java.lang.String userTrackingTagAction(java.lang.String action, java.lang.String fileName, boolean subFolder, boolean currentUser, java.lang.String userName, boolean includeGroups, java.lang.String groupName, javax.servlet.http.HttpServletRequest req)
          Tracks an OpenCms file according to the parameters.
 
Methods inherited from class javax.servlet.jsp.tagext.TagSupport
doAfterBody, doEndTag, findAncestorWithClass, getId, getParent, getValue, getValues, removeValue, setId, setPageContext, setParent, setValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SESSION_PREFIX_SUBSCRIBED

public static final java.lang.String SESSION_PREFIX_SUBSCRIBED
Prefix for the visited session attributes.

See Also:
Constant Field Values

SESSION_PREFIX_VISITED

public static final java.lang.String SESSION_PREFIX_VISITED
Prefix for the visited session attributes.

See Also:
Constant Field Values
Constructor Detail

CmsJspTagUserTracking

public CmsJspTagUserTracking()
Method Detail

userTrackingTagAction

public static java.lang.String userTrackingTagAction(java.lang.String action,
                                                     java.lang.String fileName,
                                                     boolean subFolder,
                                                     boolean currentUser,
                                                     java.lang.String userName,
                                                     boolean includeGroups,
                                                     java.lang.String groupName,
                                                     javax.servlet.http.HttpServletRequest req)
                                              throws javax.servlet.jsp.JspException
Tracks an OpenCms file according to the parameters.

Parameters:
action - the action that should be performed
fileName - the file name to track
subFolder - flag indicating if sub folders should be included
currentUser - flag indicating if the current user should be used for the tracking action
userName - the user name that should be used for the action
includeGroups - flag indicating if the given users groups should be included
groupName - the group name that should be used for the action
req - the current request
Returns:
the result of the action, usually empty except for the check actions
Throws:
javax.servlet.jsp.JspException - in case something goes wrong

generateSessionKey

protected static java.lang.String generateSessionKey(java.lang.String prefix,
                                                     java.lang.String fileName,
                                                     boolean subFolder,
                                                     CmsUser user,
                                                     java.util.List<CmsGroup> groups)
Returns a unique session key depending on the values of the given parameters.

Parameters:
prefix - the key prefix to use
fileName - the file name to track
subFolder - flag indicating if sub folders should be included
user - the user that should be used
groups - the groups that should be used
Returns:
a unique session key

isResourceSubscribed

protected static boolean isResourceSubscribed(CmsObject cms,
                                              java.lang.String fileName,
                                              boolean subFolder,
                                              CmsUser user,
                                              java.util.List<CmsGroup> groups,
                                              javax.servlet.http.HttpServletRequest req)
                                       throws CmsException
Returns if the given resource is subscribed to the user or groups.

Parameters:
cms - the current users context
fileName - the file name to track
subFolder - flag indicating if sub folders should be included
user - the user that should be used for the check
groups - the groups that should be used for the check
req - the current request
Returns:
true if the given resource is subscribed to the user or groups, otherwise false
Throws:
CmsException - if something goes wrong

isResourceVisited

protected static boolean isResourceVisited(CmsObject cms,
                                           java.lang.String fileName,
                                           boolean subFolder,
                                           CmsUser user,
                                           javax.servlet.http.HttpServletRequest req)
                                    throws CmsException
Returns if the given resource was visited by the user.

Parameters:
cms - the current users context
fileName - the file name to track
subFolder - flag indicating if sub folders should be included
user - the user that should be used for the check
req - the current request
Returns:
true if the given resource was visited by the user, otherwise false
Throws:
CmsException - if something goes wrong

removeSessionAttributes

protected static void removeSessionAttributes(java.lang.String[] prefixes,
                                              javax.servlet.http.HttpServletRequest req)
Removes all session attributes starting with the given prefixes.

Parameters:
prefixes - the prefixes of the session attributes to remove
req - the current request

doStartTag

public int doStartTag()
               throws javax.servlet.jsp.JspException
Specified by:
doStartTag in interface javax.servlet.jsp.tagext.Tag
Overrides:
doStartTag in class javax.servlet.jsp.tagext.TagSupport
Throws:
javax.servlet.jsp.JspException
See Also:
Tag.doStartTag()

getAction

public java.lang.String getAction()
Returns the action that should be performed, i.e. mark as visited or subscribe/unsubscribe.

Returns:
the action that should be performed

getCurrentuser

public java.lang.String getCurrentuser()
Returns the current user flag.

Returns:
the current user flag

getFile

public java.lang.String getFile()
Returns the file name to track.

Returns:
the file name to track

getGroup

public java.lang.String getGroup()
Returns the group name that is used for the tracking.

Returns:
the group name that is used for the tracking

getIncludegroups

public java.lang.String getIncludegroups()
Returns the include groups flag.

Returns:
the include groups flag

getOnline

public java.lang.String getOnline()
Returns the online flag.

Returns:
the online flag

getSubfolder

public java.lang.String getSubfolder()
Returns the subfolder flag.

Returns:
the subfolder flag

getUser

public java.lang.String getUser()
Returns the user name that is used for the tracking.

Returns:
the user name that is used for the tracking

release

public void release()
Specified by:
release in interface javax.servlet.jsp.tagext.Tag
Overrides:
release in class javax.servlet.jsp.tagext.TagSupport
See Also:
Tag.release()

setAction

public void setAction(java.lang.String action)
Sets the action that should be performed, i.e. mark as visited or subscribe/unsubscribe.

Parameters:
action - the action that should be performed

setCurrentuser

public void setCurrentuser(java.lang.String currentUser)
Sets the current user flag.

Current user is false by default.

Parameters:
currentUser - the flag to set

setFile

public void setFile(java.lang.String file)
Sets the file name to track.

Parameters:
file - the file name to track

setGroup

public void setGroup(java.lang.String group)
Sets the group name that is used for the tracking.

Parameters:
group - the group name that is used for the tracking

setIncludegroups

public void setIncludegroups(java.lang.String includeGroups)
Sets the include groups flag.

Include groups is false by default.

Parameters:
includeGroups - the flag to set

setOnline

public void setOnline(java.lang.String online)
Sets the online flag.

Online is false by default.

Parameters:
online - the flag to set

setSubfolder

public void setSubfolder(java.lang.String subfolder)
Sets the subfolder flag.

Online is false by default.

Parameters:
subfolder - the flag to set

setUser

public void setUser(java.lang.String user)
Sets the user name that is used for the tracking.

Parameters:
user - the user name that is used for the tracking