Fork me on GitHub

Developer's How-to (Hippo CMS Document Commenting Plugin)

Configuring 'Commenting' Field in Document Template (a.k.a 'namespace')

In a document type definition (a.k.a, a namespace configuration), you should add a custom field under editor:templates/_default_ node like the following example (document-commenting node) in System View XML format:

<?xml version="1.0" encoding="UTF-8"?>
<sv:node sv:name="newsdocument" xmlns:sv="http://www.jcp.org/jcr/sv/1.0">
  <sv:property sv:name="jcr:primaryType" sv:type="Name">
    <sv:value>hipposysedit:templatetype</sv:value>
  </sv:property>

  <!-- SNIP -->

  <sv:node sv:name="editor:templates">
    <sv:property sv:name="jcr:primaryType" sv:type="Name">
      <sv:value>editor:templateset</sv:value>
    </sv:property>
    <sv:node sv:name="_default_">
      <sv:property sv:name="jcr:primaryType" sv:type="Name">
        <sv:value>frontend:plugincluster</sv:value>
      </sv:property>

      <!-- SNIP -->

      <!--
        You should add something like the following for a Document Commenting field.
        Most part will be used without modification.
      -->

      <sv:node sv:name="document-commenting">
        <sv:property sv:name="jcr:primaryType" sv:type="Name">
          <sv:value>frontend:plugin</sv:value>
        </sv:property>
        <sv:property sv:name="caption" sv:type="String">
          <sv:value>Comments</sv:value>
        </sv:property>
        <sv:property sv:name="engine" sv:type="String">
          <sv:value>${engine}</sv:value>
        </sv:property>
        <sv:property sv:name="mode" sv:type="String">
          <sv:value>${mode}</sv:value>
        </sv:property>
        <sv:property sv:name="plugin.class" sv:type="String">
          <sv:value>org.onehippo.forge.document.commenting.cms.impl.DefaultDocumentCommentingFieldPlugin</sv:value>
        </sv:property>
        <sv:property sv:name="selection.mode" sv:type="String">
          <sv:value>multiple</sv:value>
        </sv:property>
        <sv:property sv:name="wicket.id" sv:type="String">
          <sv:value>${cluster.id}.right.item</sv:value>
        </sv:property>
        <sv:property sv:name="wicket.model" sv:type="String">
          <sv:value>${wicket.model}</sv:value>
        </sv:property>
        <sv:property sv:name="comment.persistence.manager" sv:type="String">
          <sv:value>org.onehippo.forge.document.commenting.cms.impl.DefaultJcrCommentPersistenceManager</sv:value>
        </sv:property>
        <sv:property sv:name="comment.query.limit" sv:type="Long">
          <sv:value>100</sv:value>
        </sv:property>
        <sv:property sv:name="dialog.size" sv:type="String">
          <sv:value>width=600,height=400</sv:value>
        </sv:property>
        <sv:property sv:name="comment.editable.author.only" sv:type="Boolean">
          <sv:value>false</sv:value>
        </sv:property>
        <sv:property sv:name="comment.deletable.author.only" sv:type="Boolean">
          <sv:value>false</sv:value>
        </sv:property>
        <sv:node sv:name="cluster.options">
          <sv:property sv:name="jcr:primaryType" sv:type="Name">
            <sv:value>frontend:pluginconfig</sv:value>
          </sv:property>
          <sv:property sv:name="jcr.comment.persistence.query" sv:type="String">
            <sv:value>//element(*,doccommenting:commentdata)[@doccommenting:subjectid=''{0}''] order by @doccommenting:created descending</sv:value>
          </sv:property>
          <sv:property sv:name="jcr.comment.persistence.date.format" sv:type="String">
            <sv:value>yyyy-MM-dd HH:mm:ss</sv:value>
          </sv:property>
        </sv:node>
      </sv:node>

      <!-- SNIP -->

    </sv:node>
  </sv:node>
</sv:node>
          

See the following for a full example in the demo project: https://github.com/bloomreach-forge/document-commenting/blob/master/demo/repository-data/config/src/main/resources/hcm-config/namespaces/doccommentingdemo/newsdocument.yaml

Implementing your own CommentPersistenceManager service

The Document Commenting plugin actually doesn't store/read data by itself, but relies on a CommentPersistenceManager service implementation specified in the plugin configuration as shown above. Therefore, you may extend the default implementation or you can replace it with a totally new implementation to support a different comment data storage (e.g, NoSQL database) for instance.

See an example CommentPersistenceManager implementation code here: https://github.com/bloomreach-forge/document-commenting/blob/master/demo/cms/src/main/java/org/onehippo/forge/document/commenting/demo/cms/CustomPrioritizingJcrCommentPersistenceManager.java

The example custom service implementation is used in the 'event' document namespace for demonstration purpose in the demo project.

Put your own implementation class in your CMS module project.

See Javadocs for detail about the CommentPersistenceManager.

Plugin Parameters

You may configure the following plugin parameters in the field definition of your document template definition (a.k.a 'namespace').

Parameter name Description Example value(s) Default value(s)
caption Field caption, used as field label and dialog title. "Remarks" "Comments"
comment.persistence.manager org.onehippo.forge.document.commenting.cms.api.CommentPersistenceManager implementation class FQN. "org.onehippo.forge.document.commenting.cms.impl.DefaultJcrCommentPersistenceManager"
comment.query.limit The JCR query limit when retrieving the latest comment data by subject ID. 20 100
dialog.size The size of the picker popup dialog. "width=500,height=350" "width=600,height=400"
comment.editable.author.only Whether or not each comment can be edited only by the original comment author. true false
comment.deletable.author.only Whether or not each comment can be deleted only by the original comment author. true false

Parameters of DefaultJcrCommentPersistenceManager

The following parameters are set for the DefaultJcrCommentPersistenceManager implementation additionally (under cluster.options node).

Parameter name Description Example value(s) Default value(s)
jcr.comment.persistence.query The JCR XPath query used when retrieving the latest comment data in the field area. //element(*,doccommenting:commentdata)[@doccommenting:subjectid=''{0}''] order by @doccommenting:lastModified descending //element(*,doccommenting:commentdata)[@doccommenting:subjectid=''{0}''] order by @doccommenting:created descending
jcr.comment.persistence.date.format The date format string to display MM/dd/yyyy HH:mm:ss yyyy-MM-dd HH:mm:ss