org.apache.abdera.protocol.server.adapters.jcr
Class JcrCollectionAdapter

java.lang.Object
  extended by org.apache.abdera.protocol.server.impl.AbstractCollectionAdapter
      extended by org.apache.abdera.protocol.server.impl.AbstractEntityCollectionAdapter<javax.jcr.Node>
          extended by org.apache.abdera.protocol.server.adapters.jcr.JcrCollectionAdapter
All Implemented Interfaces:
CollectionAdapter, CollectionInfo, MediaCollectionAdapter, Transactional

public class JcrCollectionAdapter
extends org.apache.abdera.protocol.server.impl.AbstractEntityCollectionAdapter<javax.jcr.Node>

Adapter implementation that uses a JCR Repository to store Atompub collection entries. The adapter is intended to be used with the DefaultProvider implementation.


Constructor Summary
JcrCollectionAdapter()
           
 
Method Summary
 void deleteEntry(String resourceName, RequestContext request)
          Delete an entry
static void dump(javax.jcr.Node node)
          Recursively outputs the contents of the given node.
 void end(RequestContext request, ResponseContext response)
          Called by the provider after dispatching the request to the adapter
 String getAuthor(RequestContext request)
           
 List<Person> getAuthors(javax.jcr.Node entry, RequestContext request)
          Get the authors for an entry.
 ResponseContext getCategories(RequestContext request)
          Get an Atompub Categories document
 Object getContent(javax.jcr.Node entry, RequestContext request)
          Get the content for the entry.
 String getContentType(javax.jcr.Node entry)
          Get the content-type for the entry.
static Calendar getDateOrNull(javax.jcr.Node node, String propName)
           
 Iterable<javax.jcr.Node> getEntries(RequestContext request)
          Get the listing of entries requested
 javax.jcr.Node getEntry(String resourceName, RequestContext request)
          Get a specific entry
 String getId(javax.jcr.Node entry)
          Gets the UUID for the specified entry.
 String getId(RequestContext request)
           
 String getMediaName(javax.jcr.Node entry)
          Get the name of the media resource.
 InputStream getMediaStream(javax.jcr.Node entry)
          Get an input stream for the media resource.
 String getName(javax.jcr.Node entry)
          Get the name of the entry resource (used to construct links)
protected  javax.jcr.Session getSession(RequestContext request)
           
static String getStringOrNull(javax.jcr.Node node, String propName)
           
 Text getSummary(javax.jcr.Node entry, RequestContext request)
          Get the summary of the entry.
 String getTitle(javax.jcr.Node entry)
          Get the title fo the entry
 String getTitle(RequestContext request)
          Get the value of the app:collection element's atom:title element.
 Date getUpdated(javax.jcr.Node entry)
          Get the value to use in the atom:updated element
static javax.jcr.Value getValueOrNull(javax.jcr.Node node, String propName)
           
 void initialize()
          Logs into the repository and posts a node for the collection if one does not exist.
 boolean isMediaEntry(javax.jcr.Node entry)
          True if this entry is a media-link entry.
protected  javax.jcr.Node mapEntryToNode(javax.jcr.Node entry, String title, String summary, Date updated, List<Person> authors, Content content, javax.jcr.Session session)
           
 javax.jcr.Node postEntry(String title, IRI id, String summary, Date updated, List<Person> authors, Content content, RequestContext request)
          Create a new entry
protected  javax.jcr.Node postEntry(String title, String summary, Date updated, List<Person> authors, Content content, javax.jcr.Session session, javax.jcr.Node collectionNode, String resourceName, int num)
           
 javax.jcr.Node postMedia(javax.activation.MimeType mimeType, String slug, InputStream inputStream, RequestContext request)
          Post a new media resource to the collection.
protected  String postSummaryForEntry(javax.jcr.Node n)
          post a summary for an entry.
 void putEntry(javax.jcr.Node entry, String title, Date updated, List<Person> authors, String summary, Content content, RequestContext request)
          Update an entry.
 void setAuthor(String author)
           
 void setCollectionNodePath(String collectionNodePath)
           
 void setCredentials(javax.jcr.Credentials credentials)
           
 void setMaxActiveSessions(int maxActiveSessions)
           
 void setRepository(javax.jcr.Repository repository)
           
 void setTitle(String title)
           
 void start(RequestContext request)
          Called by the provider before dispatching the request to the adapter
 
