Skip to contentMethod: {...}
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.media.impl;
27:
28: import javax.annotation.Nonnull;
29: import javax.inject.Inject;
30: import java.util.List;
31: import java.io.IOException;
32: import it.tidalwave.util.Id;
33: import it.tidalwave.util.Key;
34: import it.tidalwave.util.NotFoundException;
35: import it.tidalwave.northernwind.aspect.DebugProfiling;
36: import it.tidalwave.northernwind.core.model.ResourceProperties;
37: import it.tidalwave.northernwind.frontend.ui.component.gallery.spi.MediaMetadataProvider;
38: import lombok.extern.slf4j.Slf4j;
39:
40: /***************************************************************************************************************************************************************
41: *
42: * An implementation of {@link MediaMetadataProvider} which retrieves metadata from embedded data inside media files.
43: *
44: * @author Fabrizio Giudici
45: *
46: **************************************************************************************************************************************************************/
47: @Slf4j
48: public class EmbeddedMediaMetadataProvider implements MediaMetadataProvider
49: {
50: public static final Key<List<String>> P_CAMERA_IDS = new Key<>("cameraIds") {};
51:
52: public static final Key<List<String>> P_LENS_IDS = new Key<>("lensIds") {};
53:
54: public static final Key<List<String>> P_MEDIA_PATHS = new Key<>("mediaPaths") {};
55:
56: public static final Id P_GROUP_ID = new Id("EmbeddedMediaMetadataProvider");
57:
58: @Inject
59: private MetadataCache metadataCache;
60:
61: /***********************************************************************************************************************************************************
62: * {@inheritDoc}
63: **********************************************************************************************************************************************************/
64: // FIXME: should use the Metadata API of blueMarine, but we have first to make it work with Spring and its DI.
65: @Override @Nonnull @DebugProfiling(message = "metadata retrieved")
66: public String getMetadataString (@Nonnull final Id mediaId,
67: @Nonnull final String template,
68: @Nonnull final ResourceProperties properties)
69: {
70: try
71: {
72: final var metadata = metadataCache.findMetadataById(mediaId, properties);
73: return metadata.interpolateString(template, properties);
74: }
75: catch (NotFoundException e)
76: {
77: log.warn("Cannot find media for id {}: {}", mediaId, e.toString());
78: return "";
79: }
80: catch (IOException e)
81: {
82: log.warn("Unexpected I/O error for id {}: {}", mediaId, e.toString());
83: return "";
84: }
85: }
86: }