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