Skip to content

Package: SlideShowProPlayerGalleryLoader

SlideShowProPlayerGalleryLoader

nameinstructionbranchcomplexitylinemethod
SlideShowProPlayerGalleryLoader(BeanFactory, ResourceProperties)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
loadGallery(SiteNode)
M: 82 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 17 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 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.loader;
28:
29: import javax.annotation.Nonnull;
30: import java.util.ArrayList;
31: import java.util.List;
32: import java.io.IOException;
33: import java.io.StringReader;
34: import javax.xml.parsers.DocumentBuilderFactory;
35: import javax.xml.parsers.ParserConfigurationException;
36: import javax.xml.xpath.XPathConstants;
37: import javax.xml.xpath.XPathExpressionException;
38: import javax.xml.xpath.XPathFactory;
39: import org.springframework.beans.factory.BeanFactory;
40: import org.w3c.dom.DOMException;
41: import org.w3c.dom.NodeList;
42: import org.xml.sax.InputSource;
43: import org.xml.sax.SAXException;
44: import it.tidalwave.util.Id;
45: import it.tidalwave.util.Key;
46: import it.tidalwave.util.NotFoundException;
47: import it.tidalwave.northernwind.core.model.ResourceProperties;
48: import it.tidalwave.northernwind.core.model.SiteNode;
49: import it.tidalwave.northernwind.frontend.ui.component.gallery.GalleryViewController.GalleryItem;
50: import lombok.extern.slf4j.Slf4j;
51:
52: /***********************************************************************************************************************
53: *
54: * Specific for the format of SlideShowPro Player for Lightroom 1.9.8.5
55: *
56: * @author Fabrizio Giudici
57: *
58: **********************************************************************************************************************/
59: @Slf4j
60: public class SlideShowProPlayerGalleryLoader extends GalleryLoaderSupport
61: {
62: public static final Key<String> P_IMAGES = Key.of("images", String.class);
63:
64: private static final String XPATH_IMG = "/gallery/album/img";
65:
66: public SlideShowProPlayerGalleryLoader (@Nonnull final BeanFactory beanFactory,
67: @Nonnull final ResourceProperties properties)
68: {
69: super(beanFactory, properties);
70: }
71:
72: @Override @Nonnull
73: public List<GalleryItem> loadGallery (@Nonnull final SiteNode siteNode)
74: {
75: final List<GalleryItem> items = new ArrayList<>();
76:
77: try
78: {
79: final var dbf = DocumentBuilderFactory.newInstance(); // FIXME: inject
80: final var db = dbf.newDocumentBuilder(); // FIXME: inject
81: final var xPathFactory = XPathFactory.newInstance(); // FIXME: inject
82:
83: final var s = siteNode.getProperty(P_IMAGES).orElseThrow(NotFoundException::new); // FIXME
84: final var document = db.parse(new InputSource(new StringReader(s)));
85: final var xPath = xPathFactory.newXPath();
86: final var jx1 = xPath.compile(XPATH_IMG);
87: final var nodes = (NodeList)jx1.evaluate(document, XPathConstants.NODESET);
88:
89:• for (var i = 0; i < nodes.getLength(); i++)
90: {
91: final var node = nodes.item(i);
92: final var src = node.getAttributes().getNamedItem("src").getNodeValue().replaceAll("_", "-").replaceAll("\\.jpg$", "");
93: items.add(createItem(new Id(src)));
94: }
95: }
96: catch (ParserConfigurationException | NotFoundException | IOException |
97: SAXException | XPathExpressionException | DOMException e)
98: {
99: log.warn("", e);
100: }
101:
102: return items;
103: }
104: }