org.olat.modules.webFeed.managers
Class FeedManagerImpl

java.lang.Object
  extended by org.olat.core.logging.LogDelegator
      extended by org.olat.core.manager.BasicManager
          extended by org.olat.modules.webFeed.managers.FeedManager
              extended by org.olat.modules.webFeed.managers.FeedManagerImpl

public class FeedManagerImpl
extends FeedManager

This is the actual feed manager implementation. It handles all operations on the various feeds and items.

Initial Date: Feb 17, 2009

Author:
Gregor Wassmann

Field Summary
static java.lang.String ITEMS_DIR
           
static com.thoughtworks.xstream.XStream xstream
           
 
Fields inherited from class org.olat.modules.webFeed.managers.FeedManager
KIND_BLOG, KIND_PODCAST, RESOURCE_NAME, RSS_FEED_NAME
 
Constructor Summary
FeedManagerImpl()
          Please use FeedManager.getInstance()!!! This constructor is ONLY intended for JUnit tests.
 
Method Summary
 LockResult acquireLock(OLATResourceable feed, Identity identity)
          Acquires the lock on the specified feed
 LockResult acquireLock(OLATResourceable feed, Item item, Identity identity)
          Acquires the lock of an item
 void addItem(Item item, FileElement file, Feed feed)
          Adds the given Item to the Feed.
 OLATResourceable copy(OLATResourceable feed)
          Copies a given feed resourcable
 OLATResourceable createBlogResource()
          Creates a blank feed object and writes it to the file system
 MediaResource createFeedFile(OLATResourceable ores, Identity identity, java.lang.Long courseId, java.lang.String nodeId)
          Creates the RSS feed resource.
 MediaResource createFeedMediaFile(OLATResourceable feed, java.lang.String fileName)
          Returns the media file of the feed
 VFSContainer createItemContainer(Feed feed, Item item)
          Prepare the filesystem for a new item, create the item container and all necessary sub container, e.g.
 MediaResource createItemMediaFile(OLATResourceable feed, java.lang.String itemId, java.lang.String fileName)
          Returns the media file of the item
 OLATResourceable createPodcastResource()
          Creates a blank feed object and writes it to the (virtual) file system
 void delete(OLATResourceable feed)
          Deletes a given feed.
 void deleteImage(Feed feed)
          Delete the image of the feed
 VFSLeaf getFeedArchive(OLATResourceable resource)
          Create and returns a zip-file as VFSLeaf of the given feed resourue
 VFSMediaResource getFeedArchiveMediaResource(OLATResourceable resource)
          Creates and returns a zip-file media resource of the given feed resource
 java.lang.String getFeedBaseUri(Feed feed, Identity identity, java.lang.Long courseId, java.lang.String nodeId)
          Returns the base URI of the feed including user identity key and token if necessary.
 VFSContainer getFeedContainer(OLATResourceable ores)
          Returns the container of the feed
 Feed getFeedLigth(OLATResourceable ores)
          Returns the feed with the provided id or null.
 VFSContainer getFeedMediaContainer(OLATResourceable feed)
          Returns the container of media files
 VFSContainer getItemContainer(Item item, Feed feed)
          Returns the container of the item which belongs to the feed
 java.io.File getItemEnclosureFile(Item item, Feed feed)
          Returns the File of the item's enclosure if it exists or null
 VFSContainer getItemMediaContainer(Item item, Feed feed)
          Returns the media container of the item of feed
static Item loadItem(VFSItem container)
          Loads an item from file.
 java.util.List<Item> loadItems(Feed feed)
          Load all items of the feed (from file system or the external feed)
 Feed readFeed(OLATResourceable ores)
          Reads a feed resource by the resource id and returns the feed object.
