org.blojsom.fetcher
Class StandardFetcher

java.lang.Object
  extended byorg.blojsom.fetcher.StandardFetcher
All Implemented Interfaces:
BlojsomConstants, BlojsomFetcher
Direct Known Subclasses:
CachingFetcher

public class StandardFetcher
extends java.lang.Object
implements BlojsomFetcher, BlojsomConstants

StandardFetcher

Since:
blojsom 1.8
Version:
$Id: StandardFetcher.java,v 1.32 2006/01/04 16:59:54 czarneckid Exp $
Author:
David Czarnecki

Field Summary
protected  BlojsomConfiguration _blojsomConfiguration
           
protected  java.lang.String _ignoreFlavors
           
protected  org.apache.commons.logging.Log _logger
           
protected static java.lang.String DEFAULT_IGNORE_FLAVORS
           
protected static java.lang.String DEPTH_PARAM
           
protected static java.lang.String IGNORE_FLAVORS_PARAM
           
protected static java.lang.String STANDARD_FETCHER_CATEGORY
           
protected static java.lang.String STANDARD_FETCHER_DEPTH
           
 
Fields inherited from interface org.blojsom.fetcher.BlojsomFetcher
FETCHER_CATEGORY, FETCHER_FLAVOR, FETCHER_NUM_POSTS_INTEGER, FETCHER_PERMALINK
 
