com.xpn.xwiki.plugin.watchlist
Class WatchListStore

java.lang.Object
  extended by com.xpn.xwiki.plugin.watchlist.WatchListStore
All Implemented Interfaces:
org.xwiki.observation.EventListener

public class WatchListStore
extends java.lang.Object
implements org.xwiki.observation.EventListener

WatchList store class. Handles user subscription storage.

Version:
$Id: WatchListStore.java 22900 2009-08-25 13:03:08Z jvdrean $

Nested Class Summary
static class WatchListStore.ElementType
          List of elements that can be watched.
 
Field Summary
static java.lang.String SCHEDULER_SPACE
          Space of the scheduler application.
static java.lang.String SPACE_PAGE_SEP
          Character used to separated space and page in XWiki model.
static java.lang.String WATCHLIST_ELEMENT_SEP
          Character used to separated elements in Watchlist lists (pages, spaces, etc).
static java.lang.String WIKI_SPACE_SEP
          Character used to separated wiki and space in XWiki model.
 
Constructor Summary
WatchListStore()
           
 
Method Summary
 boolean addWatchedElement(java.lang.String user, java.lang.String newWatchedElement, WatchListStore.ElementType type, com.xpn.xwiki.XWikiContext context)
          Add the specified element (document or space) to the corresponding list in the user's WatchList.
 com.xpn.xwiki.objects.BaseObject createWatchListObject(java.lang.String user, com.xpn.xwiki.XWikiContext context)
          Creates a WatchList XWiki Object in the user's profile's page.
 java.util.List<org.xwiki.observation.event.Event> getEvents()
          
 java.lang.String getName()
          
 java.util.List<java.lang.String> getSubscribersForJob(java.lang.String jobId)
           
 java.util.List<java.lang.String> getWatchedElements(java.lang.String user, WatchListStore.ElementType type, com.xpn.xwiki.XWikiContext context)
          Get watched elements for the given element type and user.
 com.xpn.xwiki.objects.BaseObject getWatchListObject(java.lang.String user, com.xpn.xwiki.XWikiContext context)
          Gets the WatchList XWiki Object from user's profile's page.
 java.util.List<java.lang.String> globalSearchDocuments(java.lang.String request, int nb, int start, java.util.List<java.lang.Object> values, com.xpn.xwiki.XWikiContext context)
          Search documents on all the wikis by passing HQL where clause values as parameters.
 void init(com.xpn.xwiki.XWikiContext context)
          Init watchlist store.
 boolean isWatched(java.lang.String element, java.lang.String user, WatchListStore.ElementType type, com.xpn.xwiki.XWikiContext context)
          Is the element watched by the given user.
 void onEvent(org.xwiki.observation.event.Event event, java.lang.Object source, java.lang.Object data)
          
 boolean removeWatchedElement(java.lang.String user, java.lang.String watchedElement, WatchListStore.ElementType type, com.xpn.xwiki.XWikiContext context)
          Remove the specified element (document or space) from the corresponding list in the user's WatchList.
 void virtualInit(com.xpn.xwiki.XWikiContext context)
          Virtual init for watchlist store.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

WATCHLIST_ELEMENT_SEP

public static final java.lang.String WATCHLIST_ELEMENT_SEP
Character used to separated elements in Watchlist lists (pages, spaces, etc).

See Also:
Constant Field Values

WIKI_SPACE_SEP

public static final java.lang.String WIKI_SPACE_SEP
Character used to separated wiki and space in XWiki model.

See Also:
Constant Field Values

SPACE_PAGE_SEP

public static final java.lang.String SPACE_PAGE_SEP
Character used to separated space and page in XWiki model.

See Also:
Constant Field Values

SCHEDULER_SPACE

public static final java.lang.String SCHEDULER_SPACE
Space of the scheduler application.

See Also:
Constant Field Values
Constructor Detail

WatchListStore

public WatchListStore()
Method Detail

init

public void init(com.xpn.xwiki.XWikiContext context)
          throws com.xpn.xwiki.XWikiException
Init watchlist store. Get all the jobs present in the wiki. Create the list of subscribers.

Parameters:
context - the XWiki context
Throws:
com.xpn.xwiki.XWikiException - if the watchlist XWiki class creation fails

virtualInit

public void virtualInit(com.xpn.xwiki.XWikiContext context)
                 throws com.xpn.xwiki.XWikiException
Virtual init for watchlist store. Create the WatchList XWiki class.

Parameters:
context - the XWiki context
Throws:
com.xpn.xwiki.XWikiException - if the watchlist XWiki class creation fails

getSubscribersForJob

