1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.mycore.iview2.frontend;
20
21 import java.nio.file.Files;
22 import java.util.Collection;
23
24 import org.apache.logging.log4j.LogManager;
25 import org.apache.logging.log4j.Logger;
26 import org.mycore.access.MCRAccessManager;
27 import org.mycore.common.config.MCRConfiguration2;
28 import org.mycore.datamodel.common.MCRLinkTableManager;
29 import org.mycore.datamodel.niofs.MCRPath;
30 import org.mycore.frontend.MCRFrontendUtil;
31 import org.mycore.frontend.servlets.MCRServlet;
32 import org.mycore.iview2.services.MCRIView2Tools;
33
34
35
36
37
38
39
40
41 public class MCRIView2XSLFunctionsAdapter {
42 private static Logger LOGGER = LogManager.getLogger(MCRIView2XSLFunctionsAdapter.class);
43
44 private static final MCRLinkTableManager LINK_TABLE_MANAGER = MCRLinkTableManager.instance();
45
46 public static MCRIView2XSLFunctionsAdapter getInstance() {
47 return MCRConfiguration2
48 .<MCRIView2XSLFunctionsAdapter>getInstanceOf(MCRIView2Tools.CONFIG_PREFIX + "MCRIView2XSLFunctionsAdapter")
49 .orElseGet(MCRIView2XSLFunctionsAdapter::new);
50 }
51
52 public boolean hasMETSFile(String derivateID) {
53 return Files.exists(MCRPath.getPath(derivateID, "/mets.xml"));
54 }
55
56 public String getSupportedMainFile(String derivateID) {
57 return MCRIView2Tools.getSupportedMainFile(derivateID);
58 }
59
60 public String getOptions(String derivateID, String extensions) {
61 final Collection<String> sources = LINK_TABLE_MANAGER.getSourceOf(derivateID, "derivate");
62 String objectID = (sources != null && !sources.isEmpty()) ? sources.iterator().next() : "";
63 StringBuilder options = new StringBuilder();
64 options.append('{');
65 options.append("\"derivateId\":").append('\"').append(derivateID).append("\",");
66 options.append("\"objectId\":").append('\"').append(objectID).append("\",");
67 options.append("\"webappBaseUri\":").append('\"').append(MCRFrontendUtil.getBaseURL()).append("\",");
68 String baseUris = MCRConfiguration2.getString("MCR.Module-iview2.BaseURL").orElse("");
69 if (baseUris.length() < 10) {
70 baseUris = MCRServlet.getServletBaseURL() + "MCRTileServlet";
71 }
72 options.append("\"baseUri\":").append('\"').append(baseUris).append("\".split(\",\")");
73 if (MCRAccessManager.checkPermission(derivateID, "create-pdf")) {
74 options.append(",\"pdfCreatorURI\":").append('\"')
75 .append(MCRConfiguration2.getString("MCR.Module-iview2.PDFCreatorURI").orElse("")).append("\",");
76 options.append("\"pdfCreatorStyle\":").append('\"')
77 .append(MCRConfiguration2.getString("MCR.Module-iview2.PDFCreatorStyle").orElse("")).append('\"');
78 }
79
80 if (extensions != null && !extensions.equals("")) {
81 options.append(',');
82 options.append(extensions);
83 }
84
85 options.append('}');
86 LOGGER.debug(options.toString());
87 return options.toString();
88 }
89 }