static Feed readFeedFile(VFSContainer feedContainer)
          Returns the feed in the given container.
 void releaseLock(LockResult lock)
          Releases a lock
 void remove(Item item, Feed feed)
          Removes the given Item from the Feed.
 void setEnclosure(FileElement file, Item item, Feed feed)
           
 void setImage(FileElement image, Feed feed)
          Set the image of the feed (update handled separately)
 Feed updateFeedMetadata(Feed feed)
          Update the feed metadata from the given feed object
 Feed updateFeedMode(java.lang.Boolean external, Feed feed)
          Update the feed source mode
 void updateItem(Item item, FileElement file, Feed feed)
           
 ValidatedURL validateFeedUrl(java.lang.String url, java.lang.String type)
          Validates a feed url.
 
Methods inherited from class org.olat.modules.webFeed.managers.FeedManager
getFeedKind, getInstance, isLocked
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ITEMS_DIR

public static final java.lang.String ITEMS_DIR
See Also:
Constant Field Values

xstream

public static final com.thoughtworks.xstream.XStream xstream
Constructor Detail

FeedManagerImpl

public FeedManagerImpl()
Please use FeedManager.getInstance()!!! This constructor is ONLY intended for JUnit tests.

Method Detail

createPodcastResource

public OLATResourceable createPodcastResource()
Creates a blank feed object and writes it to the (virtual) file system

Specified by:
createPodcastResource in class FeedManager
Returns:
The resource
See Also:
FeedManager.createPodcastResource()

createBlogResource

public OLATResourceable createBlogResource()
Creates a blank feed object and writes it to the file system

Specified by:
createBlogResource in class FeedManager
Returns:
The resource
See Also:
FeedManager.createPodcastResource()

delete

public void delete(OLATResourceable feed)
Description copied from class: FeedManager
Deletes a given feed.

Specified by:
delete in class FeedManager
See Also:
FeedManager.delete(org.olat.core.id.OLATResourceable)

readFeed

public Feed readFeed(OLATResourceable ores)
Description copied from class: FeedManager
Reads a feed resource by the resource id and returns the feed object.

Specified by:
readFeed in class FeedManager
Returns:
The feed
See Also:
FeedManager.readFeed(org.olat.core.id.OLATResourceable)

getFeedLigth

public Feed getFeedLigth(OLATResourceable ores)
Description copied from class: FeedManager
Returns the feed with the provided id or null. This is thought to get the feed information in an efficient way and without the necessity of loading any items.

Specified by:
getFeedLigth in class FeedManager
Parameters:
ores - The feed to be re-read
Returns:
The newly read feed (without items)
See Also:
FeedManager.getFeedLigth(org.olat.core.id.OLATResourceable)

readFeedFile

public static Feed readFeedFile(VFSContainer feedContainer)
Returns the feed in the given container. It is public and static to be accessible by PodcastFileResource.

Parameters:
feedContainer -
Returns:
The Feed upon success

loadItems

public java.util.List<Item> loadItems(Feed feed)
Load all items of the feed (from file system or the external feed)

Specified by:
loadItems in class FeedManager
Parameters:
feed -

loadItem

public static Item loadItem(VFSItem container)
Loads an item from file. Used for validation in PodcastFileResource, that's why its public and static.

Parameters:
container -
Returns:
The item

remove

public void remove(Item item,
                   Feed feed)
Description copied from class: FeedManager
Removes the given Item from the Feed. Its content will be deleted.

Specified by:
remove in class FeedManager
See Also:
FeedManager.remove(org.olat.modules.webFeed.models.Item, org.olat.modules.webFeed.models.Feed)

addItem

public void addItem(Item item,
                    FileElement file,
                    Feed feed)
Description copied from class: FeedManager
Adds the given Item to the Feed.

Specified by:
addItem in class FeedManager
See Also:
FeedManager.addItem(org.olat.modules.webFeed.models.Item, org.olat.core.gui.components.form.flexible.elements.FileElement, org.olat.modules.webFeed.models.Feed)

getFeedContainer

public VFSContainer getFeedContainer(OLATResourceable ores)
Description copied from class: FeedManager
Returns the container of the feed

Specified by:
getFeedContainer in class FeedManager
Returns:
The feed container
See Also:
FeedManager.getFeedContainer(org.olat.core.id.OLATResourceable)

setEnclosure

public void setEnclosure(FileElement file,
                         Item item,
                         Feed feed)
Parameters:
file -
item -
feed -

