public class NewsfeedContentProvider extends PageFlowScopeAdapter implements Serializable, IUpdateableContentProvider, IRefreshableContentProvider
This provider's feed
property represents the feed content
as a rome SyndFeed
.
If this provider's normalize
property is set to true,
the SyndFeed
will be "normalized" by sanitizing all URI properties
(such as the feed's link and the individual entry links)
and all SyndContent
properties (such as the feed's title and the entries' contents).
Modifier and Type | Field and Description |
---|---|
protected boolean |
m_autoRefresh |
protected IErrorHandler |
m_errorHandler |
protected com.sun.syndication.feed.synd.SyndFeed |
m_feed |
protected boolean |
m_needRefresh |
protected boolean |
m_normalize |
protected String |
m_url |
protected static Object[] |
PROPERTY_KEYS_ARRAY |
protected static Set<Object> |
PROPERTY_KEYS_SET |
protected static Pattern |
RE_CONTAINS_HTML |
protected static Pattern |
RE_HTML_CONTENT_TYPE |
protected static Pattern |
RE_IMAGE_CONTENT_TYPE |
protected static Pattern |
RE_SAFE_URI_SCHEME |
fExpireWithPageFlow
Constructor and Description |
---|
NewsfeedContentProvider()
Creates a new, uninitialized newsfeed content-provider.
|
NewsfeedContentProvider(String url)
Creates a new newsfeed content-provider
initialized with a feed URL.
|
NewsfeedContentProvider(String url,
boolean normalize)
Creates a new newsfeed content-provider
initialized with a feed URL and a normalize flag.
|
Modifier and Type | Method and Description |
---|---|
IErrorHandler |
getErrorHandler()
Handler for errors retrieving feed content.
|
com.sun.syndication.feed.synd.SyndFeed |
getFeed()
Feed content.
|
boolean |
getNeedRefresh()
Returns
true when IRefreshable.isAutoRefresh() is on and the result properties need to be refreshed from
the data source by executing IRefreshable.refresh() method. |
Object[] |
getPropertyKeys()
Returns list of properties supported by this content provider.
|
Class<?> |
getType(Object propertyKey)
Returns java type of the given property
|
String |
getUrl()
Feed url.
|
Object |
getValue(Object propertyKey)
Returns value of the given property
|
boolean |
hasProperty(Object propertyKey)
Checks if the given property is supported by this content provider
|
boolean |
isAutoRefresh()
Returns
true if the provider is currenlty in auto-refresh mode |
protected boolean |
isHTML(String s)
True if the specified string contains html.
|
boolean |
isNormalize()
True to "normalize" feed content.
|
boolean |
isReadOnly(Object propertyKey)
Returns true if the given property is readonly.
|
protected void |
normalize() |
protected com.sun.syndication.feed.synd.SyndContent |
normalizeContent(com.sun.syndication.feed.synd.SyndContent content)
Converts content to script-safe html.
|
protected com.sun.syndication.feed.synd.SyndLink |
normalizeLink(com.sun.syndication.feed.synd.SyndLink link)
Sanitizes link urls and ensures every link has a title.
|
protected String |
normalizeString(String s)
Converts specified string to script-safe html.
|
protected String |
normalizeUrl(String url)
Sanitizes url and trims leading/trailing whitespace.
|
protected String |
processHTML(String s)
Strips unsafe html elements and attributes.
|
protected String |
processPlainText(String s)
Adds html formatting to plain text.
|
void |
refresh()
(Re)loads data from the data source.
|
void |
setAutoRefresh(boolean autoRefresh)
Sets auto refresh mode on.
|
void |
setErrorHandler(IErrorHandler errorHandler)
Handler for errors retrieving feed content.
|
void |
setNeedRefresh(boolean needRefresh)
Tells the provider that the input parameters have changed and the output results need to be refreshed the next time any
output property is requested via
IContentProvider.getValue(Object) . |
void |
setNormalize(boolean normalize)
True to "normalize" feed content.
|
void |
setUrl(String url)
Feed url.
|
void |
setValue(Object propertyKey,
Object value)
Sets new value of the given property
|
boolean |
supportsAutoRefresh()
Returns true if this content provider supports auto refresh feature.
|
getExpireWithPageFlow, setExpireWithPageFlow
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
toString
protected static final Pattern RE_CONTAINS_HTML
protected static final Pattern RE_HTML_CONTENT_TYPE
protected static final Pattern RE_IMAGE_CONTENT_TYPE
protected static final Pattern RE_SAFE_URI_SCHEME
protected static final Object[] PROPERTY_KEYS_ARRAY
protected boolean m_autoRefresh
protected boolean m_needRefresh
protected IErrorHandler m_errorHandler
protected boolean m_normalize
protected String m_url
protected transient com.sun.syndication.feed.synd.SyndFeed m_feed
public NewsfeedContentProvider()
public NewsfeedContentProvider(String url)
public NewsfeedContentProvider(String url, boolean normalize)
public Object[] getPropertyKeys()
IContentProvider
Object[0]
,
never null.getPropertyKeys
in interface IContentProvider
String
or Integer
public Class<?> getType(Object propertyKey) throws PropertyNotFoundException
IContentProvider
getType
in interface IContentProvider
propertyKey
- the property key of type String
or Integer
Class
PropertyNotFoundException
- if property is not supportedpublic Object getValue(Object propertyKey) throws ELException, PropertyNotFoundException
IContentProvider
getValue
in interface IContentProvider
propertyKey
- the property key of type String
or Integer
null
PropertyNotFoundException
- if property is not supportedELException
public boolean hasProperty(Object propertyKey)
IContentProvider
hasProperty
in interface IContentProvider
propertyKey
- property key of type String
or Integer
true
if property is supportedpublic boolean isReadOnly(Object propertyKey) throws ELException, PropertyNotFoundException
IUpdateableContentProvider
Returns true if the given property is readonly. If it is readonly, IUpdateableContentProvider.setValue(Object, Object)
will
definitely fail.
isReadOnly
in interface IUpdateableContentProvider
propertyKey
- property key of type String
or Integer
PropertyNotFoundException
ELException
public void setValue(Object propertyKey, Object value) throws ELException, PropertyNotFoundException
IUpdateableContentProvider
Sets new value of the given property
setValue
in interface IUpdateableContentProvider
propertyKey
- property key of type String
or Integer
value
- new property valuePropertyNotFoundException
- if property is not foundELException
public boolean getNeedRefresh()
IRefreshable
Returns true
when IRefreshable.isAutoRefresh()
is on and the result properties need to be refreshed from
the data source by executing IRefreshable.refresh()
method.
Implementations may return an accurate value from this method if they can track the changes to the input parameter
properties or they may require the clients to call IRefreshable.setNeedRefresh(boolean)
explicitely.
getNeedRefresh
in interface IRefreshable
true
when the output properties are not up-to-date with the current input parameters, i.e. IRefreshable.refresh()
needs to be executed manually or automatically.public boolean isAutoRefresh()
IRefreshable
true
if the provider is currenlty in auto-refresh modeisAutoRefresh
in interface IRefreshable
public void refresh() throws ContentProviderException
IRefreshable
refresh
in interface IRefreshable
ContentProviderException
- if error loading data from the data sourcepublic void setAutoRefresh(boolean autoRefresh) throws ContentProviderException
IRefreshable
Sets auto refresh mode on. When auto refresh mode is on, the provider calls IRefreshable.getNeedRefresh()
to determine whether the refresh needs to be done before returning any result properties. If it returns
true
, the provider calls IRefreshable.refresh()
method to updated the result properties.
setAutoRefresh
in interface IRefreshable
autoRefresh
- true to turn it onContentProviderException
- if auto refresh mode is not supportedIRefreshable.supportsAutoRefresh()
,
IRefreshable.getNeedRefresh()
,
IRefreshable.setNeedRefresh(boolean)
public void setNeedRefresh(boolean needRefresh)
IRefreshable
IContentProvider.getValue(Object)
.setNeedRefresh
in interface IRefreshable
needRefresh
- true
if the input parameters have changedpublic boolean supportsAutoRefresh()
IRefreshable
supportsAutoRefresh
in interface IRefreshable
IRefreshable.setAutoRefresh(boolean)
protected void normalize()
protected com.sun.syndication.feed.synd.SyndLink normalizeLink(com.sun.syndication.feed.synd.SyndLink link)
protected String normalizeUrl(String url)
protected com.sun.syndication.feed.synd.SyndContent normalizeContent(com.sun.syndication.feed.synd.SyndContent content)
protected String normalizeString(String s)
protected boolean isHTML(String s)
protected String processPlainText(String s)
public IErrorHandler getErrorHandler()
public void setErrorHandler(IErrorHandler errorHandler)
public boolean isNormalize()
Normalization means sanitizing all URI properties
(such as the feed's link and the individual entry links)
and all SyndContent
properties (such as the feed's title and the entries' contents).
public void setNormalize(boolean normalize)
Normalization means sanitizing all URI properties
(such as the feed's link and the individual entry links)
and all SyndContent
properties (such as the feed's title and the entries' contents).
public String getUrl()
public void setUrl(String url)
public com.sun.syndication.feed.synd.SyndFeed getFeed()