|
1 | 1 | package org.edu_sharing.repository.tools;
|
2 | 2 |
|
3 | 3 | import jakarta.servlet.http.HttpServletRequest;
|
4 |
| -import org.apache.commons.logging.Log; |
5 |
| -import org.apache.commons.logging.LogFactory; |
| 4 | +import lombok.NonNull; |
| 5 | +import lombok.extern.slf4j.Slf4j; |
| 6 | +import org.apache.commons.lang3.StringUtils; |
6 | 7 | import org.edu_sharing.alfresco.repository.server.authentication.Context;
|
7 | 8 | import org.edu_sharing.repository.server.RequestHelper;
|
8 | 9 | import org.edu_sharing.repository.server.tools.ApplicationInfo;
|
9 | 10 | import org.edu_sharing.repository.server.tools.ApplicationInfoList;
|
10 | 11 |
|
| 12 | +@Slf4j |
11 | 13 | public class URLHelper {
|
12 | 14 |
|
13 |
| - private static Log logger = LogFactory.getLog(URLHelper.class); |
14 |
| - |
15 |
| - public static String getBaseUrl(boolean dynamic){ |
| 15 | + public static String getBaseUrl(boolean dynamic) { |
16 | 16 | ApplicationInfo homeRepository = ApplicationInfoList.getHomeRepository();
|
17 |
| - if(dynamic && homeRepository.getBoolean(ApplicationInfo.KEY_URL_DYNAMIC,false)) { |
| 17 | + if (dynamic && homeRepository.getBoolean(ApplicationInfo.KEY_URL_DYNAMIC, false)) { |
18 | 18 | try {
|
19 | 19 | HttpServletRequest req = Context.getCurrentInstance().getRequest();
|
20 | 20 | return getBaseUrlFromRequest(req);
|
21 |
| - } |
22 |
| - catch(Throwable t){ |
23 |
| - logger.debug("Failed to get dynamic base url, will use the one defined in homeApp"); |
| 21 | + } catch (Throwable t) { |
| 22 | + log.debug("Failed to get dynamic base url, will use the one defined in homeApp"); |
24 | 23 | }
|
25 | 24 | }
|
26 | 25 |
|
@@ -48,46 +47,72 @@ public static String getNgRenderNodeUrl(String nodeId, String version, boolean d
|
48 | 47 |
|
49 | 48 | /**
|
50 | 49 | * Get the url to the angular rendering component
|
| 50 | + * |
51 | 51 | * @param nodeId
|
52 | 52 | * @param version may be null to use the latest
|
53 | 53 | * @return
|
54 | 54 | */
|
55 |
| - public static String getNgRenderNodeUrl(String nodeId,String version,boolean dynamic, String repository) { |
56 |
| - String ngComponentsUrl = getNgComponentsUrl(dynamic)+"render/"+nodeId+(version!=null && !version.equals("-1") && !version.trim().isEmpty() ? "/"+version : ""); |
57 |
| - if(repository != null) { |
58 |
| - ngComponentsUrl+="?repository="+repository; |
| 55 | + public static String getNgRenderNodeUrl(String nodeId, String version, boolean dynamic, String repository) { |
| 56 | + return getNgRenderNodeUrl(getNgComponentsUrl(dynamic), nodeId, version, repository); |
| 57 | + } |
| 58 | + |
| 59 | + public static String getNgRenderNodeUrl(String domain, String nodeId, String version) { |
| 60 | + return getNgRenderNodeUrl(getNgComponentsUrl(domain), nodeId, version, null); |
| 61 | + } |
| 62 | + |
| 63 | + private static String getNgRenderNodeUrl(@NonNull String domain, @NonNull String nodeId, String version, String repository) { |
| 64 | + StringBuilder sb = new StringBuilder(2048); |
| 65 | + sb.append(domain); |
| 66 | + sb.append("render/"); |
| 67 | + sb.append(nodeId); |
| 68 | + |
| 69 | + if(StringUtils.isNotBlank(version) && !version.equals("-1")) { |
| 70 | + sb.append("/"); |
| 71 | + sb.append(version); |
59 | 72 | }
|
60 |
| - return ngComponentsUrl; |
| 73 | + |
| 74 | + if (StringUtils.isNotBlank(repository)) { |
| 75 | + sb.append("?repository="); |
| 76 | + sb.append(repository); |
| 77 | + } |
| 78 | + |
| 79 | + return sb.toString(); |
61 | 80 | }
|
62 | 81 |
|
63 |
| - public static String getBaseUrl(String repositoryId){ |
| 82 | + |
| 83 | + public static String getBaseUrl(String repositoryId) { |
64 | 84 | ApplicationInfo repository = ApplicationInfoList.getRepositoryInfoById(repositoryId);
|
65 |
| - String hostOrDomain = (repository.getDomain() == null || repository.getDomain().trim().equals(""))? repository.getHost() : repository.getDomain(); |
66 | 85 |
|
67 |
| - String host = hostOrDomain; |
68 |
| - logger.debug("host:"+host); |
| 86 | + String host = StringUtils.isBlank(repository.getDomain()) |
| 87 | + ? repository.getHost() |
| 88 | + : repository.getDomain(); |
| 89 | + log.debug("host:{}", host); |
69 | 90 | String port = repository.getClientport();
|
70 |
| - logger.debug("port:"+port); |
| 91 | + log.debug("port:{}", port); |
71 | 92 | String edusharingcontext = repository.getWebappname();
|
72 |
| - logger.debug("edusharingcontext:"+edusharingcontext); |
| 93 | + log.debug("edusharingcontext:{}", edusharingcontext); |
73 | 94 |
|
74 | 95 | String protocol = repository.getClientprotocol();
|
75 | 96 |
|
76 | 97 |
|
77 |
| - String baseUrl = null; |
78 |
| - if(port.equals("80") || port.equals("443")){ |
79 |
| - baseUrl = protocol+"://" + host + "/"+edusharingcontext; |
80 |
| - }else{ |
81 |
| - baseUrl = protocol+"://" + host + ":" + port + "/"+ edusharingcontext; |
| 98 | + String baseUrl; |
| 99 | + if (port.equals("80") || port.equals("443")) { |
| 100 | + baseUrl = protocol + "://" + host + "/" + edusharingcontext; |
| 101 | + } else { |
| 102 | + baseUrl = protocol + "://" + host + ":" + port + "/" + edusharingcontext; |
82 | 103 | }
|
83 | 104 | return baseUrl;
|
84 | 105 | }
|
85 | 106 |
|
86 |
| - public static String getNgComponentsUrl(){ |
| 107 | + public static String getNgComponentsUrl() { |
87 | 108 | return getNgComponentsUrl(true);
|
88 | 109 | }
|
89 | 110 |
|
90 |
| - public static String getNgComponentsUrl(boolean dynamic){ |
91 |
| - return getBaseUrl(dynamic)+"/components/"; |
| 111 | + public static String getNgComponentsUrl(String baseUrl) { |
| 112 | + return baseUrl.replaceAll("/$","") + "/components/"; |
| 113 | + } |
| 114 | + |
| 115 | + public static String getNgComponentsUrl(boolean dynamic) { |
| 116 | + return getNgComponentsUrl(getBaseUrl(dynamic)); |
92 | 117 | }
|
93 | 118 | }
|
0 commit comments