getItemContainer

public VFSContainer getItemContainer(Item item,
                                     Feed feed)
Description copied from class: FeedManager
Returns the container of the item which belongs to the feed

Specified by:
getItemContainer in class FeedManager
Returns:
The container of the item
See Also:
FeedManager.getItemContainer(org.olat.modules.webFeed.models.Item, org.olat.modules.webFeed.models.Feed)

getItemMediaContainer

public VFSContainer getItemMediaContainer(Item item,
                                          Feed feed)
Description copied from class: FeedManager
Returns the media container of the item of feed

Specified by:
getItemMediaContainer in class FeedManager
Returns:
The media container of the item
See Also:
FeedManager.getItemMediaContainer(org.olat.modules.webFeed.models.Item, org.olat.modules.webFeed.models.Feed)

getItemEnclosureFile

public java.io.File getItemEnclosureFile(Item item,
                                         Feed feed)
Description copied from class: FeedManager
Returns the File of the item's enclosure if it exists or null

Specified by:
getItemEnclosureFile in class FeedManager
Returns:
The enclosure media file
See Also:
FeedManager.getItemMediaContainer(org.olat.modules.webFeed.models.Item, org.olat.modules.webFeed.models.Feed)

getFeedMediaContainer

public VFSContainer getFeedMediaContainer(OLATResourceable feed)
Returns the container of media files

Parameters:
feed -
Returns:
The feed media container

updateItem

public void updateItem(Item item,
                       FileElement file,
                       Feed feed)
Specified by:
updateItem in class FeedManager
See Also:
FeedManager.updateItem(org.olat.modules.webFeed.models.Item, org.olat.core.gui.components.form.flexible.elements.FileElement, org.olat.modules.webFeed.models.Feed)

updateFeedMode

public Feed updateFeedMode(java.lang.Boolean external,
                           Feed feed)
Description copied from class: FeedManager
Update the feed source mode

Specified by:
updateFeedMode in class FeedManager
Parameters:
external - True: set to be an external feed; false: this is an internal feed; null=undefined
Returns:
Feed the updated feed object
See Also:
FeedManager.updateFeedMode(java.lang.Boolean, org.olat.modules.webFeed.models.Feed)

updateFeedMetadata

public Feed updateFeedMetadata(Feed feed)
Description copied from class: FeedManager
Update the feed metadata from the given feed object

Specified by:
updateFeedMetadata in class FeedManager
Returns:
See Also:
FeedManager.updateFeedMetadata(org.olat.modules.webFeed.models.Feed)

createItemMediaFile

public MediaResource createItemMediaFile(OLATResourceable feed,
                                         java.lang.String itemId,
                                         java.lang.String fileName)
Description copied from class: FeedManager
Returns the media file of the item

Specified by:
createItemMediaFile in class FeedManager
Returns:
The media resource (audio or video file of the feed item)
See Also:
org.olat.modules.webFeed.managers.FeedManager#createMediaResource(java.lang.Long, java.lang.String, java.lang.String, java.lang.String)

createFeedMediaFile

public MediaResource createFeedMediaFile(OLATResourceable feed,
                                         java.lang.String fileName)
Description copied from class: FeedManager
Returns the media file of the feed

Specified by:
createFeedMediaFile in class FeedManager
Returns:
The media file of the feed
See Also:
org.olat.modules.webFeed.managers.FeedManager#createMediaResource(java.lang.Long, java.lang.String, java.lang.String)

getFeedBaseUri

public java.lang.String getFeedBaseUri(Feed feed,
                                       Identity identity,
                                       java.lang.Long courseId,
                                       java.lang.String nodeId)
Description copied from class: FeedManager
Returns the base URI of the feed including user identity key and token if necessary.

Specified by:
getFeedBaseUri in class FeedManager
Returns:
The base URI of the (RSS) feed
See Also:
org.olat.modules.webFeed.managers.FeedManager#getFeedUri(org.olat.modules.webFeed.models.Feed, java.lang.Long)

createFeedFile

public MediaResource createFeedFile(OLATResourceable ores,
                                    Identity identity,
                                    java.lang.Long courseId,
                                    java.lang.String nodeId)
