Package com.adobe.granite.comments
Class AbstractCommentingProvider
- java.lang.Object
-
- com.adobe.granite.comments.AbstractCommentingProvider
-
- All Implemented Interfaces:
CommentingProvider
@ConsumerType public abstract class AbstractCommentingProvider extends java.lang.Object implements CommentingProvider
TheAbstractCommentingProviderprovides a default implementation for storingComments andCommentCollections.CommentingProviders are recommended to extend this abstract implementation and override where necessary.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringJCR_CREATED_BYstatic java.lang.StringPN_ANNOTATIONDATAThe name of the property holding optional annotation datastatic java.lang.StringPN_AUTHORThe property containing the optional creator of a commentstatic java.lang.StringPN_MESSAGEThe name of the property holding a comment's message ("comment").static java.lang.StringRELATIVE_TARGET_ROOTThe name of the node holding comment collections below a target.static java.lang.StringSLING_RESOURCE_TYPE-
Fields inherited from interface com.adobe.granite.comments.CommentingProvider
PROPERTY_COLLECTION_TYPES, PROPERTY_COMMENT_TYPES
-
-
Constructor Summary
Constructors Constructor Description AbstractCommentingProvider()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description ResourcecreateAttachmentResource(Resource commentResource, java.lang.String name, java.io.InputStream inputStream, java.lang.String mimeType)Add an attachment to the givenComment.ResourcecreateCollectionResource(Resource target)Create the root of aCommentCollectionfor the given targetResource.ResourcecreateCommentResource(Resource collectionResource, java.lang.String message, java.lang.String author, java.lang.String annotationData)Add aCommentresource to the givenCommentCollectionresource, set the givenmessageon the comment.java.util.Map<java.lang.String,Resource>getAttachmentMap(Resource commentResource)Return aMapcontaining the givenComments attachments.ResourcegetAttachmentResource(Resource commentResource, java.lang.String name)Return the attachment of the givenCommentas identified by its givenname(file name).abstract java.lang.StringgetCollectionResourceType()Returns an optional resource type to set for newly created collections.java.util.Iterator<Resource>getCommentResources(Resource collectionResource)Returns anIteratorofResources, with each resource representing aCommentof the givenCommentCollection.abstract java.lang.StringgetCommentResourceType()Returns an optional resource type to set for newly created comments.voidremoveAttachmentResource(Resource commentResource, java.lang.String name)Remove (delete) the attachment identified by the givennamefrom the givenComment.voidremoveCollectionResource(Resource resource)Remove (delete) the givenCommentCollectionfrom the repository.voidremoveCommentResource(Resource resource)Remove (delete) the givenCommentfrom the repository.-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.adobe.granite.comments.CommentingProvider
createCollection, getCollection
-
-
-
-
Field Detail
-
RELATIVE_TARGET_ROOT
public static final java.lang.String RELATIVE_TARGET_ROOT
The name of the node holding comment collections below a target.- See Also:
- Constant Field Values
-
PN_ANNOTATIONDATA
public static final java.lang.String PN_ANNOTATIONDATA
The name of the property holding optional annotation data- See Also:
- Constant Field Values
-
PN_AUTHOR
public static final java.lang.String PN_AUTHOR
The property containing the optional creator of a comment- See Also:
- Constant Field Values
-
PN_MESSAGE
public static final java.lang.String PN_MESSAGE
The name of the property holding a comment's message ("comment").- See Also:
- Constant Field Values
-
JCR_CREATED_BY
public static final java.lang.String JCR_CREATED_BY
- See Also:
- Constant Field Values
-
SLING_RESOURCE_TYPE
public static final java.lang.String SLING_RESOURCE_TYPE
- See Also:
- Constant Field Values
-
-
Method Detail
-
createCollectionResource
public final Resource createCollectionResource(Resource target)
Create the root of aCommentCollectionfor the given targetResource. Node creation may be overridden viacreateCollectionNode(String, javax.jcr.Session). If not already present on the node, this method also will set theJCR_CREATED_BYandJcrConstants.JCR_CREATEDproperties. The last modified mixin will maintain the last modified date. Custom properties may be set on the collection node viacustomizeCollectionNode(Resource, javax.jcr.Node).- Parameters:
target- The target resource for which to create a collection root.- Returns:
- The newly created resource representing the collection root.
- Throws:
CommentException- If a collection already exists for the given target, or upon encountering an error writing to the repository.
-
createCommentResource
public final Resource createCommentResource(Resource collectionResource, java.lang.String message, java.lang.String author, java.lang.String annotationData)
Add aCommentresource to the givenCommentCollectionresource, set the givenmessageon the comment. Comment node creation may be overridden viacreateCommentNode(String, javax.jcr.Node, javax.jcr.Session). This method will forcibly set aSLING_RESOURCE_TYPEproperty (if defined bygetCommentResourceType()()}), thePN_MESSAGEproperty. If not already present on the node, this method also will set theJCR_CREATED_BYandJcrConstants.JCR_CREATEDproperties. Custom properties may be set on the comment resource viacustomizeCommentNode(Resource, javax.jcr.Node)(javax.jcr.Node)}.- Parameters:
collectionResource- The collection within which to create the comment.message- The message to store in the comment.author- The author to store in the comment.annotationData- The annotation data to store in the comment.- Returns:
- The newly created comment
Resource. - Throws:
CommentException- Upon encountering an error writing to the repository.
-
getCommentResources
public java.util.Iterator<Resource> getCommentResources(Resource collectionResource)
Returns anIteratorofResources, with each resource representing aCommentof the givenCommentCollection.- Parameters:
collectionResource- TheCommentCollectionfor which to retrieve the comment resources.- Returns:
- The iterator containing the comment resources, or an empty iterator if no comments are present.
- Throws:
CommentException- Upon encountering an error retrieving the comments.
-
removeCommentResource
public void removeCommentResource(Resource resource)
Remove (delete) the givenCommentfrom the repository.- Parameters:
resource- The comment resource to delete.- Throws:
CommentException- Upon encountering an error writing to the repository.
-
removeCollectionResource
public void removeCollectionResource(Resource resource)
Remove (delete) the givenCommentCollectionfrom the repository.- Parameters:
resource- The collection to delete.- Throws:
CommentException- Upon encountering an error writing to the repository.
-
createAttachmentResource
public final Resource createAttachmentResource(Resource commentResource, java.lang.String name, java.io.InputStream inputStream, java.lang.String mimeType)
Add an attachment to the givenComment. The attachment is represented by the givenname(file name), anInputStreamand the mime type, all of which are mandatory parameters. The relative path with which the attachment is created can be customized viagetAttachmentResourcePath(String), also arbitrary properties can be set on the attachment's content node viacustomizeAttachmentNode(Resource, javax.jcr.Node).- Parameters:
commentResource- The comment to which to add the attachment.name- The name (file name) for the attachment.inputStream- The input stream containing the file data of the attachment.mimeType- The mime type of the attachment data.- Returns:
- The newly created attachment resource.
- Throws:
CommentException- Upon encountering an error writing to the repository.
-
getAttachmentResource
public Resource getAttachmentResource(Resource commentResource, java.lang.String name)
Return the attachment of the givenCommentas identified by its givenname(file name).- Parameters:
commentResource- The comment from which to get the attachment.name- The name of the attachment.- Returns:
- The
Resourcerepresenting the attachment, ornullif no attachment with the given name was found. - Throws:
CommentException- Upon encountering an error retrieving the attachment.
-
removeAttachmentResource
public void removeAttachmentResource(Resource commentResource, java.lang.String name)
Remove (delete) the attachment identified by the givennamefrom the givenComment.- Parameters:
commentResource- The comment from which to remove the attachment.name- The name of the attachment to remove.- Throws:
CommentException- Upon encountering an error writing to the repository.
-
getAttachmentMap
public final java.util.Map<java.lang.String,Resource> getAttachmentMap(Resource commentResource) throws CommentException
Return aMapcontaining the givenComments attachments. The map key is the attachment's name (file name), the map value holds theResourcerepresenting the attachment.- Parameters:
commentResource- The comment for which to retrieve the attachments.- Returns:
- The map of attachments, or an empty map if no attachments are present.
- Throws:
CommentException- Upon encountering an error retrieving the attachments.
-
getCollectionResourceType
public abstract java.lang.String getCollectionResourceType()
Returns an optional resource type to set for newly created collections.- Returns:
- The resource type or
nullif none shall be set.
-
getCommentResourceType
public abstract java.lang.String getCommentResourceType()
Returns an optional resource type to set for newly created comments.- Returns:
- The resource type or
nullif none shall be set.
-
-