Class StringTemplate<D>

  • Type Parameters:
    D - The type of domain object to replace with text
    All Implemented Interfaces:
    com.opentext.ia.sdk.sip.Template<D>

    public class StringTemplate<D>
    extends com.opentext.ia.sdk.sip.FixedHeaderAndFooterTemplate<D>
    Template using the StringTemplate template engine. Templates have access to the following objects:
    model
    The domain object (of type D)
    content
    The reference information and the encoded hashes of the DigitalObjects associated with the domain object, if any
    • Constructor Summary

      Constructors 
      Constructor Description
      StringTemplate​(java.io.InputStream header, java.io.InputStream footer, java.io.InputStream row)
      Create an instance.
      StringTemplate​(java.lang.String header, java.lang.String footer, java.lang.String row)
      Create an instance with the default start and end delimeters.
      StringTemplate​(java.lang.String header, java.lang.String footer, java.lang.String row, char delimeterStart, char delimeterEnd)
      Create an instance.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void prepareGroup​(org.stringtemplate.v4.STGroup group)
      Prepares a group by adding renderers, adaptors and sub templates.
      protected org.stringtemplate.v4.ST prepareTemplate​(org.stringtemplate.v4.ST prototype, D domainObject, java.util.Map<java.lang.String,​com.opentext.ia.sdk.sip.ContentInfo> contentInfo)
      Prepares the template by adding the variables.
      protected <S> void registerAdaptor​(org.stringtemplate.v4.STGroup group, java.lang.Class<S> type, org.stringtemplate.v4.ModelAdaptor adaptor)
      Registers a ModelAdaptor with the group.
      protected <S> void registerRenderer​(org.stringtemplate.v4.STGroup group, java.lang.Class<S> type, org.stringtemplate.v4.AttributeRenderer attributeRenderer)
      Registers a renderer with the group.
      void writeRow​(D domainObject, java.util.Map<java.lang.String,​com.opentext.ia.sdk.sip.ContentInfo> contentInfo, java.io.PrintWriter writer)  
      • Methods inherited from class com.opentext.ia.sdk.sip.FixedHeaderAndFooterTemplate

        toString, writeFooter, writeHeader
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • StringTemplate

        public StringTemplate​(java.io.InputStream header,
                              java.io.InputStream footer,
                              java.io.InputStream row)
        Create an instance.
        Parameters:
        header - The fixed header
        footer - The fixed footer
        row - The template for the rows
      • StringTemplate

        public StringTemplate​(java.lang.String header,
                              java.lang.String footer,
                              java.lang.String row)
        Create an instance with the default start and end delimeters.
        Parameters:
        header - The fixed header
        footer - The fixed footer
        row - The template for the rows
      • StringTemplate

        public StringTemplate​(java.lang.String header,
                              java.lang.String footer,
                              java.lang.String row,
                              char delimeterStart,
                              char delimeterEnd)
        Create an instance.
        Parameters:
        header - The fixed header
        footer - The fixed footer
        row - The template for the rows
        delimeterStart - The character that starts a StringTemplate expression.
        delimeterEnd - The character that ends a StringTemplate expression.
    • Method Detail

      • prepareGroup

        protected void prepareGroup​(org.stringtemplate.v4.STGroup group)
        Prepares a group by adding renderers, adaptors and sub templates. Override this if you want to add additional renderers. By default adds:
        • an XmlDateRenderer which renders Date instances into the standard XML date and time format
        • an MapModelAdaptor which allows Map to be used transparently as domain objects.
        Parameters:
        group - The template group
      • registerAdaptor

        protected <S> void registerAdaptor​(org.stringtemplate.v4.STGroup group,
                                           java.lang.Class<S> type,
                                           org.stringtemplate.v4.ModelAdaptor adaptor)
        Registers a ModelAdaptor with the group. Override this method if you want to suppress one OOTB adaptor but not all.
        Type Parameters:
        S - The domain object type
        Parameters:
        group - The template group
        type - The domain object class
        adaptor - The adaptor that will be used to extract properties of objects of type S
      • registerRenderer

        protected <S> void registerRenderer​(org.stringtemplate.v4.STGroup group,
                                            java.lang.Class<S> type,
                                            org.stringtemplate.v4.AttributeRenderer attributeRenderer)
        Registers a renderer with the group. Override this method if you want to suppress one OOTB renderer but not all.
        Type Parameters:
        S - The domain object type
        Parameters:
        group - The template group
        type - The domain object class
        attributeRenderer - The renderer that will be used to render objects of type S into a String
      • writeRow

        public void writeRow​(D domainObject,
                             java.util.Map<java.lang.String,​com.opentext.ia.sdk.sip.ContentInfo> contentInfo,
                             java.io.PrintWriter writer)
                      throws java.io.IOException
        Throws:
        java.io.IOException
      • prepareTemplate

        protected org.stringtemplate.v4.ST prepareTemplate​(org.stringtemplate.v4.ST prototype,
                                                           D domainObject,
                                                           java.util.Map<java.lang.String,​com.opentext.ia.sdk.sip.ContentInfo> contentInfo)
        Prepares the template by adding the variables.
        Parameters:
        prototype - The template prototype
        domainObject - The domain object
        contentInfo - The reference information and the encoded content hashes
        Returns:
        The prepared template instance