Methods inherited from class org.apache.abdera.protocol.server.impl.AbstractEntityCollectionAdapter
addContent, addEntryDetails, addFeedDetails, addMediaContent, buildGetMediaResponse, createMediaEntry, createNonMediaEntry, deleteEntry, deleteMedia, deleteMedia, getEntry, getEntryFromCollectionProvider, getFeed, getFeedIriForEntry, getLink, getLink, getLink, getLink, getMedia, getQueryParameters, headEntry, headMedia, postEntry, postMedia, putEntry, putMedia, putMedia
 
Methods inherited from class org.apache.abdera.protocol.server.impl.AbstractCollectionAdapter
asCollectionElement, buildCreateEntryResponse, buildGetEntryResponse, buildGetFeedResponse, buildHeadEntryResponse, buildPostMediaEntryResponse, compensate, createErrorResponse, createFeedBase, extensionRequest, getAccepts, getCategoriesInfo, getEntryFromRequest, getHref, getHref, getResourceName, optionsEntry, optionsMedia, setHref
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JcrCollectionAdapter

public JcrCollectionAdapter()
Method Detail

setCollectionNodePath

public void setCollectionNodePath(String collectionNodePath)

setTitle

public void setTitle(String title)

setAuthor

public void setAuthor(String author)

initialize

public void initialize()
                throws Exception
Logs into the repository and posts a node for the collection if one does not exist. Also, this will set up the session pool.

Throws:
javax.jcr.RepositoryException
Exception

start

public void start(RequestContext request)
           throws ResponseContextException
Description copied from interface: Transactional
Called by the provider before dispatching the request to the adapter

Specified by:
start in interface Transactional
Overrides:
start in class org.apache.abdera.protocol.server.impl.AbstractCollectionAdapter
Throws:
ResponseContextException

end

public void end(RequestContext request,
                ResponseContext response)
Description copied from interface: Transactional
Called by the provider after dispatching the request to the adapter

Specified by:
end in interface Transactional
Overrides:
end in class org.apache.abdera.protocol.server.impl.AbstractCollectionAdapter

getContentType

public String getContentType(javax.jcr.Node entry)
Description copied from class: org.apache.abdera.protocol.server.impl.AbstractEntityCollectionAdapter
Get the content-type for the entry. By default this operation is not supported.

Overrides:
getContentType in class org.apache.abdera.protocol.server.impl.AbstractEntityCollectionAdapter<javax.jcr.Node>

isMediaEntry

public boolean isMediaEntry(javax.jcr.Node entry)
                     throws ResponseContextException
Description copied from class: org.apache.abdera.protocol.server.impl.AbstractEntityCollectionAdapter
True if this entry is a media-link entry. By default this always returns false. Implementations must override to support media link entries

Overrides:
isMediaEntry in class org.apache.abdera.protocol.server.impl.AbstractEntityCollectionAdapter<javax.jcr.Node>
Throws:
ResponseContextException

postMedia

public javax.jcr.Node postMedia(javax.activation.MimeType mimeType,
                                String slug,
                                InputStream inputStream,
                                RequestContext request)
                         throws ResponseContextException
Description copied from class: org.apache.abdera.protocol.server.impl.AbstractEntityCollectionAdapter
Post a new media resource to the collection. By default, this method is not supported. Implementations must override this method to support posting media resources

Overrides:
postMedia in class org.apache.abdera.protocol.server.impl.AbstractEntityCollectionAdapter<javax.jcr.Node>
Parameters:
mimeType - The mime-type of the resource
slug - The value of the Slug header
inputStream - An InputStream providing access to the request payload
request - The request context
Throws:
ResponseContextException

postSummaryForEntry

protected String postSummaryForEntry(javax.jcr.Node n)
post a summary for an entry. Used when a media entry is postd so you have the chance to post a meaningful summary for consumers of the feed.

Parameters:
n -
Returns:

postEntry

public javax.jcr.Node postEntry(String title,
                                IRI id,
                                String summary,
                                Date updated,
                                List<Person> authors,
                                Content content,
                                RequestContext request)
                         throws ResponseContextException
Description copied from class: org.apache.abdera.protocol.server.impl.AbstractEntityCollectionAdapter
Create a new entry

Specified by:
postEntry in class org.apache.abdera.protocol.server.impl.AbstractEntityCollectionAdapter<javax.jcr.Node>
Parameters:
title - The title of the entry (assumes that type="text")
id - The value of the atom:id element
summary - The summary of the entry
updated - The value of the atom:updated element
authors - Listing of atom:author elements
request - The request context
Throws:
ResponseContextException

