Package: DefaultHtmlFragmentViewController
DefaultHtmlFragmentViewController
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
lambda$renderView$0(String) |
|
|
|
|
|
||||||||||||||||||||
lambda$renderView$1(ResourceProperties) |
|
|
|
|
|
||||||||||||||||||||
renderView(RenderContext) |
|
|
|
|
|
||||||||||||||||||||
static {...} |
|
|
|
|
|
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.htmlfragment;
27:
28: import javax.annotation.Nonnull;
29: import it.tidalwave.northernwind.core.model.Resource;
30: import it.tidalwave.northernwind.core.model.Site;
31: import it.tidalwave.northernwind.core.model.SiteNode;
32: import it.tidalwave.northernwind.frontend.ui.RenderContext;
33: import lombok.RequiredArgsConstructor;
34: import lombok.extern.slf4j.Slf4j;
35: import static java.util.Collections.emptyList;
36: import static java.util.stream.Collectors.*;
37: import static it.tidalwave.northernwind.core.model.Content.*;
38: import static it.tidalwave.northernwind.frontend.ui.component.Properties.*;
39:
40: /***************************************************************************************************************************************************************
41: *
42: * A default implementation of {@link HtmlFragmentViewController}.
43: *
44: * @author Fabrizio Giudici
45: *
46: **************************************************************************************************************************************************************/
47: @RequiredArgsConstructor @Slf4j
48: public class DefaultHtmlFragmentViewController implements HtmlFragmentViewController
49: {
50: @Nonnull
51: private final HtmlFragmentView view;
52:
53: @Nonnull
54: private final SiteNode siteNode;
55:
56: @Nonnull
57: private final Site site;
58:
59: /***********************************************************************************************************************************************************
60: * {@inheritDoc}
61: **********************************************************************************************************************************************************/
62: @Override
63: public void renderView (@Nonnull final RenderContext context)
64: {
65: final var viewProperties = siteNode.getPropertyGroup(view.getId());
66: view.setContent(viewProperties.getProperty(P_CONTENT_PATHS).orElse(emptyList())
67: .stream()
68: .flatMap(path -> site.find(_Content_).withRelativePath(path).stream())
69: .map(Resource::getProperties)
70: .map(properties -> properties.getProperty(P_FULL_TEXT) // TODO: use multi-key
71: .orElse(properties.getProperty(P_TEMPLATE)
72: .orElse("")))
73: .collect(joining("\n")));
74: view.setClassName(viewProperties.getProperty(P_CLASS).orElse("nw-" + view.getId()));
75: }
76: }