info.magnolia.module.rssaggregator.importhandler
Class RSSFeedImportHandler

java.lang.Object
  extended by info.magnolia.module.data.importer.ImportHandler
      extended by info.magnolia.module.rssaggregator.importhandler.RSSFeedImportHandler

public class RSSFeedImportHandler
extends info.magnolia.module.data.importer.ImportHandler

ImportHandler capable of importing RSS and Atom feeds over http for aggregate feeds defined in RSS Aggregator module.

Allows optional configuration with a RSSFeedFetcher implementation of choice, by means of configuring the node:

 /data/config/importers/rssaggregator
 
If no custom implementation is configured, will fall back to using the default SimpleRSSFeedFetcher.

Author:
had, Rob van der Linden Vooren

Field Summary
 
Fields inherited from class info.magnolia.module.data.importer.ImportHandler
activateImport, automatedExecution, backup, backupFile, deleteOldData, lockDuringImport, MILLI_2_HOUR, name, NODE_DATA_IMPORT_STATE, NODE_DATA_IMPORT_STATE_NEW, NODE_DATA_IMPORT_STATE_OLD, NODE_DATA_USED_IMPORTER_TARGET, repository, running, targets
 
Constructor Summary
RSSFeedImportHandler(RSSFeedFetcher feedFetcher)
          Creates handler with default mappers AggregateFeedContentMapper and FilterPredicateContentMapper.
 
Method Summary
protected  void checkPreConditions()
           
protected  javax.jcr.Node createCategoriesNode(com.sun.syndication.feed.synd.SyndEntry entry, javax.jcr.Node entryNode)
           
protected  javax.jcr.Node createFeedChannelEntryNode(com.sun.syndication.feed.synd.SyndEntry entry, String nodeName, javax.jcr.Node channelNode)
          Create a feed channel entry node under the given channelNode with the given nodeName for the given entry.
 Set doImport(info.magnolia.module.data.importer.ImportTarget target, info.magnolia.cms.core.Content root, Set newContentUUIDs)
           
protected  String getEntryContent(com.sun.syndication.feed.synd.SyndEntry entry)
          Retrieves the main content of an entry.
protected  javax.jcr.Node getOrCreateNode(javax.jcr.Node contentNode, String name, String itemType)
          Behaves exactly like NodeUtil.createPath(Node contentNode, String name, String itemType, boolean save).
 AggregateFilter loadAggregateFilter(javax.jcr.Node aggregateNode)
          Load the AggregateFilter for the AggregateFeed which is represented by the given aggregateNode.
 Set<AggregateFeed> loadAggregates(javax.jcr.Node parentNode)
          Load the aggregate feed definitions and their feed channels from the Content Repository.
protected  javax.jcr.Node loadSingleAggregateNode(javax.jcr.Node parentNode, String aggregateNodeName)
          Load a single aggregate content node from the given parentNode with the given aggregateName.
protected  javax.jcr.Node recreateFeedChannelNode(FeedChannel feedChannel, javax.jcr.Node dataNode)
          Recreate the feed channel content node the given feed channel in the Content Repository.
protected  Set<String> saveAggregates(Set<AggregateFeed> aggregateFeeds, javax.jcr.Node parentNode)
          Save the feed entry content contained in the feed channels of the given aggregateFeeds as children of the given parentNode.
protected  javax.jcr.Node saveFeedChannel(FeedChannel feedChannel, AggregateFilter aggregateFilter, javax.jcr.Node dataNode)
          Save the entries contained in the given FeedChannel that pass the given AggregateFilter in the provided dataNode.
protected  AggregateFeedContentMapper setAggregateFeedContentMapper(AggregateFeedContentMapper aggregateFeedMapper)
          for testing.
 RSSFeedFetcher setFeedFetcher(RSSFeedFetcher rssFeedFetcher)
          for testing.
protected  FilterPredicateContentMapper setFilterPredicateContentMapper(FilterPredicateContentMapper filterPredicateMapper)
          for testing.
 
Methods inherited from class info.magnolia.module.data.importer.ImportHandler
addTarget, backup, collectOldContent, destroy, doPostImport, execute, executeImport, getAutomatedExecution, getBackupPath, getName, getParent, getRepository, getTargets, isActivateImport, isBackup, isDeleteBackupAfterImport, isDeleteOldData, isLockDuringImport, lock, restore, setActivateImport, setAutomatedExecution, setBackup, setBackupPath, setDeleteBackupAfterImport, setDeleteOldData, setImportState, setLockDuringImport, setName, setRepository, setTargets, unlock
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RSSFeedImportHandler

@Inject
public RSSFeedImportHandler(RSSFeedFetcher feedFetcher)
Creates handler with default mappers AggregateFeedContentMapper and FilterPredicateContentMapper.

Method Detail

checkPreConditions

protected void checkPreConditions()
                           throws info.magnolia.module.data.importer.ImportException
Overrides:
checkPreConditions in class info.magnolia.module.data.importer.ImportHandler
Throws:
info.magnolia.module.data.importer.ImportException

doImport

public Set doImport(info.magnolia.module.data.importer.ImportTarget target,
                    info.magnolia.cms.core.Content root,
                    Set newContentUUIDs)
             throws info.magnolia.module.data.importer.ImportException
Specified by:
doImport in class info.magnolia.module.data.importer.ImportHandler
Throws:
info.magnolia.module.data.importer.ImportException

loadAggregates