Fields inherited from interface org.blojsom.util.BlojsomConstants
ADMINISTRATORS_IP, BLOG_ADMIN_URL_IP, BLOG_ADMINISTRATION_LOCALE_IP, BLOG_AUTHORIZATION_IP, BLOG_BASE_URL_IP, BLOG_BLACKLIST_FILE_IP, BLOG_COMMENTS_DIRECTORY_IP, BLOG_COMMENTS_ENABLED_IP, BLOG_COUNTRY_DEFAULT, BLOG_COUNTRY_IP, BLOG_DEFAULT_CATEGORY_EXCLUSION_MAPPING_IP, BLOG_DEFAULT_CATEGORY_MAPPING_IP, BLOG_DEFAULT_FETCHER, BLOG_DEFAULT_FILE_EXTENSION_IP, BLOG_DEFAULT_FLAVOR_IP, BLOG_DEFAULT_PROPERTIES, BLOG_DEPTH_IP, BLOG_DESCRIPTION_IP, BLOG_DIRECTORY_FILTER_IP, BLOG_EMAIL_ENABLED_IP, BLOG_ENTRIES_DISPLAY_DEFAULT, BLOG_ENTRIES_DISPLAY_IP, BLOG_ENTRY_META_DATA_EXTENSION_IP, BLOG_FILE_ENCODING_IP, BLOG_FILE_EXTENSIONS_IP, BLOG_HOME_IP, BLOG_LANGUAGE_DEFAULT, BLOG_LANGUAGE_IP, BLOG_NAME_IP, BLOG_OWNER, BLOG_OWNER_EMAIL, BLOG_PERMISSIONS_IP, BLOG_PINGBACKS_DIRECTORY_IP, BLOG_PINGBACKS_ENABLED_IP, BLOG_PROPERTIES_EXTENSIONS_IP, BLOG_TRACKBACK_DIRECTORY_IP, BLOG_TRACKBACKS_ENABLED_IP, BLOG_URL_IP, BLOJSOM_ALL_CATEGORIES, BLOJSOM_AUTHORIZATION_PROVIDER_IP, BLOJSOM_BLOG, BLOJSOM_BLOG_HOME_IP, BLOJSOM_BROADCASTER_IP, BLOJSOM_CATEGORIES, BLOJSOM_COMMENTS_ENABLED, BLOJSOM_CONFIGURATION_BASE_DIRECTORY_IP, BLOJSOM_CONFIGURATION_IP, BLOJSOM_DATE, BLOJSOM_DATE_ISO8601, BLOJSOM_DATE_OBJECT, BLOJSOM_DATE_UTC, BLOJSOM_DEFAULT_BROADCASTER, BLOJSOM_DEFAULT_CONFIGURATION_BASE_DIRECTORY, BLOJSOM_DEFAULT_RESOURCE_DIRECTORY, BLOJSOM_DEFAULT_RESOURCE_MANAGER, BLOJSOM_DEFAULT_TEMPLATES_DIRECTORY, BLOJSOM_DEFAULT_USER_IP, BLOJSOM_EMAIL_ENABLED, BLOJSOM_ENTRIES, BLOJSOM_FETCHER_IP, BLOJSOM_FLAVOR_CONFIGURATION_IP, BLOJSOM_INSTALLATION_DIRECTORY_IP, BLOJSOM_INSTALLED_LOCALES_IP, BLOJSOM_LAST_MODIFIED, BLOJSOM_LISTENER_CONFIGURATION_IP, BLOJSOM_PERMALINK, BLOJSOM_PERMALINK_NEXT_ENTRY, BLOJSOM_PERMALINK_PREVIOUS_ENTRY, BLOJSOM_PLUGIN_CHAIN, BLOJSOM_PLUGIN_CONFIGURATION_IP, BLOJSOM_PLUGINS, BLOJSOM_REQUESTED_CATEGORY, BLOJSOM_REQUESTED_FLAVOR, BLOJSOM_RESOURCE_DIRECTORY_IP, BLOJSOM_RESOURCE_MANAGER_BUNDLES_IP, BLOJSOM_RESOURCE_MANAGER_CONTEXT_KEY, BLOJSOM_RESOURCE_MANAGER_IP, BLOJSOM_SITE_URL, BLOJSOM_TEMPLATES_DIRECTORY_IP, BLOJSOM_USER, BLOJSOM_USERS_IP, BLOJSOM_VERSION, BLOJSOM_VERSION_NUMBER, CACHE_CONTROL_HTTP_HEADER, CATEGORY_PARAM, COMMENT_EXTENSION, DEFAULT_AUTHORIZATION_PROVIDER, DEFAULT_COMMENTS_DIRECTORY, DEFAULT_DIGEST_ALGORITHM, DEFAULT_DISPATCHER_CONFIGURATION_FILE, DEFAULT_ENTRY_EXTENSION, DEFAULT_FLAVOR_CONFIGURATION_FILE, DEFAULT_FLAVOR_HTML, DEFAULT_METADATA_EXTENSION, DEFAULT_PERMISSIONS_CONFIGURATION_FILE, DEFAULT_PINGBACKS_DIRECTORY, DEFAULT_PLUGIN_CONFIGURATION_FILE, DEFAULT_PROPERTIES_EXTENSIONS, DEFAULT_TRACKBACK_DIRECTORY, DESCRIPTION_KEY, DIGEST_ALGORITHM, FLAVOR_PARAM, HTTP_ETAG, HTTP_LASTMODIFIED, INFINITE_BLOG_DEPTH, ISO_8601_DATE_FORMAT, LINE_SEPARATOR, LINEAR_NAVIGATION_ENABLED_IP, MAX_HASHABLE_LENGTH, NAME_KEY, NO_CACHE_HTTP_HEADER_VALUE, OVERRIDE_LASTMODIFIED_PARAM, PAGE_PARAM, PAGE_PARAM_ARCHIVE, PERMALINK_PARAM, PINGBACK_EXTENSION, PLUGINS_PARAM, PRAGMA_HTTP_HEADER, PREFERRED_SYNDICATION_FLAVOR, RECURSIVE_CATEGORIES, REDIRECT_TO_PARAM, RFC_822_DATE_FORMAT, SHORT_ISO_8601_DATE_FORMAT, TRACKBACK_EXTENSION, USE_ENCRYPTED_PASSWORDS, UTC_DATE_FORMAT, UTF8, WHITESPACE, XMLRPC_ENABLED_IP
 
Constructor Summary
StandardFetcher()
          Default constructor
 
Method Summary
 void destroy()
          Called when BlojsomServlet is taken out of service
 BlogCategory[] fetchCategories(javax.servlet.http.HttpServletRequest httpServletRequest, javax.servlet.http.HttpServletResponse httpServletResponse, BlogUser user, java.lang.String flavor, java.util.Map context)
          Fetch a set of BlogCategory objects
 BlogCategory[] fetchCategories(java.util.Map fetchParameters, BlogUser user)
          Fetch a set of BlogCategory objects.
 BlogEntry[] fetchEntries(javax.servlet.http.HttpServletRequest httpServletRequest, javax.servlet.http.HttpServletResponse httpServletResponse, BlogUser user, java.lang.String flavor, java.util.Map context)
          Fetch a set of BlogEntry objects.
 BlogEntry[] fetchEntries(java.util.Map fetchParameters, BlogUser user)
          Fetch a set of BlogEntry objects.
