Class DefaultBlogViewController

  • All Implemented Interfaces:
    BlogViewController, ViewController

    public abstract class DefaultBlogViewController
    extends java.lang.Object
    implements BlogViewController

    A default implementation of the BlogViewController that is independent of the presentation technology. This class is capable to render:

    • blog posts (in various ways)
    • an index of the blog
    • a tag cloud

    It accepts path parameters as follows:

    • <uri>: selects a single post with the given uri;
    • <category>: selects posts with the given category;
    • tags/<tag>: selects posts with the given tag;
    • index: renders a post index, with links to single posts;
    • index/<category>: renders an index of posts with the given category;
    • index/tag/<tag>: renders an index of posts with the given tag.

    Supported properties of the SiteNode:

    • P_CONTENT_PATHS: one or more Content that contains the posts to render; they are folders and can have sub-folders, which will be searched for in a recursive fashion;
    • P_MAX_FULL_ITEMS: the max. number of posts to be rendered in full;
    • P_MAX_LEADIN_ITEMS: the max. number of posts to be rendered with lead-in text;
    • P_MAX_ITEMS: the max. number of posts to be rendered as links;
    • P_DATE_FORMAT: the pattern for formatting date and times;
    • P_TIME_ZONE: the time zone for rendering dates (defaults to CET);
    • P_INDEX: if true, forces an index rendering (useful e.g. when used in sidebars);
    • P_TAG_CLOUD: if true, forces a tag cloud rendering (useful e.g. when used in sidebars).

    The P_DATE_FORMAT property accepts any valid pattern in Java 8, plus the values S-, M-, L-, F-, which stand for small/medium/large and full patterns for a given locale.

    Supported properties of the Content:

    • P_TITLE: the title;
    • P_FULL_TEXT: the full text;
    • P_LEADIN_TEXT: the lead-in text;
    • P_ID: the unique id;
    • P_IMAGE_ID: the id of an image representative of the post;
    • P_PUBLISHING_DATE: the publishing date;
    • P_CREATION_DATE: the creation date;
    • P_TAGS: the tags;
    • P_CATEGORY: the category.

    When preparing for rendering, the following dynamic properties will be set, only if a single post is rendered:

    • PD_URL: the canonical URL of the post;
    • PD_ID: the unique id of the post;
    • PD_IMAGE_ID: the id of the representative image.

    Concrete implementations must provide two methods for rendering the blog posts and the tag cloud:

    Author:
    Fabrizio Giudici
    • Field Detail

      • DATE_KEYS

        protected static final java.util.List<it.tidalwave.util.Key<java.time.ZonedDateTime>> DATE_KEYS
      • TIME0

        public static final java.time.ZonedDateTime TIME0
      • DEFAULT_TIMEZONE

        public static final java.lang.String DEFAULT_TIMEZONE
        See Also:
        Constant Field Values
      • title

        protected java.util.Optional<java.lang.String> title
    • Constructor Detail

      • DefaultBlogViewController

        public DefaultBlogViewController()
    • Method Detail

      • renderPosts

        protected abstract void renderPosts​(@Nonnull
                                            java.util.List<Content> fullPosts,
                                            @Nonnull
                                            java.util.List<Content> leadinPosts,
                                            @Nonnull
                                            java.util.List<Content> linkedPosts)
                                     throws java.lang.Exception
        Renders the blog posts. Must be implemented by concrete subclasses.
        Parameters:
        fullPosts - the posts to be rendered in full
        leadinPosts - the posts to be rendered with lead in text
        linkedPosts - the posts to be rendered as references
        Throws:
        java.lang.Exception - if something fails
      • renderTagCloud

        protected abstract void renderTagCloud​(@Nonnull
                                               java.util.Collection<DefaultBlogViewController.TagAndCount> tagsAndCount)
        Renders the tag cloud. Must be implemented by concrete subclasses.
        Parameters:
        tagsAndCount - the tags
      • createLink

        @Nonnull
        protected final java.lang.String createLink​(@Nonnull
                                                    ResourcePath path)
        Creates a link for a ResourcePath.
        Parameters:
        path - the path
        Returns:
        the link
      • createTagLink

        @Nonnull
        protected final java.lang.String createTagLink​(java.lang.String tag)
        Creates a link for a tag.
        Parameters:
        tag - the tag
        Returns:
        the link
      • formatDateTime

        @Nonnull
        protected final java.lang.String formatDateTime​(@Nonnull
                                                        java.time.ZonedDateTime dateTime)
        Formats a date with the settings taken from the configuration and the request settings.
        Parameters:
        dateTime - the date to render
        Returns:
        the formatted date