public Set<AggregateFeed> loadAggregates(javax.jcr.Node parentNode)
                                  throws javax.jcr.RepositoryException
Load the aggregate feed definitions and their feed channels from the Content Repository.

Parameters:
parentNode - the parent content node that holds the aggregate feed nodes
Returns:
the aggregate feeds
Throws:
javax.jcr.RepositoryException - when an exception occurs accessing the Content Repository

saveAggregates

protected Set<String> saveAggregates(Set<AggregateFeed> aggregateFeeds,
                                     javax.jcr.Node parentNode)
                              throws javax.jcr.RepositoryException
Save the feed entry content contained in the feed channels of the given aggregateFeeds as children of the given parentNode. If an AggregateFeed has AggregateFilter defined, feed entries must pass the filter before they will be actually saved in the Content Repository.

Parameters:
parentNode - the parent content node of the aggregate feeds content to save
aggregateFeeds - the aggregate feeds to save
Returns:
a set of UUIDs of the newly created aggregate content nodes
Throws:
javax.jcr.RepositoryException - when an exception occurs accessing the Content Repository

loadSingleAggregateNode

protected javax.jcr.Node loadSingleAggregateNode(javax.jcr.Node parentNode,
                                                 String aggregateNodeName)
                                          throws javax.jcr.RepositoryException
Load a single aggregate content node from the given parentNode with the given aggregateName. If no such aggregate could be found, null is returned.

Parameters:
parentNode - the parentNode to load the node from
aggregateNodeName - the name of the aggregate content node to load
Returns:
the aggregate content node, or null if no such node was found
Throws:
IllegalStateException - when multiple aggregate content nodes with the same name are found
javax.jcr.RepositoryException

getOrCreateNode

protected javax.jcr.Node getOrCreateNode(javax.jcr.Node contentNode,
                                         String name,
                                         String itemType)
                                  throws javax.jcr.RepositoryException
Behaves exactly like NodeUtil.createPath(Node contentNode, String name, String itemType, boolean save). This method exists for testability.

Parameters:
contentNode - the contentNode to (create if non-existent and then) get
name - the name of the node
itemType - the type of the content node
Returns:
the created content node
Throws:
javax.jcr.RepositoryException - when an exception occurs accessing the Content Repository

loadAggregateFilter

public AggregateFilter loadAggregateFilter(javax.jcr.Node aggregateNode)
                                    throws javax.jcr.RepositoryException
Load the AggregateFilter for the AggregateFeed which is represented by the given aggregateNode. Only

Parameters:
aggregateNode - the content node representing the AggregateFeed to load the AggregateFilter for
Returns:
the aggregate filter
Throws:
javax.jcr.RepositoryException - when an exception occurs accessing the Content Repository

saveFeedChannel

protected javax.jcr.Node saveFeedChannel(FeedChannel feedChannel,
                                         AggregateFilter aggregateFilter,
                                         javax.jcr.Node dataNode)
                                  throws javax.jcr.RepositoryException
Save the entries contained in the given FeedChannel that pass the given AggregateFilter in the provided dataNode.

Parameters:
dataNode - the content node to store the feed content under
feedChannel - the feed channel to save
aggregateFilter - the aggregate filter to apply to entries in the feed channel
Throws:
javax.jcr.RepositoryException - when an exception occurs accessing the Content Repository

recreateFeedChannelNode

protected javax.jcr.Node recreateFeedChannelNode(FeedChannel feedChannel,
                                                 javax.jcr.Node dataNode)
                                          throws javax.jcr.RepositoryException
Recreate the feed channel content node the given feed channel in the Content Repository.

Parameters:
dataNode - the node to store the feed channel under
feedChannel - the feed channel to recreate
Returns:
the created feed channel content node
Throws:
javax.jcr.RepositoryException - when an exception occurs accessing the Content Repository

createFeedChannelEntryNode

protected javax.jcr.Node createFeedChannelEntryNode(com.sun.syndication.feed.synd.SyndEntry entry,
                                                    String nodeName,
                                                    javax.jcr.Node channelNode)
                                             throws javax.jcr.RepositoryException
Create a feed channel entry node under the given channelNode with the given nodeName for the given entry.

Parameters:
entry - the feed channel entry to save
nodeName - the name of the feed channel entry node to create
channelNode - the feed channel content node to create the feed channel entry under
Throws:
javax.jcr.RepositoryException - when an exception occurs accessing the Content Repository

getEntryContent

protected String getEntryContent(com.sun.syndication.feed.synd.SyndEntry entry)
Retrieves the main content of an entry.

Parameters:
entry - Feed entry holding all data.
Returns:
Entry content as String or empty String if no content is available.

createCategoriesNode

protected javax.jcr.Node createCategoriesNode(com.sun.syndication.feed.synd.SyndEntry entry,
                                              javax.jcr.Node entryNode)
                                       throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

setAggregateFeedContentMapper

protected AggregateFeedContentMapper setAggregateFeedContentMapper(AggregateFeedContentMapper aggregateFeedMapper)
for testing.


setFeedFetcher

public RSSFeedFetcher setFeedFetcher(RSSFeedFetcher rssFeedFetcher)
for testing.


setFilterPredicateContentMapper

protected FilterPredicateContentMapper setFilterPredicateContentMapper(FilterPredicateContentMapper filterPredicateMapper)
for testing.



Copyright © 2014 Magnolia International Ltd.. All Rights Reserved.