Skip to content

Package: HtmlTemplateSitemapViewController

HtmlTemplateSitemapViewController

nameinstructionbranchcomplexitylinemethod
HtmlTemplateSitemapViewController(SiteNode, HtmlTemplateSitemapView)
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
render(Set)
M: 0 C: 20
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
static {...}
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
toAggregate(DefaultSitemapViewController.Entry)
M: 0 C: 20
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%

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.sitemap.htmltemplate;
27:
28: import javax.annotation.Nonnull;
29: import java.time.format.DateTimeFormatter;
30: import java.util.Set;
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.sitemap.DefaultSitemapViewController;
35: import it.tidalwave.northernwind.frontend.ui.component.sitemap.SitemapViewController;
36: import static it.tidalwave.northernwind.core.model.Template.Aggregates.toAggregates;
37:
38: /***************************************************************************************************************************************************************
39: *
40: * <p>An implementation of {@link SitemapViewController} based on HTML templates.</p>
41: *
42: * <p>The template for rendering the page can be specified by means of the property {@code P_SITEMAP_TEMPLATE_PATH}.</p>
43: *
44: * <p>This controller calls render methods to the view by passing {@link Aggregates} to be used with templates.</p>
45: * <p>In case of post rendering, the following aggregates are defined:</p>
46: *
47: * <ul>
48: * <li>{@code entries}: the entries to be rendered.</li>
49: * </ul>
50: *
51: * <p>Each item is an {@link Aggregate} of the following fields:</p>
52: *
53: * <ul>
54: * <li>{@code location}: the URL of the page;</li>
55: * <li>{@code lastModification}: the last modification date of the page;</li>
56: * <li>{@code changeFrequency}: the change frequency of the page;</li>
57: * <li>{@code priority}: the priority of the page.</li>
58: * </ul>
59: *
60: * @author Fabrizio Giudici
61: *
62: **************************************************************************************************************************************************************/
63: public class HtmlTemplateSitemapViewController extends DefaultSitemapViewController
64: {
65: private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd");
66:
67: @Nonnull
68: private final HtmlTemplateSitemapView view;
69:
70: public HtmlTemplateSitemapViewController (@Nonnull final SiteNode siteNode,
71: @Nonnull final HtmlTemplateSitemapView view)
72: {
73: super(siteNode, view);
74: this.view = view;
75: }
76:
77: @Override
78: protected void render (@Nonnull final Set<? extends Entry> entries)
79: {
80: view.setMimeType("application/xml");
81: view.render(getViewProperties().getProperty(P_SITEMAP_TEMPLATE_PATH),
82: entries.stream().map(HtmlTemplateSitemapViewController::toAggregate).collect(toAggregates("entries")));
83: }
84:
85: @Nonnull
86: private static Aggregate toAggregate (@Nonnull final Entry entry)
87: {
88: return Aggregate.of("location", entry.getLocation())
89: .with("lastModification", entry.getLastModification().format(FORMATTER))
90: .with("changeFrequency", entry.getChangeFrequency())
91: .with("priority", Float.toString(entry.getPriority()));
92: }
93: }