Skip to content

Package: MediaMetadataXsltAdapter

MediaMetadataXsltAdapter

nameinstructionbranchcomplexitylinemethod
MediaMetadataXsltAdapter()
M: 77 C: 0
0%
M: 22 C: 0
0%
M: 12 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
findMediaMetadataProvider()
M: 16 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
getInstance()
M: 8 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
getMetadataString(Id, String)
M: 20 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
getMetadataString(String, String)
M: 15 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 5 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 - 2025 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.spi;
28:
29: import javax.annotation.Nonnull;
30: import javax.inject.Inject;
31: import javax.inject.Provider;
32: import org.springframework.beans.factory.NoSuchBeanDefinitionException;
33: import org.springframework.beans.factory.annotation.Configurable;
34: import org.springframework.context.ApplicationContext;
35: import it.tidalwave.util.Id;
36: import it.tidalwave.util.NotFoundException;
37: import it.tidalwave.northernwind.core.model.SiteNode;
38: import it.tidalwave.northernwind.core.model.SiteProvider;
39: import lombok.extern.slf4j.Slf4j;
40:
41: /***************************************************************************************************************************************************************
42: *
43: * @author Fabrizio Giudici
44: *
45: **************************************************************************************************************************************************************/
46: @Configurable(preConstruction = true) @Slf4j
47: public final class MediaMetadataXsltAdapter
48: {
49: private static MediaMetadataXsltAdapter instance;
50:
51: @Inject
52: private ApplicationContext context;
53:
54: @Inject
55: private Provider<SiteProvider> siteProvider;
56:
57: @Nonnull
58: private final MediaMetadataProvider mediaMetadataProvider;
59:
60: /***********************************************************************************************************************************************************
61: *
62: **********************************************************************************************************************************************************/
63: @Nonnull
64: public static String getMetadataString (@Nonnull final String id, @Nonnull final String format)
65: {
66: try
67: {
68: return getInstance().getMetadataString(new Id(id), format);
69: }
70: catch (Exception e)
71: {
72: log.error("During XSLT invocation", e);
73: return "ERROR";
74: }
75: }
76:
77: /***********************************************************************************************************************************************************
78: *
79: **********************************************************************************************************************************************************/
80: @Nonnull
81: public static synchronized MediaMetadataXsltAdapter getInstance()
82: {
83:• if (instance == null)
84: {
85: instance = new MediaMetadataXsltAdapter();
86: }
87:
88: return instance;
89: }
90:
91: /***********************************************************************************************************************************************************
92: *
93: **********************************************************************************************************************************************************/
94: private MediaMetadataXsltAdapter()
95:• {
96: mediaMetadataProvider = findMediaMetadataProvider();
97:• }
98:
99: /***********************************************************************************************************************************************************
100: *
101: **********************************************************************************************************************************************************/
102: @Nonnull
103: private String getMetadataString (@Nonnull final Id id, @Nonnull final String format)
104: throws NotFoundException
105: {
106: // FIXME: should use current SiteNode properties
107: final var properties = siteProvider.get().getSite().find(SiteNode.class)
108: .withRelativePath("/")
109: .result()
110: .getProperties();
111: return mediaMetadataProvider.getMetadataString(id, format, properties);
112: }
113:
114: /***********************************************************************************************************************************************************
115: * Finds the {@link MediaMetadataProvider}.
116: **********************************************************************************************************************************************************/
117: @Nonnull
118: private MediaMetadataProvider findMediaMetadataProvider()
119: {
120: // FIXME: should be read by Node properties
121: final var metadataProviderName = "EmbeddedMediaMetadataProvider";
122:
123: try
124: {
125: return context.getBean(metadataProviderName, MediaMetadataProvider.class);
126: }
127: catch (NoSuchBeanDefinitionException e)
128: {
129: log.warn("Cannot find bean: {}", metadataProviderName);
130: return MediaMetadataProvider.VOID;
131: }
132: }
133: }