Skip to content

Commit 638da40

Browse files
committed
refactor: move Url.asMap() to ThymeleafViewResolverInitializingBean.resourcesAsMap().
Addressed to #927 No functional changes.
1 parent c686a2b commit 638da40

File tree

2 files changed

+43
-44
lines changed

2 files changed

+43
-44
lines changed

src/main/java/ru/mystamps/web/Url.java

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,6 @@
1717
*/
1818
package ru.mystamps.web;
1919

20-
import ru.mystamps.web.feature.account.AccountUrl;
21-
import ru.mystamps.web.feature.category.CategoryUrl;
22-
import ru.mystamps.web.feature.collection.CollectionUrl;
23-
import ru.mystamps.web.feature.country.CountryUrl;
24-
import ru.mystamps.web.feature.image.ImageUrl;
25-
import ru.mystamps.web.feature.participant.ParticipantUrl;
26-
import ru.mystamps.web.feature.report.ReportUrl;
27-
import ru.mystamps.web.feature.series.SeriesUrl;
28-
import ru.mystamps.web.feature.series.importing.SeriesImportUrl;
29-
import ru.mystamps.web.feature.series.importing.sale.SeriesSalesImportUrl;
30-
import ru.mystamps.web.feature.site.ResourceUrl;
31-
import ru.mystamps.web.feature.site.SiteUrl;
32-
33-
import java.util.HashMap;
34-
import java.util.Map;
35-
3620
/**
3721
* Holds path to site and all URLs.
3822
*
@@ -48,30 +32,4 @@ public final class Url {
4832
private Url() {
4933
}
5034

51-
public static Map<String, String> asMap(boolean production) {
52-
// Not all URLs are exported here but only those that are being used on views
53-
Map<String, String> map = new HashMap<>();
54-
AccountUrl.exposeUrlsToView(map);
55-
CategoryUrl.exposeUrlsToView(map);
56-
CountryUrl.exposeUrlsToView(map);
57-
CollectionUrl.exposeUrlsToView(map);
58-
ParticipantUrl.exposeUrlsToView(map);
59-
ReportUrl.exposeUrlsToView(map);
60-
ResourceUrl.exposeUrlsToView(map);
61-
SeriesUrl.exposeUrlsToView(map);
62-
SeriesImportUrl.exposeUrlsToView(map);
63-
SeriesSalesImportUrl.exposeUrlsToView(map);
64-
SiteUrl.exposeUrlsToView(map);
65-
66-
ResourceUrl.exposeWebjarResourcesToView(map, production);
67-
68-
map.put("PUBLIC_URL", production ? SiteUrl.PUBLIC_URL : SiteUrl.SITE);
69-
70-
String resourcesHost = production ? ResourceUrl.STATIC_RESOURCES_URL : null;
71-
ImageUrl.exposeResourcesToView(map, resourcesHost);
72-
ResourceUrl.exposeResourcesToView(map, resourcesHost);
73-
74-
return map;
75-
}
76-
7735
}

src/main/java/ru/mystamps/web/support/spring/boot/ThymeleafViewResolverInitializingBean.java

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,21 @@
2727
import org.springframework.context.annotation.Configuration;
2828
import org.springframework.core.env.Environment;
2929
import org.thymeleaf.spring4.view.ThymeleafViewResolver;
30-
import ru.mystamps.web.Url;
30+
import ru.mystamps.web.feature.account.AccountUrl;
31+
import ru.mystamps.web.feature.category.CategoryUrl;
32+
import ru.mystamps.web.feature.collection.CollectionUrl;
33+
import ru.mystamps.web.feature.country.CountryUrl;
34+
import ru.mystamps.web.feature.image.ImageUrl;
35+
import ru.mystamps.web.feature.participant.ParticipantUrl;
36+
import ru.mystamps.web.feature.report.ReportUrl;
37+
import ru.mystamps.web.feature.series.SeriesUrl;
38+
import ru.mystamps.web.feature.series.importing.SeriesImportUrl;
39+
import ru.mystamps.web.feature.series.importing.sale.SeriesSalesImportUrl;
40+
import ru.mystamps.web.feature.site.ResourceUrl;
41+
import ru.mystamps.web.feature.site.SiteUrl;
42+
43+
import java.util.HashMap;
44+
import java.util.Map;
3145

3246
/**
3347
* Adjusts {@link ThymeleafViewResolver} instance by setting static variables.
@@ -59,7 +73,34 @@ public void afterPropertiesSet() throws Exception {
5973
}
6074

6175
boolean productionEnv = environment.acceptsProfiles("prod");
62-
viewResolver.setStaticVariables(Url.asMap(productionEnv));
76+
viewResolver.setStaticVariables(resourcesAsMap(productionEnv));
77+
}
78+
79+
// Not all URLs are exported here but only those that are being used on views
80+
private Map<String, ?> resourcesAsMap(boolean production) {
81+
Map<String, String> map = new HashMap<>();
82+
83+
map.put("PUBLIC_URL", production ? SiteUrl.PUBLIC_URL : SiteUrl.SITE);
84+
85+
AccountUrl.exposeUrlsToView(map);
86+
CategoryUrl.exposeUrlsToView(map);
87+
CountryUrl.exposeUrlsToView(map);
88+
CollectionUrl.exposeUrlsToView(map);
89+
ParticipantUrl.exposeUrlsToView(map);
90+
ReportUrl.exposeUrlsToView(map);
91+
ResourceUrl.exposeUrlsToView(map);
92+
SeriesUrl.exposeUrlsToView(map);
93+
SeriesImportUrl.exposeUrlsToView(map);
94+
SeriesSalesImportUrl.exposeUrlsToView(map);
95+
SiteUrl.exposeUrlsToView(map);
96+
97+
String resourcesHost = production ? ResourceUrl.STATIC_RESOURCES_URL : null;
98+
ImageUrl.exposeResourcesToView(map, resourcesHost);
99+
ResourceUrl.exposeResourcesToView(map, resourcesHost);
100+
101+
ResourceUrl.exposeWebjarResourcesToView(map, production);
102+
103+
return map;
63104
}
64105

65106
}

0 commit comments

Comments
 (0)