1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.mycore.iiif.presentation.impl;
20
21 import java.lang.reflect.Constructor;
22 import java.lang.reflect.InvocationTargetException;
23 import java.util.HashMap;
24 import java.util.Map;
25
26 import org.mycore.common.MCRException;
27 import org.mycore.common.config.MCRConfiguration2;
28 import org.mycore.common.config.MCRConfigurationException;
29 import org.mycore.iiif.presentation.model.basic.MCRIIIFManifest;
30
31 public abstract class MCRIIIFPresentationImpl {
32
33 private static final String MCR_IIIF_PRESENTATION_CONFIG_PREFIX = "MCR.IIIFPresentation.";
34
35 private static final Map<String, MCRIIIFPresentationImpl> IMPLHOLDER = new HashMap<>();
36
37 private final String implName;
38
39 public MCRIIIFPresentationImpl(final String implName) {
40 this.implName = implName;
41 }
42
43 public static synchronized MCRIIIFPresentationImpl getInstance(String implNameParameter) {
44 String implName = (implNameParameter == null || implNameParameter.isBlank())
45 ? MCRConfiguration2.getStringOrThrow("MCR.IIIFPresentation.Default")
46 : implNameParameter;
47
48 if (IMPLHOLDER.containsKey(implName)) {
49 return IMPLHOLDER.get(implName);
50 }
51
52 String classPropertyName = MCR_IIIF_PRESENTATION_CONFIG_PREFIX + implName;
53 Class<? extends MCRIIIFPresentationImpl> classObject = MCRConfiguration2.<MCRIIIFPresentationImpl>getClass(
54 classPropertyName)
55 .orElseThrow(() -> MCRConfiguration2.createConfigurationException(classPropertyName));
56
57 try {
58 Constructor<? extends MCRIIIFPresentationImpl> constructor = classObject.getConstructor(String.class);
59 MCRIIIFPresentationImpl presentationImpl = constructor.newInstance(implName);
60 IMPLHOLDER.put(implName, presentationImpl);
61 return presentationImpl;
62 } catch (NoSuchMethodException e) {
63 throw new MCRConfigurationException(
64 "Configurated class (" + classObject.getName() + ") needs a string constructor: " + classPropertyName);
65 } catch (IllegalAccessException | InstantiationException | InvocationTargetException e) {
66 throw new MCRException(e);
67 }
68 }
69
70 public String getImplName() {
71 return implName;
72 }
73
74 protected final Map<String, String> getProperties() {
75 return MCRConfiguration2.getSubPropertiesMap(getConfigPrefix());
76 }
77
78 private String getConfigPrefix() {
79 return MCR_IIIF_PRESENTATION_CONFIG_PREFIX + implName + ".";
80 }
81
82
83
84
85
86
87
88
89
90
91 public String normalizeIdentifier(String identifier) {
92 return identifier;
93 }
94
95 public abstract MCRIIIFManifest getManifest(String id);
96
97 }