org.apache.commons.feedparser.locate.blogservice
Class BlogService

java.lang.Object
  extended by org.apache.commons.feedparser.locate.blogservice.BlogService
Direct Known Subclasses:
AOLJournal, Blogger, Blosxom, DiaryLand, ExpressionEngine, Flickr, GreyMatter, iBlog, LiveJournal, Manila, MovableType, PMachine, RadioUserland, TextAmerica, TextPattern, Typepad, Unknown, WordPress, Xanga, YahooGroups

public abstract class BlogService
extends Object

Models the different kinds of blog services that are available. This is needed for two reasons. First, sometimes it is useful to simply know what provider a given weblog is being hosted by, such as Blogger or PMachine, in order to use special, non-standard capabilities. Second, many services have "quirks" that don't follow the standards, such as supporting autodiscovery or supporting it in an incorrect way, and we therefore need to know what service we are dealing with so that we can find its feed. The BlogService object encapsulates how to determine if a given weblog is of that type and how to find its feeds. Concrete subclasses, such as org.apache.commons.feedparser.locate.blogservice.Blogger, fill in this class and provide the actual way to determine these things for each blog service type.

Author:
Brad Neuberg, bkn3@columbia.edu

Field Summary
protected static List blogServices
           
protected static Pattern metaTagsPattern
          Locates all the generator meta tags (i.e.
protected static Pattern patternToStrip
          A regex to find any trailing filename and strip it
 
Constructor Summary
BlogService()
           
 
Method Summary
protected  boolean containsDomain(String resource, String domain)
          Determines if the given resource contains the given domain name fragment.
 boolean equals(Object obj)
           
abstract  boolean followRedirects()
          Returns whether we should follow HTTP redirects for this blog service.
 String getBaseFeedPath(String resource)
          This method takes a resource, such as "http://www.codinginparadise.org/myweblog.php", and gets the path necessary to build up a feed, such as "http://www.codinginparadise.org/".
static BlogService[] getBlogServices()
          Gets an array of all of the available BlogService implementations.
abstract  FeedReference[] getFeedLocations(String resource, String content)
          Returns an array of FeedReferences that contains information on the usual locations this blog service contains its feed.
protected  boolean hasGenerator(String content, String generatorType)
          Determines if the given content was generated by the given generator.
 int hashCode()
           
abstract  boolean hasValidAutoDiscovery()
          Returns whether we can trust the results of this blog service's autodiscovery links.
protected static void initializeBlogServices()
           
 boolean isThisService(String resource)
          Determines if the weblog at the given resource is this blog service.
abstract  boolean isThisService(String resource, String content)
          Determines if the weblog at the given resource and with the given content is this blog service.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

blogServices

protected static List blogServices

metaTagsPattern

protected static Pattern metaTagsPattern
Locates all the generator meta tags (i.e. )


patternToStrip

protected static Pattern patternToStrip
A regex to find any trailing filename and strip it

Constructor Detail

BlogService

public BlogService()
Method Detail

hasValidAutoDiscovery

public abstract boolean hasValidAutoDiscovery()
Returns whether we can trust the results of this blog service's autodiscovery links. For example, TextAmerica returns invalid autodiscovery results.


followRedirects

public abstract boolean followRedirects()
Returns whether we should follow HTTP redirects for this blog service. Some services don't implement HTTP redirects correctly, while others, like Xanga, require it.


isThisService

public abstract boolean isThisService(String resource,
                                      String content)
                               throws FeedParserException
Determines if the weblog at the given resource and with the given content is this blog service.

Parameters:
resource - A full URI to this resource, such as "http://www.codinginparadise.org".
content - The full HTML content at the resource's URL.
Throws:
FeedParserException - Thrown if an error occurs while determining the type of this weblog.

getFeedLocations

public abstract FeedReference[] getFeedLocations(String resource,
                                                 String content)
                                          throws FeedParserException
Returns an array of FeedReferences that contains information on the usual locations this blog service contains its feed. The feeds should be ordered by quality, so that higher quality feeds come before lower quality ones (i.e. you would want to have an Atom FeedReference object come before an RSS 0.91 FeedReference object in this list).

Parameters:
resource - A URL to the given weblog that might be used to build up where feeds are usually located.
content - The full content of the resource URL, which might be useful to determine where feeds are usually located. This can be null.
Throws:
FeedParserException - Thrown if an error occurs while trying to determine the usual locations of feeds for this service.

isThisService

public boolean isThisService(String resource)
                      throws FeedParserException
Determines if the weblog at the given resource is this blog service.

Parameters:
resource - A full URI to this resource, such as "http://www.codinginparadise.org".
Throws:
FeedParserException - Thrown if an error occurs while determining the type of this weblog.

getBaseFeedPath

public String getBaseFeedPath(String resource)
This method takes a resource, such as "http://www.codinginparadise.org/myweblog.php", and gets the path necessary to build up a feed, such as "http://www.codinginparadise.org/". Basicly it appends a slash to the end if there is not one, and removes any file names that might be at the end, such as "myweblog.php". There is a special exception for some Blosxom blogs, which have things inside of a cgi-script and 'hang' their RSS files off of this cgi-bin. For example, http://www.bitbucketheaven.com/cgi-bin/blosxom.cgi has its RSS file at http://www.bitbucketheaven.com/cgi-bin/blosxom.cgi/index.rss, so we must return the blosxom.cgi at the end as well for this method.

Throws:
MalformedURLException - Thrown if the given resource's URL is incorrectly formatted.

toString

public String toString()
Overrides:
toString in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

getBlogServices

public static BlogService[] getBlogServices()
Gets an array of all of the available BlogService implementations.


containsDomain

protected boolean containsDomain(String resource,
                                 String domain)
Determines if the given resource contains the given domain name fragment.


hasGenerator

protected boolean hasGenerator(String content,
                               String generatorType)
Determines if the given content was generated by the given generator. Example. This document contains a meta tag with name="generator" and content equal to the generatorType).


initializeBlogServices

protected static void initializeBlogServices()


Copyright © 2001-2010 The Apache Software Foundation. All Rights Reserved.