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