protected  BlogCategory[] getBlogCategories(BlogUser blogUser, int blogDirectoryDepth)
          Return a list of categories for the blog that are appropriate in a hyperlink
protected  BlogCategory getBlogCategory(BlogUser user, javax.servlet.http.HttpServletRequest httpServletRequest)
          Determine the blog category based on the request
protected  BlogCategory[] getBlogCategoryHierarchy(BlogUser blogUser, BlogCategory currentCategory, int blogDirectoryDepth)
          Return a list of categories up the category hierarchy from the current category.
protected  BlogEntry[] getEntriesAllCategories(BlogUser user, java.lang.String[] categoryFilter, java.lang.String[] categoryExclusionFilter, int maxBlogEntries, int blogDirectoryDepth)
          Retrieve entries for all the categories in the blog.
protected  BlogEntry[] getEntriesAllCategories(BlogUser user, java.lang.String flavor, int maxBlogEntries, int blogDirectoryDepth)
          Retrive entries for the categories, using the values set for the default category mapping and the configured number of blog entries to retrieve from each category
protected  BlogEntry[] getEntriesForCategory(BlogUser user, BlogCategory requestedCategory, int maxBlogEntries)
          Retrieve all of the entries for a requested category
protected  BlogEntry[] getPermalinkEntry(BlogUser blogUser, BlogCategory requestedCategory, java.lang.String permalink)
          Retrieve a permalink entry from the entries for a given category
 void init(javax.servlet.ServletConfig servletConfig, BlojsomConfiguration blojsomConfiguration)
          Initialize this fetcher.
 BlogCategory newBlogCategory()
          Return a new blog category instance
 BlogComment newBlogComment()
          Return a new BlogComment instance
 BlogEntry newBlogEntry()
          Return a new blog entry instance.
 Pingback newPingback()
          Return a new Pingback instance
 Trackback newTrackback()
          Return a new Trackback instance
protected  void recursiveCategoryBuilder(BlogUser blogUser, int blogDepth, int blogDirectoryDepth, java.lang.String blogDirectory, java.util.ArrayList categoryList)
          Build a list of blog categories recursively
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_logger

protected org.apache.commons.logging.Log _logger

DEPTH_PARAM

protected static final java.lang.String DEPTH_PARAM
See Also:
Constant Field Values

IGNORE_FLAVORS_PARAM

protected static final java.lang.String IGNORE_FLAVORS_PARAM
See Also:
Constant Field Values

DEFAULT_IGNORE_FLAVORS

protected static final java.lang.String DEFAULT_IGNORE_FLAVORS
See Also:
Constant Field Values

STANDARD_FETCHER_CATEGORY

protected static final java.lang.String STANDARD_FETCHER_CATEGORY
See Also:
Constant Field Values

STANDARD_FETCHER_DEPTH

protected static final java.lang.String STANDARD_FETCHER_DEPTH
See Also:
Constant Field Values

_ignoreFlavors

protected java.lang.String _ignoreFlavors

_blojsomConfiguration

protected BlojsomConfiguration _blojsomConfiguration
Constructor Detail

StandardFetcher

public StandardFetcher()
Default constructor

Method Detail

init

public void init(javax.servlet.ServletConfig servletConfig,
                 BlojsomConfiguration blojsomConfiguration)
          throws BlojsomFetcherException
Initialize this fetcher. This method only called when the fetcher is instantiated.

Specified by:
init in interface BlojsomFetcher
Parameters:
servletConfig - Servlet config object for the plugin to retrieve any initialization parameters
blojsomConfiguration - blojsom configuration information
Throws:
BlojsomFetcherException - If there is an error initializing the fetcher

newBlogEntry

public BlogEntry newBlogEntry()
Return a new blog entry instance. This methods returns an instance of FileBackedBlogEntry.

Specified by:
newBlogEntry in interface BlojsomFetcher
Returns:
Blog entry instance
Since:
blojsom 1.9

newBlogCategory

public BlogCategory newBlogCategory()
Return a new blog category instance

Specified by:
newBlogCategory in interface BlojsomFetcher
Returns:
Blog category instance
Since:
blojsom 1.9.1

newBlogComment

public BlogComment newBlogComment()
Return a new BlogComment instance

Specified by:
newBlogComment in interface BlojsomFetcher
Returns:
BlogComment
Since:
blojsom 2.26

newTrackback

