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 - 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.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: *
64: ******************************************************************************************************************/
65: @Nonnull
66: public static String getMetadataString (@Nonnull final String id, @Nonnull final String format)
67: {
68: try
69: {
70: return getInstance().getMetadataString(new Id(id), format);
71: }
72: catch (Exception e)
73: {
74: log.error("During XSLT invocation", e);
75: return "ERROR";
76: }
77: }
78:
79: /*******************************************************************************************************************
80: *
81: *
82: *
83: ******************************************************************************************************************/
84: @Nonnull
85: public static synchronized MediaMetadataXsltAdapter getInstance()
86: {
87:• if (instance == null)
88: {
89: instance = new MediaMetadataXsltAdapter();
90: }
91:
92: return instance;
93: }
94:
95: /*******************************************************************************************************************
96: *
97: *
98: *
99: ******************************************************************************************************************/
100: private MediaMetadataXsltAdapter()
101:• {
102: mediaMetadataProvider = findMediaMetadataProvider();
103:• }
104:
105: /*******************************************************************************************************************
106: *
107: *
108: *
109: ******************************************************************************************************************/
110: @Nonnull
111: private String getMetadataString (@Nonnull final Id id, @Nonnull final String format)
112: throws NotFoundException
113: {
114: // FIXME: should use current SiteNode properties
115: final var properties = siteProvider.get().getSite().find(SiteNode.class)
116: .withRelativePath("/")
117: .result()
118: .getProperties();
119: return mediaMetadataProvider.getMetadataString(id, format, properties);
120: }
121:
122: /*******************************************************************************************************************
123: *
124: * Finds the {@link MediaMetadataProvider}.
125: *
126: ******************************************************************************************************************/
127: @Nonnull
128: private MediaMetadataProvider findMediaMetadataProvider()
129: {
130: // FIXME: should be read by Node properties
131: final var metadataProviderName = "EmbeddedMediaMetadataProvider";
132:
133: try
134: {
135: return context.getBean(metadataProviderName, MediaMetadataProvider.class);
136: }
137: catch (NoSuchBeanDefinitionException e)
138: {
139: log.warn("Cannot find bean: {}", metadataProviderName);
140: return MediaMetadataProvider.VOID;
141: }
142: }
143: }