Description copied from class: FeedManager
Creates the RSS feed resource.

Specified by:
createFeedFile in class FeedManager
Returns:
The RSS feed as a MediaResource
See Also:
org.olat.modules.webFeed.managers.FeedManager#createFeedMediaResource(java.lang.Long, java.lang.String, java.lang.Long)

validateFeedUrl

public ValidatedURL validateFeedUrl(java.lang.String url,
                                    java.lang.String type)
Description copied from class: FeedManager
Validates a feed url.

Specified by:
validateFeedUrl in class FeedManager
Returns:
valid url (rss, atom etc.)
See Also:
org.olat.modules.webFeed.managers.FeedManager#isValidFeedUrl(java.lang.String)

copy

public OLATResourceable copy(OLATResourceable feed)
Description copied from class: FeedManager
Copies a given feed resourcable

Specified by:
copy in class FeedManager
See Also:
FeedManager.copy(org.olat.core.id.OLATResourceable)

getFeedArchiveMediaResource

public VFSMediaResource getFeedArchiveMediaResource(OLATResourceable resource)
Description copied from class: FeedManager
Creates and returns a zip-file media resource of the given feed resource

Specified by:
getFeedArchiveMediaResource in class FeedManager
Returns:
A zip-file media resource
See Also:
FeedManager.getFeedArchiveMediaResource(org.olat.core.id.OLATResourceable)

getFeedArchive

public VFSLeaf getFeedArchive(OLATResourceable resource)
Description copied from class: FeedManager
Create and returns a zip-file as VFSLeaf of the given feed resourue

Specified by:
getFeedArchive in class FeedManager
Parameters:
resource - the resource
Returns:
The VFSLeaf
See Also:
FeedManager.getFeedArchive(org.olat.core.id.OLATResourceable)

releaseLock

public void releaseLock(LockResult lock)
Description copied from class: FeedManager
Releases a lock

Specified by:
releaseLock in class FeedManager
Parameters:
lock - The lock to be released
See Also:
FeedManager.releaseLock(org.olat.core.util.coordinate.LockResult)

acquireLock

public LockResult acquireLock(OLATResourceable feed,
                              Identity identity)
Description copied from class: FeedManager
Acquires the lock on the specified feed

Specified by:
acquireLock in class FeedManager
Parameters:
feed - The feed to be locked
identity - The person who is locking the resource
Returns:
The lock result
See Also:
FeedManager.acquireLock(org.olat.core.id.OLATResourceable, org.olat.core.id.Identity)

acquireLock

public LockResult acquireLock(OLATResourceable feed,
                              Item item,
                              Identity identity)
Description copied from class: FeedManager
Acquires the lock of an item

Specified by:
acquireLock in class FeedManager
Parameters:
feed - The item's feed
item - The item to be locked
identity - The person who is locking the resource
Returns:
The lock result
See Also:
FeedManager.acquireLock(org.olat.core.id.OLATResourceable, org.olat.modules.webFeed.models.Item, org.olat.core.id.Identity)

setImage

public void setImage(FileElement image,
                     Feed feed)
Description copied from class: FeedManager
Set the image of the feed (update handled separately)

Specified by:
setImage in class FeedManager
See Also:
FeedManager.setImage(org.olat.core.gui.components.form.flexible.elements.FileElement, org.olat.modules.webFeed.models.Feed)

deleteImage

public void deleteImage(Feed feed)
Description copied from class: FeedManager
Delete the image of the feed

Specified by:
deleteImage in class FeedManager
See Also:
FeedManager.deleteImage(org.olat.modules.webFeed.models.Feed)

createItemContainer

public VFSContainer createItemContainer(Feed feed,
                                        Item item)
Description copied from class: FeedManager
Prepare the filesystem for a new item, create the item container and all necessary sub container, e.g. the media container

Specified by:
createItemContainer in class FeedManager
Returns:
the container for the item
See Also:
FeedManager.createItemContainer(org.olat.modules.webFeed.models.Feed, org.olat.modules.webFeed.models.Item)