Class StatsUtil


  • public final class StatsUtil
    extends Object
    Utility class for statistics.
    Version:
    $Id: 5f076ea496b853c7595c9e6ffca5bfb66991f04e $
    • Method Detail

      • getCookieDomains

        public static String[] getCookieDomains​(XWikiContext context)
        Parameters:
        context - the XWiki context.
        Returns:
        the list of cookie domains.
        Since:
        1.4M1
      • getCookieExpirationDate

        public static Date getCookieExpirationDate()
        Returns:
        the expiration date of the cookie.
        Since:
        1.4M1
      • getRecentActionFromSessions

        public static Collection<?> getRecentActionFromSessions​(XWikiContext context,
                                                                String action)
        Parameters:
        context - the XWiki context from where to get the HTTP session session.
        action - the action id.
        Returns:
        the recent statistics actions stored in the session.
        Since:
        1.4M1
      • setRecentActionsFromSession

        public static void setRecentActionsFromSession​(XWikiContext context,
                                                       String action,
                                                       Collection<?> actions)
        Store the recent statistics actions in the session.
        Parameters:
        context - the XWiki context from where to get the HTTP session session.
        action - the action id.
        actions - the actions.
        Since:
        1.4M1
      • getRecentVisitSize

        public static int getRecentVisitSize​(XWikiContext context)
        Parameters:
        context - the XWiki context.
        Returns:
        the size of the recent list of visit statistics actions.
        Since:
        1.4M1
      • getVisitFromSession

        public static VisitStats getVisitFromSession​(javax.servlet.http.HttpSession session)
        Parameters:
        session - the session.
        Returns:
        the visit object stored in the session.
        Since:
        1.4M1
      • setVisitInSession

        public static void setVisitInSession​(javax.servlet.http.HttpSession session,
                                             VisitStats visitStat)
        Store the visit object in the session.
        Parameters:
        session - the session.
        visitStat - the visit object.
        Since:
        1.4M1
      • isStatsEnabled

        public static boolean isStatsEnabled​(XWikiContext context)
        Parameters:
        context - the XWiki context.
        Returns:
        true if statistics are enabled, false otherwise.
        Since:
        1.4M1
      • isWikiStatsEnabled

        public static boolean isWikiStatsEnabled​(XWikiContext context)
        Parameters:
        context - the XWiki context
        Returns:
        true if statistics are enabled for this wiki, false otherwise.
        Since:
        1.4M1
      • findVisit

        public static VisitStats findVisit​(XWikiContext context)
        Try to find the visiting session of the current request, or create a new one if this request is not part of a visit. The session is searched in the following way:
        1. the java session is searched for the visit object
        2. try to find the stored session using the cookie
        3. try to find the session by matching the IP and User Agent
        The session is invalidated if:
        • the cookie is not the same as the stored cookie
        • more than 30 minutes have elapsed from the previous request
        • the user is not the same
        Parameters:
        context - The context of this request.
        Returns:
        The visiting session, retrieved from the database or created.
        Since:
        1.4M1
      • findVisitByField

        protected static VisitStats findVisitByField​(String fieldName,
                                                     String fieldValue,
                                                     XWikiContext context)
                                              throws XWikiException
        Search visit statistics object in the database based on cookie name.
        Parameters:
        fieldName - the field name.
        fieldValue - the field value.
        context - the XWiki context.
        Returns:
        the visit object, null if no object was found.
        Throws:
        XWikiException - error when searching for visit object.
        Since:
        1.4M1
      • findVisitByCookie

        protected static VisitStats findVisitByCookie​(String cookie,
                                                      XWikiContext context)
                                               throws XWikiException
        Search visit statistics object in the database based on cookie name.
        Parameters:
        cookie - the cookie name.
        context - the XWiki context.
        Returns:
        the visit object, null if no object was found.
        Throws:
        XWikiException - error when searching for visit object.
        Since:
        1.4M1
      • findVisitByIPUA

        protected static VisitStats findVisitByIPUA​(String uniqueID,
                                                    XWikiContext context)
                                             throws XWikiException
        Search visit statistics object in the database based on visit unique id.
        Parameters:
        uniqueID - the visit unique id.
        context - the XWiki context.
        Returns:
        the visit object.
        Throws:
        XWikiException - error when searching for visit object.
        Since:
        1.4M1
      • addCookie

        protected static javax.servlet.http.Cookie addCookie​(XWikiContext context)
        Create a new visit cookie and return it.
        Parameters:
        context - the XWiki context.
        Returns:
        the newly created cookie.
        Since:
        1.4M1
      • findCookie

        public static boolean findCookie​(XWikiContext context)
        Try to find the cookie of the current request or create it.
        Parameters:
        context - The context of this request.
        Returns:
        true if the cookie is created.
        Since:
        1.4M1
      • getReferer

        public static String getReferer​(XWikiContext context)
        Parameters:
        context - the XWiki context.
        Returns:
        the referer.
        Since:
        1.4M1