public Trackback newTrackback()
Return a new Trackback instance

Specified by:
newTrackback in interface BlojsomFetcher
Returns:
Trackback
Since:
blojsom 2.26

newPingback

public Pingback newPingback()
Return a new Pingback instance

Specified by:
newPingback in interface BlojsomFetcher
Returns:
Pingback
Since:
blojsom 2.26

getPermalinkEntry

protected BlogEntry[] getPermalinkEntry(BlogUser blogUser,
                                        BlogCategory requestedCategory,
                                        java.lang.String permalink)
Retrieve a permalink entry from the entries for a given category

Parameters:
blogUser - Blog information
requestedCategory - Requested category
permalink - Permalink entry requested
Returns:
Blog entry array containing the single requested permalink entry, or BlogEntry[0] if the permalink entry was not found

getEntriesForCategory

protected BlogEntry[] getEntriesForCategory(BlogUser user,
                                            BlogCategory requestedCategory,
                                            int maxBlogEntries)
Retrieve all of the entries for a requested category

Parameters:
requestedCategory - Requested category
maxBlogEntries - Maximum number of blog entries to retrieve from a blog category
Returns:
Blog entry array containing the list of blog entries for the requested category, or BlogEntry[0] if there are no entries for the category

getEntriesAllCategories

protected BlogEntry[] getEntriesAllCategories(BlogUser user,
                                              java.lang.String flavor,
                                              int maxBlogEntries,
                                              int blogDirectoryDepth)
Retrive entries for the categories, using the values set for the default category mapping and the configured number of blog entries to retrieve from each category

Parameters:
flavor - Requested flavor
maxBlogEntries - Maximum number of entries to retrieve per category
blogDirectoryDepth - Depth to which the fetcher should stop looking for categories
Returns:
Blog entry array containing the list of blog entries for the categories or BlogEntry[0] if there are no entries

getEntriesAllCategories

protected BlogEntry[] getEntriesAllCategories(BlogUser user,
                                              java.lang.String[] categoryFilter,
                                              java.lang.String[] categoryExclusionFilter,
                                              int maxBlogEntries,
                                              int blogDirectoryDepth)
Retrieve entries for all the categories in the blog. This method will the parameter maxBlogEntries to limit the entries it retrieves from each of the categories. Entries from the categories are sorted based on file time.

Parameters:
categoryFilter - If null, a list of all the categories is retrieved, otherwise only the categories in the list will be used to search for entries
categoryExclusionFilter - If not null the categories in the list will be excluded from the entries' search
maxBlogEntries - Maximum number of blog entries to retrieve from each category
blogDirectoryDepth - Depth to which the fetcher should stop looking for categories
Returns:
Blog entry array containing the list of blog entries for the categories or BlogEntry[0] if there are no entries

getBlogCategory

protected BlogCategory getBlogCategory(BlogUser user,
                                       javax.servlet.http.HttpServletRequest httpServletRequest)
Determine the blog category based on the request

Parameters:
httpServletRequest - Request
Returns:
BlogCategory of the requested category

fetchEntries

public BlogEntry[] fetchEntries(javax.servlet.http.HttpServletRequest httpServletRequest,
                                javax.servlet.http.HttpServletResponse httpServletResponse,
                                BlogUser user,
                                java.lang.String flavor,
                                java.util.Map context)
                         throws BlojsomFetcherException
Fetch a set of BlogEntry objects.

Specified by:
fetchEntries in interface BlojsomFetcher
Parameters:
httpServletRequest - Request
httpServletResponse - Response
user - BlogUser instance
flavor - Flavor
context - Context
Returns:
Blog entries retrieved for the particular request
Throws:
BlojsomFetcherException - If there is an error retrieving the blog entries for the request

fetchEntries

public BlogEntry[] fetchEntries(java.util.Map fetchParameters,
                                BlogUser user)
                         throws BlojsomFetcherException
Fetch a set of BlogEntry objects. This method is intended to be used for other components such as the XML-RPC handlers that cannot generate servlet request and response objects, but still need to be able to fetch entries. Implementations of this method must be explicit about the exact parameter names and types that are expected to return an appropriate set of BlogEntry objects. The following table describes the parameters accepted by this method and their return value. The value for fetchParameters may represent the keys and data types that should be present in the fetchParameters map to return the proper data.