postEntry

protected javax.jcr.Node postEntry(String title,
                                   String summary,
                                   Date updated,
                                   List<Person> authors,
                                   Content content,
                                   javax.jcr.Session session,
                                   javax.jcr.Node collectionNode,
                                   String resourceName,
                                   int num)
                            throws ResponseContextException,
                                   javax.jcr.RepositoryException
Throws:
ResponseContextException
javax.jcr.RepositoryException

mapEntryToNode

protected javax.jcr.Node mapEntryToNode(javax.jcr.Node entry,
                                        String title,
                                        String summary,
                                        Date updated,
                                        List<Person> authors,
                                        Content content,
                                        javax.jcr.Session session)
                                 throws ResponseContextException,
                                        javax.jcr.RepositoryException
Throws:
ResponseContextException
javax.jcr.RepositoryException

getSession

protected javax.jcr.Session getSession(RequestContext request)

deleteEntry

public void deleteEntry(String resourceName,
                        RequestContext request)
                 throws ResponseContextException
Description copied from class: org.apache.abdera.protocol.server.impl.AbstractEntityCollectionAdapter
Delete an entry

Specified by:
deleteEntry in class org.apache.abdera.protocol.server.impl.AbstractEntityCollectionAdapter<javax.jcr.Node>
Parameters:
resourceName - The entry to delete
request - The request context
Throws:
ResponseContextException

dump

public static void dump(javax.jcr.Node node)
                 throws javax.jcr.RepositoryException
Recursively outputs the contents of the given node.

Throws:
javax.jcr.RepositoryException

getAuthor

public String getAuthor(RequestContext request)
                 throws ResponseContextException
Specified by:
getAuthor in class org.apache.abdera.protocol.server.impl.AbstractCollectionAdapter
Throws:
ResponseContextException

getAuthors

public List<Person> getAuthors(javax.jcr.Node entry,
                               RequestContext request)
                        throws ResponseContextException
Description copied from class: org.apache.abdera.protocol.server.impl.AbstractEntityCollectionAdapter
Get the authors for an entry. By default this returns null. Implementations must override in order to providing a listing of authors for an entry

Overrides:
getAuthors in class org.apache.abdera.protocol.server.impl.AbstractEntityCollectionAdapter<javax.jcr.Node>
Throws:
ResponseContextException

getContent

public Object getContent(javax.jcr.Node entry,
                         RequestContext request)
                  throws ResponseContextException
Description copied from class: org.apache.abdera.protocol.server.impl.AbstractEntityCollectionAdapter
Get the content for the entry.

Specified by:
getContent in class org.apache.abdera.protocol.server.impl.AbstractEntityCollectionAdapter<javax.jcr.Node>
Throws:
ResponseContextException

getEntries

public Iterable<javax.jcr.Node> getEntries(RequestContext request)
                                    throws ResponseContextException
Description copied from class: org.apache.abdera.protocol.server.impl.AbstractEntityCollectionAdapter
Get the listing of entries requested

Specified by:
getEntries in class org.apache.abdera.protocol.server.impl.AbstractEntityCollectionAdapter<javax.jcr.Node>
Throws:
ResponseContextException

getEntry

public javax.jcr.Node getEntry(String resourceName,
                               RequestContext request)
                        throws ResponseContextException
Description copied from class: org.apache.abdera.protocol.server.impl.AbstractEntityCollectionAdapter
Get a specific entry

Specified by:
getEntry in class org.apache.abdera.protocol.server.impl.AbstractEntityCollectionAdapter<javax.jcr.Node>
Parameters:
resourceName - The entry to get
request - The request context
Throws:
ResponseContextException

getId

public String getId(RequestContext request)
Specified by:
getId in class org.apache.abdera.protocol.server.impl.AbstractCollectionAdapter

getId

public String getId(javax.jcr.Node entry)
             throws ResponseContextException
Description copied from class: org.apache.abdera.protocol.server.impl.AbstractEntityCollectionAdapter
Gets the UUID for the specified entry.

Specified by:
getId in class org.apache.abdera.protocol.server.impl.AbstractEntityCollectionAdapter<javax.jcr.Node>
Returns:
Throws:
ResponseContextException

getMediaName

public String getMediaName(javax.jcr.Node entry)
                    throws ResponseContextException
