Skip to content

Package: HtmlTemplateHtmlTextWithTitleViewController

HtmlTemplateHtmlTextWithTitleViewController

nameinstructionbranchcomplexitylinemethod
HtmlTemplateHtmlTextWithTitleViewController(HtmlTemplateHtmlTextWithTitleView, SiteNode)
M: 0 C: 11
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
render(List)
M: 0 C: 25
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
toAggregate(DefaultHtmlTextWithTitleViewController.TextWithTitle)
M: 0 C: 14
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

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