fetchParameters value Return value
"FETCHER_CATEGORY" (BlogCategory) and "FETCHER_PERMALINK" (String) return a single BlogEntry for the requested permalink
"FETCHER_CATEGORY" (BlogCategory) and "FETCHER_NUM_POSTS_INTEGER" (Integer) return entries for the requested category up to the value indicated by the number of entries
"FETCHER_FLAVOR" (String) and "FETCHER_NUM_POSTS_INTEGER" (Integer) return all entries for the default category ("/") for the requested flavor up to the value indicated by the number of entries

Specified by:
fetchEntries in interface BlojsomFetcher
Parameters:
fetchParameters - Parameters which will be used to retrieve blog entries
user - BlogUser instance
Returns:
Blog entries retrieved for the particular request
Throws:
BlojsomFetcherException - If there is an error retrieving the blog entries for the request

recursiveCategoryBuilder

protected void recursiveCategoryBuilder(BlogUser blogUser,
                                        int blogDepth,
                                        int blogDirectoryDepth,
                                        java.lang.String blogDirectory,
                                        java.util.ArrayList categoryList)
Build a list of blog categories recursively

Parameters:
blogUser - BlogUser
blogDepth - Depth at which the current iteration is running
blogDirectoryDepth - Depth to which the fetcher should stop looking for categories
blogDirectory - Directory in which the current iteration is running
categoryList - Dynamic list of categories that gets added to as it explores directories

getBlogCategories

protected BlogCategory[] getBlogCategories(BlogUser blogUser,
                                           int blogDirectoryDepth)
Return a list of categories for the blog that are appropriate in a hyperlink

Parameters:
blogUser - BlogUser
blogDirectoryDepth - Depth to which the fetcher should stop looking for categories
Returns:
List of BlogCategory objects

getBlogCategoryHierarchy

protected BlogCategory[] getBlogCategoryHierarchy(BlogUser blogUser,
                                                  BlogCategory currentCategory,
                                                  int blogDirectoryDepth)
Return a list of categories up the category hierarchy from the current category. If the "/" category is requested, null is returned. Up the hierarchy, only the parent categories are returned. Down the hierarchy from the current category, all children are returned while obeying the blog-directory-depth parameter.

Parameters:
blogUser - BlogUser
currentCategory - Current category in the blog category hierarchy
blogDirectoryDepth - Depth to which the fetcher should stop looking for categories
Returns:
List of blog categories or null if "/" category is requested or there are no sub-categories

fetchCategories

public BlogCategory[] fetchCategories(javax.servlet.http.HttpServletRequest httpServletRequest,
                                      javax.servlet.http.HttpServletResponse httpServletResponse,
                                      BlogUser user,
                                      java.lang.String flavor,
                                      java.util.Map context)
                               throws BlojsomFetcherException
Fetch a set of BlogCategory objects

Specified by:
fetchCategories in interface BlojsomFetcher
Parameters:
httpServletRequest - Request
httpServletResponse - Response
user - BlogUser instance
flavor - Flavor
context - Context
Returns:
Blog categories retrieved for the particular request
Throws:
BlojsomFetcherException - If there is an error retrieving the blog categories for the request

fetchCategories

public BlogCategory[] fetchCategories(java.util.Map fetchParameters,
                                      BlogUser user)
                               throws BlojsomFetcherException
Fetch a set of BlogCategory objects. This method is intended to be used for other components such as the XML-RPC handlers that cannot generate servlet request and response objects, but still need to be able to fetch categories. Implementations of this method must be explicit about the exact parameter names and types that are expected to return an appropriate set of BlogCategory objects. The following table describes the parameters accepted by this method and their return value. The value for fetchParameters may represent the keys and data types that should be present in the fetchParameters map to return the proper data.

fetchParameters value Return value
null return all categories
"FETCHER_CATEGORY" (BlogCategory) Up the hierarchy, only the parent categories are returned. Down the hierarchy from the current category, all children are returned while obeying the blog-directory-depth parameter.

Specified by:
fetchCategories in interface BlojsomFetcher
Parameters:
fetchParameters - Parameters which will be used to retrieve blog entries
user - BlogUser instance
Returns:
Blog categories retrieved for the particular request
Throws:
BlojsomFetcherException - If there is an error retrieving the blog categories for the request

destroy

public void destroy()
             throws BlojsomFetcherException
Called when BlojsomServlet is taken out of service

Specified by:
destroy in interface BlojsomFetcher
Throws:
BlojsomFetcherException - If there is an error in finalizing this fetcher