Skip to content

Package: HtmlTemplateGalleryViewController

HtmlTemplateGalleryViewController

nameinstructionbranchcomplexitylinemethod
HtmlTemplateGalleryViewController(GalleryView, SiteNode, RequestLocaleManager, ModelFactory, BeanFactory)
M: 21 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
computeInlinedScriptsSection()
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getParam(RenderContext)
M: 12 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
getViewProperties()
M: 10 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
prepareRendering(RenderContext)
M: 114 C: 0
0%
M: 8 C: 0
0%
M: 6 C: 0
0%
M: 26 C: 0
0%
M: 1 C: 0
0%
renderView(RenderContext)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

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.gallery.htmltemplate;
28:
29: import javax.annotation.Nonnull;
30: import org.springframework.beans.factory.BeanFactory;
31: import it.tidalwave.util.Id;
32: import it.tidalwave.northernwind.core.model.HttpStatusException;
33: import it.tidalwave.northernwind.core.model.ModelFactory;
34: import it.tidalwave.northernwind.core.model.RequestLocaleManager;
35: import it.tidalwave.northernwind.core.model.ResourcePath;
36: import it.tidalwave.northernwind.core.model.ResourceProperties;
37: import it.tidalwave.northernwind.core.model.SiteNode;
38: import it.tidalwave.northernwind.frontend.ui.RenderContext;
39: import it.tidalwave.northernwind.frontend.ui.component.htmltemplate.TextHolder;
40: import it.tidalwave.northernwind.frontend.ui.component.gallery.DefaultGalleryViewController;
41: import it.tidalwave.northernwind.frontend.ui.component.gallery.GalleryView;
42: import it.tidalwave.northernwind.frontend.ui.component.gallery.htmltemplate.bluette.BluetteGalleryAdapter;
43: import lombok.extern.slf4j.Slf4j;
44: import static javax.servlet.http.HttpServletResponse.*;
45: import static it.tidalwave.northernwind.core.model.Content.P_TITLE;
46:
47: /***********************************************************************************************************************
48: *
49: * @author Fabrizio Giudici
50: *
51: **********************************************************************************************************************/
52: @Slf4j
53: public class HtmlTemplateGalleryViewController extends DefaultGalleryViewController
54: {
55: @Nonnull
56: private final GalleryView view;
57:
58: @Nonnull
59: private final SiteNode siteNode;
60:
61: /*******************************************************************************************************************
62: *
63: *
64: *
65: ******************************************************************************************************************/
66: public HtmlTemplateGalleryViewController (@Nonnull final GalleryView view,
67: @Nonnull final SiteNode siteNode,
68: @Nonnull final RequestLocaleManager requestLocaleManager,
69: @Nonnull final ModelFactory modelFactory,
70: @Nonnull final BeanFactory beanFactory)
71: {
72: super(view, siteNode, requestLocaleManager, beanFactory);
73: this.view = view;
74: this.siteNode = siteNode;
75: galleryAdapter = new BluetteGalleryAdapter(siteNode, view, modelFactory); // FIXME: get implementation from configuration
76: }
77:
78: /*******************************************************************************************************************
79: *
80: * {@inheritDoc}
81: *
82: ******************************************************************************************************************/
83: @Override
84: public void prepareRendering (@Nonnull final RenderContext context)
85: throws Exception
86: {
87: super.prepareRendering(context);
88: final var param = getParam(context);
89: log.info(">>>> pathParams: *{}*", param);
90: final var textHolder = (TextHolder)view;
91: final var siteNodeTitle = siteNode.getProperty(P_TITLE).orElse("");
92:
93:• switch (param.getSegmentCount())
94: {
95: case 0: // no args, full JS gallery
96: galleryAdapter.prepareGallery(items.get(0), items);
97: textHolder.addAttribute("title", siteNodeTitle);
98: break;
99:
100: case 1:
101:• switch (param.getLeading())
102: {
103: case "images.xml":
104: galleryAdapter.prepareCatalog(items);
105: break;
106:
107: case "lightbox":
108: galleryAdapter.prepareFallbackLightbox(items);
109: textHolder.addAttribute("title", siteNodeTitle);
110: break;
111:
112: default: // id of the gallery item to render, fallback mode
113: final var id = new Id(param.getLeading());
114: final var item = itemMapById.get(id);
115:
116:• if (item == null)
117: {
118: log.warn("Gallery item not found: {}", id);
119: log.debug("Gallery item not found: {}, available: {}", id, itemMapById.keySet());
120: throw new HttpStatusException(SC_NOT_FOUND);
121: }
122:
123: galleryAdapter.prepareFallbackGallery(item, items);
124: textHolder.addAttribute("title", item.getDescription());
125: break;
126: }
127:
128: break;
129:
130: default:
131: throw new HttpStatusException(SC_BAD_REQUEST);
132: }
133: }
134:
135: /*******************************************************************************************************************
136: *
137: * {@inheritDoc}
138: *
139: ******************************************************************************************************************/
140: @Override
141: public void renderView (@Nonnull final RenderContext context)
142: throws Exception
143: {
144: super.renderView(context);
145: galleryAdapter.render(context);
146: }
147:
148: @Nonnull
149: private ResourcePath getParam (@Nonnull final RenderContext context)
150: {
151: return context.getQueryParam("_escaped_fragment_").map(ResourcePath::of)
152: .orElse(context.getPathParams(siteNode));
153: }
154:
155: /*******************************************************************************************************************
156: *
157: * {@inheritDoc}
158: *
159: ******************************************************************************************************************/
160: @Override @Nonnull
161: protected final String computeInlinedScriptsSection()
162: {
163: return super.computeInlinedScriptsSection() + "\n" + galleryAdapter.getInlinedScript();
164: }
165:
166: /*******************************************************************************************************************
167: *
168: * {@inheritDoc}
169: *
170: ******************************************************************************************************************/
171: @Override @Nonnull
172: protected ResourceProperties getViewProperties()
173: {
174: return super.getViewProperties().merged(galleryAdapter.getExtraViewProperties(view.getId()));
175: }
176: }