Package: HtmlTemplateHtmlTextWithTitleViewController
HtmlTemplateHtmlTextWithTitleViewController
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
HtmlTemplateHtmlTextWithTitleViewController(HtmlTemplateHtmlTextWithTitleView, SiteNode) |
|
|
|
|
|
||||||||||||||||||||
render(List) |
|
|
|
|
|
||||||||||||||||||||
toAggregate(DefaultHtmlTextWithTitleViewController.TextWithTitle) |
|
|
|
|
|
Coverage
1: /*
2: * *************************************************************************************************************************************************************
3: *
4: * NorthernWind - lightweight CMS
5: * http://tidalwave.it/projects/northernwind
6: *
7: * Copyright (C) 2011 - 2025 Tidalwave s.a.s. (http://tidalwave.it)
8: *
9: * *************************************************************************************************************************************************************
10: *
11: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
12: * You may obtain a copy of the License at
13: *
14: * http://www.apache.org/licenses/LICENSE-2.0
15: *
16: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
17: * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
18: *
19: * *************************************************************************************************************************************************************
20: *
21: * git clone https://bitbucket.org/tidalwave/northernwind-src
22: * git clone https://github.com/tidalwave-it/northernwind-src
23: *
24: * *************************************************************************************************************************************************************
25: */
26: package it.tidalwave.northernwind.frontend.ui.component.htmltextwithtitle.htmltemplate;
27:
28: import javax.annotation.Nonnull;
29: import java.util.List;
30: import it.tidalwave.northernwind.core.model.SiteNode;
31: import it.tidalwave.northernwind.core.model.Template.Aggregate;
32: import it.tidalwave.northernwind.core.model.Template.Aggregates;
33: import it.tidalwave.northernwind.frontend.ui.component.htmltextwithtitle.DefaultHtmlTextWithTitleViewController;
34: import it.tidalwave.northernwind.frontend.ui.component.htmltextwithtitle.HtmlTextWithTitleViewController;
35: import static it.tidalwave.northernwind.core.model.Template.Aggregates.toAggregates;
36: import static it.tidalwave.northernwind.frontend.ui.component.Properties.*;
37:
38: /***************************************************************************************************************************************************************
39: *
40: * <p>An implementation of {@link HtmlTextWithTitleViewController} based on HTML templates.</p>
41: *
42: * <p>The templates for rendering the page can be specified by means of the following properties:</p>
43: *
44: * <ul>
45: * <li>{@code P_TEMPLATE_PATH}: the template for rendering all the component;</li>
46: * <li>{@code P_WRAPPER_TEMPLATE_PATH}: an optional template wrapping each single item.</li>
47: * </ul>
48: *
49: * <p>This controller calls render methods to the view by passing {@link Aggregates} to be used with templates:</p>
50: *
51: * <ul>
52: * <li>{@code contents}: the items to be rendered.</li>
53: * </ul>
54: *
55: * <p>Each item of this {@link Aggregate} is composed of the following fields:</p>
56: *
57: * <ul>
58: * <li>{@code title}: the title of the item;</li>
59: * <li>{@code text}: the text of the item;</li>
60: * <li>{@code level}: the level of the post (used for rendering the title).</li>
61: * </ul>
62: *
63: * @see DefaultHtmlTextWithTitleViewController
64: * @see HtmlTemplateHtmlTextWithTitleView
65: * @author Fabrizio Giudici
66: *
67: **************************************************************************************************************************************************************/
68: public class HtmlTemplateHtmlTextWithTitleViewController extends DefaultHtmlTextWithTitleViewController
69: {
70: @Nonnull
71: private final HtmlTemplateHtmlTextWithTitleView view;
72:
73: @Nonnull
74: private final SiteNode siteNode;
75:
76: /***********************************************************************************************************************************************************
77: * Creates a new instance.
78: *
79: * @param view the controlled view
80: * @param siteNode the associated {@link SiteNode}
81: **********************************************************************************************************************************************************/
82: public HtmlTemplateHtmlTextWithTitleViewController (@Nonnull final HtmlTemplateHtmlTextWithTitleView view,
83: @Nonnull final SiteNode siteNode)
84: {
85: super(view, siteNode);
86: this.siteNode = siteNode;
87: this.view = view;
88: }
89:
90: /***********************************************************************************************************************************************************
91: * {@inheritDoc}
92: **********************************************************************************************************************************************************/
93: @Override
94: protected void render (@Nonnull final List<? extends TextWithTitle> txts)
95: {
96: final var viewProperties = siteNode.getPropertyGroup(view.getId());
97: view.render(viewProperties.getProperty(P_WRAPPER_TEMPLATE_PATH),
98: viewProperties.getProperty(P_TEMPLATE_PATH),
99: txts.stream().map(HtmlTemplateHtmlTextWithTitleViewController::toAggregate).collect(toAggregates("contents")));
100: }
101:
102: /***********************************************************************************************************************************************************
103: *
104: **********************************************************************************************************************************************************/
105: @Nonnull
106: private static Aggregate toAggregate (@Nonnull final TextWithTitle content)
107: {
108: return Aggregate.of("title", content.title).with("text", content.text).with("level", content.level);
109: }
110: }