public java.util.List<java.lang.String> getSubscribersForJob(java.lang.String jobId)
Parameters:
jobId - ID of the job.
Returns:
subscribers for the given notification job.

getWatchedElements

public java.util.List<java.lang.String> getWatchedElements(java.lang.String user,
                                                           WatchListStore.ElementType type,
                                                           com.xpn.xwiki.XWikiContext context)
                                                    throws com.xpn.xwiki.XWikiException
Get watched elements for the given element type and user.

Parameters:
user - user to match
type - element type to match
context - the XWiki context
Returns:
matching elements
Throws:
com.xpn.xwiki.XWikiException - if retrieval of elements fails

isWatched

public boolean isWatched(java.lang.String element,
                         java.lang.String user,
                         WatchListStore.ElementType type,
                         com.xpn.xwiki.XWikiContext context)
                  throws com.xpn.xwiki.XWikiException
Is the element watched by the given user.

Parameters:
element - the element to look for
user - user to check
type - type of the element
context - the XWiki context
Returns:
true if the element is watched by the user, false otherwise
Throws:
com.xpn.xwiki.XWikiException - if the retrieval of watched elements fails

addWatchedElement

public boolean addWatchedElement(java.lang.String user,
                                 java.lang.String newWatchedElement,
                                 WatchListStore.ElementType type,
                                 com.xpn.xwiki.XWikiContext context)
                          throws com.xpn.xwiki.XWikiException
Add the specified element (document or space) to the corresponding list in the user's WatchList.

Parameters:
user - XWikiUser
newWatchedElement - The name of the element to add (document of space)
type - type of the element to remove
context - Context of the request
Returns:
True if the element was'nt already in list
Throws:
com.xpn.xwiki.XWikiException - if the modification hasn't been saved

removeWatchedElement

public boolean removeWatchedElement(java.lang.String user,
                                    java.lang.String watchedElement,
                                    WatchListStore.ElementType type,
                                    com.xpn.xwiki.XWikiContext context)
                             throws com.xpn.xwiki.XWikiException
Remove the specified element (document or space) from the corresponding list in the user's WatchList.

Parameters:
user - XWiki User
watchedElement - The name of the element to remove (document or space)
type - type of the element to remove
context - Context of the request
Returns:
True if the element was in list and has been removed, false if the element was'nt in the list
Throws:
com.xpn.xwiki.XWikiException - If the WatchList Object cannot be retreived or if the user's profile cannot be saved

createWatchListObject

public com.xpn.xwiki.objects.BaseObject createWatchListObject(java.lang.String user,
                                                              com.xpn.xwiki.XWikiContext context)
                                                       throws com.xpn.xwiki.XWikiException
Creates a WatchList XWiki Object in the user's profile's page.

Parameters:
user - XWiki User
context - Context of the request
Returns:
the watchlist object that has been created
Throws:
com.xpn.xwiki.XWikiException - if the document cannot be saved

getWatchListObject

public com.xpn.xwiki.objects.BaseObject getWatchListObject(java.lang.String user,
                                                           com.xpn.xwiki.XWikiContext context)
                                                    throws com.xpn.xwiki.XWikiException
Gets the WatchList XWiki Object from user's profile's page.

Parameters:
user - XWiki User
context - Context of the request
Returns:
the WatchList XWiki BaseObject
Throws:
com.xpn.xwiki.XWikiException - if BaseObject creation fails

globalSearchDocuments

public java.util.List<java.lang.String> globalSearchDocuments(java.lang.String request,
                                                              int nb,
                                                              int start,
                                                              java.util.List<java.lang.Object> values,
                                                              com.xpn.xwiki.XWikiContext context)
Search documents on all the wikis by passing HQL where clause values as parameters.

Parameters:
request - The HQL where clause.
nb - Number of results to retrieve
start - Offset to use in the search query
values - The where clause values that replaces the question marks (?)
context - The XWiki context
Returns:
a list of document names prefixed with the wiki they come from ex : xwiki:Main.WebHome

onEvent

public void onEvent(org.xwiki.observation.event.Event event,
                    java.lang.Object source,
                    java.lang.Object data)

Specified by:
onEvent in interface org.xwiki.observation.EventListener
See Also:
EventListener.onEvent(org.xwiki.observation.event.Event, java.lang.Object, java.lang.Object)

getEvents

public java.util.List<org.xwiki.observation.event.Event> getEvents()

Specified by:
getEvents in interface org.xwiki.observation.EventListener
See Also:
EventListener.getEvents()

getName

public java.lang.String getName()

Specified by:
getName in interface org.xwiki.observation.EventListener
See Also:
EventListener.getName()


Copyright © 2004-2009 XWiki. All Rights Reserved.