1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.mycore.common.content.transformer;
20
21 import java.util.HashMap;
22
23 import org.mycore.common.config.MCRConfiguration2;
24
25
26
27
28
29
30 public class MCRContentTransformerFactory {
31
32
33 private static HashMap<String, MCRContentTransformer> transformers = new HashMap<>();
34
35
36
37
38
39 public static MCRContentTransformer getTransformer(String id) {
40 if (transformers.containsKey(id)) {
41 return transformers.get(id);
42 } else {
43 return buildTransformer(id);
44 }
45 }
46
47
48
49
50 private static synchronized MCRContentTransformer buildTransformer(String id) {
51 String property = "MCR.ContentTransformer." + id + ".Class";
52 if (MCRConfiguration2.getString(property).isEmpty()
53 && MCRConfiguration2.getString("MCR.ContentTransformer." + id + ".Stylesheet").isEmpty()) {
54
55 return null;
56 }
57 MCRContentTransformer transformer = MCRConfiguration2.<MCRContentTransformer>getInstanceOf(property)
58 .orElseGet(MCRXSLTransformer::new);
59 transformer.init(id);
60 transformers.put(id, transformer);
61 return transformer;
62 }
63 }