Description copied from class: org.apache.abdera.protocol.server.impl.AbstractEntityCollectionAdapter
Get the name of the media resource. By default this method is unsupported. Implementations must override.

Overrides:
getMediaName in class org.apache.abdera.protocol.server.impl.AbstractEntityCollectionAdapter<javax.jcr.Node>
Throws:
ResponseContextException

getMediaStream

public InputStream getMediaStream(javax.jcr.Node entry)
                           throws ResponseContextException
Description copied from class: org.apache.abdera.protocol.server.impl.AbstractEntityCollectionAdapter
Get an input stream for the media resource. By default this method is unsupported. Implementations must override.

Overrides:
getMediaStream in class org.apache.abdera.protocol.server.impl.AbstractEntityCollectionAdapter<javax.jcr.Node>
Throws:
ResponseContextException

getName

public String getName(javax.jcr.Node entry)
               throws ResponseContextException
Description copied from class: org.apache.abdera.protocol.server.impl.AbstractEntityCollectionAdapter
Get the name of the entry resource (used to construct links)

Specified by:
getName in class org.apache.abdera.protocol.server.impl.AbstractEntityCollectionAdapter<javax.jcr.Node>
Throws:
ResponseContextException

getSummary

public Text getSummary(javax.jcr.Node entry,
                       RequestContext request)
                throws ResponseContextException
Description copied from class: org.apache.abdera.protocol.server.impl.AbstractEntityCollectionAdapter
Get the summary of the entry. By default this returns null.

Overrides:
getSummary in class org.apache.abdera.protocol.server.impl.AbstractEntityCollectionAdapter<javax.jcr.Node>
Throws:
ResponseContextException

getTitle

public String getTitle(RequestContext request)
Description copied from interface: CollectionInfo
Get the value of the app:collection element's atom:title element. This assumes that the title will be type="text". This must not be null;


getTitle

public String getTitle(javax.jcr.Node entry)
                throws ResponseContextException
Description copied from class: org.apache.abdera.protocol.server.impl.AbstractEntityCollectionAdapter
Get the title fo the entry

Specified by:
getTitle in class org.apache.abdera.protocol.server.impl.AbstractEntityCollectionAdapter<javax.jcr.Node>
Throws:
ResponseContextException

getUpdated

public Date getUpdated(javax.jcr.Node entry)
                throws ResponseContextException
Description copied from class: org.apache.abdera.protocol.server.impl.AbstractEntityCollectionAdapter
Get the value to use in the atom:updated element

Specified by:
getUpdated in class org.apache.abdera.protocol.server.impl.AbstractEntityCollectionAdapter<javax.jcr.Node>
Throws:
ResponseContextException

putEntry

public void putEntry(javax.jcr.Node entry,
                     String title,
                     Date updated,
                     List<Person> authors,
                     String summary,
                     Content content,
                     RequestContext request)
              throws ResponseContextException
Description copied from class: org.apache.abdera.protocol.server.impl.AbstractEntityCollectionAdapter
Update an entry.

Specified by:
putEntry in class org.apache.abdera.protocol.server.impl.AbstractEntityCollectionAdapter<javax.jcr.Node>
Parameters:
entry - The entry to update
title - The new title of the entry
updated - The new value of atom:updated
authors - To new listing of authors
summary - The new summary
content - The new content
request - The request context
Throws:
ResponseContextException

getStringOrNull

public static String getStringOrNull(javax.jcr.Node node,
                                     String propName)
                              throws ResponseContextException
Throws:
ResponseContextException

getCategories

public ResponseContext getCategories(RequestContext request)
Description copied from interface: CollectionAdapter
Get an Atompub Categories document

Specified by:
getCategories in interface CollectionAdapter
Overrides:
getCategories in class org.apache.abdera.protocol.server.impl.AbstractCollectionAdapter

getDateOrNull

public static Calendar getDateOrNull(javax.jcr.Node node,
                                     String propName)
                              throws ResponseContextException
Throws:
ResponseContextException

getValueOrNull

public static javax.jcr.Value getValueOrNull(javax.jcr.Node node,
                                             String propName)
                                      throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

setRepository

public void setRepository(javax.jcr.Repository repository)

setCredentials

public void setCredentials(javax.jcr.Credentials credentials)

setMaxActiveSessions

public void setMaxActiveSessions(int maxActiveSessions)


Copyright © 2006-2010 Apache Software Foundation. All Rights Reserved.