com.xpn.xwiki.stats.impl
Class StatsUtil

java.lang.Object
  extended by com.xpn.xwiki.stats.impl.StatsUtil

public final class StatsUtil
extends Object

Utility class for statistics.

Version:
$Id: eb5daed1900768bb567695307fc322db1e91749f $

Nested Class Summary
static class StatsUtil.PeriodType
          The type of the period.
 
Method Summary
protected static javax.servlet.http.Cookie addCookie(XWikiContext context)
          Create a new visit cookie and return it.
static boolean findCookie(XWikiContext context)
          Try to find the cookie of the current request or create it.
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.
protected static VisitStats findVisitByCookie(String cookie, XWikiContext context)
          Search visit statistics object in the database based on cookie name.
protected static VisitStats findVisitByField(String fieldName, String fieldValue, XWikiContext context)
          Search visit statistics object in the database based on cookie name.
protected static VisitStats findVisitByIPUA(String uniqueID, XWikiContext context)
          Search visit statistics object in the database based on visit unique id.
static String[] getCookieDomains(XWikiContext context)
           
static Date getCookieExpirationDate()
           
static int getPeriodAsInt(Date date, StatsUtil.PeriodType type)
          Computes an integer representation of the passed date using the following format: "yyyMMdd" for StatsUtil.PeriodType.DAY "yyyMM" for StatsUtil.PeriodType.MONTH .
static Collection<?> getRecentActionFromSessions(XWikiContext context, String action)
           
static int getRecentVisitSize(XWikiContext context)
           
static String getReferer(XWikiContext context)
           
static Collection<DocumentReference> getRequestFilteredUsers(XWikiContext context)
          The list of users to filter in view request.
static Collection<DocumentReference> getStorageFilteredUsers(XWikiContext context)
          The list of users to filter when storing statistics.
static VisitStats getVisitFromSession(javax.servlet.http.HttpSession session)
           
static boolean isStatsEnabled(XWikiContext context)
           
static boolean isWikiStatsEnabled(XWikiContext context)
           
static void setRecentActionsFromSession(XWikiContext context, String action, Collection<?> actions)
          Store the recent statistics actions in the session.
static void setVisitInSession(javax.servlet.http.HttpSession session, VisitStats visitStat)
          Store the visit object in the session.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getPeriodAsInt

public static int getPeriodAsInt(Date date,
                                 StatsUtil.PeriodType type)
Computes an integer representation of the passed date using the following format: .

Parameters:
date - the date for which to return an integer representation.
type - the date type. It can be StatsUtil.PeriodType.DAY or StatsUtil.PeriodType.MONTH.
Returns:
the integer representation of the specified date.
Since:
1.4M1
See Also:
SimpleDateFormat

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:

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

getStorageFilteredUsers

public static Collection<DocumentReference> getStorageFilteredUsers(XWikiContext context)
                                                             throws XWikiException
The list of users to filter when storing statistics.

Parameters:
context - the XWiki context
Returns:
the list of users references
Throws:
XWikiException - error when trying to resolve users

getRequestFilteredUsers

public static Collection<DocumentReference> getRequestFilteredUsers(XWikiContext context)
                                                             throws XWikiException
The list of users to filter in view request.

Parameters:
context - the XWiki context
Returns:
the list of users references
Throws:
XWikiException - error when trying to resolve users


Copyright © 2004–2014 XWiki. All rights reserved.