1
1
package au.org.ala.spatial.portal
2
2
3
+ import asset.pipeline.AssetPipelineConfigHolder
4
+ import asset.pipeline.fs.FileSystemAssetResolver
3
5
import au.org.ala.cas.util.AuthenticationUtils
4
6
import au.org.ala.web.AuthService
5
7
import grails.converters.JSON
8
+ import org.apache.commons.io.FileUtils
6
9
import org.apache.commons.lang3.StringUtils
7
10
import org.springframework.core.io.FileSystemResource
8
11
import org.springframework.core.io.Resource
@@ -28,9 +31,75 @@ class BootStrap {
28
31
// fix config data types when using a .properties file
29
32
parseConfig()
30
33
34
+ // support for external layouts
35
+ //
36
+ // e.g. config "skin.layout=myLayout" will use the layout file /data/spatial-hub/views/layouts/myLayout.gsp
37
+ //
38
+ // support external files with the asset tag in the layout gsp
39
+ // e.g.
40
+ // files
41
+ // /data/spatial-hub/assets/css/externalCss.css
42
+ // /data/spatial-hub/assets/js/externalJs.js
43
+ // /data/spatial-hub/assets/img/externalImage.png
44
+ // asset tags
45
+ // <asset:stylesheet src="css/externalCss.css" />
46
+ // <asset:javascript src="js/externalJs.js" />
47
+ // <asset:image src="img/externalImg.png" />
48
+ //
49
+ // Support the use of the default "skin.layout=generic" with a local "headerAndFooter.baseURL" by the creating files
50
+ // /data/spatial-hub/assets/css/bootstrap.min.css
51
+ // /data/spatial-hub/assets/css/ala-styles.css
52
+ addExternalViews()
53
+ addExternalAssets(servletContext)
54
+
31
55
portalService. updateListQueries()
32
56
}
33
57
58
+ def addExternalViews = {
59
+ groovyPageLocator. addResourceLoader(new ResourceLoader () {
60
+
61
+ @Override
62
+ Resource getResource (String s ) {
63
+ File resource = new File (' /data/spatial-hub/views' + s)
64
+ if (resource. exists()) {
65
+ return new FileSystemResource (resource)
66
+ }
67
+ return null
68
+ }
69
+
70
+ @Override
71
+ ClassLoader getClassLoader () {
72
+ return null
73
+ }
74
+ })
75
+ }
76
+
77
+ def addExternalAssets = { servletContext ->
78
+ try {
79
+ File src = new File (' /data/spatial-hub/assets' )
80
+
81
+ if (src. exists() && src. isDirectory()) {
82
+ // asset-pipeline resolves files differently depending on the presence of a manifest
83
+ if (AssetPipelineConfigHolder . manifest) {
84
+ // copy external asset files into expanded war assets directory so they can be discovered
85
+ File dst = new File (servletContext. getRealPath(" /assets" ))
86
+
87
+ if (dst. exists() && dst. isDirectory()) {
88
+ FileUtils . copyDirectory(src, dst)
89
+ } else {
90
+ log. error(" External assets are unavailable. Expanded WAR asset directory '${ dst.path} ' does not exist." )
91
+ }
92
+ } else {
93
+ // a new Resolver is required to find the external assets at runtime
94
+ def resolver = new FileSystemAssetResolver (" external-assets" , ' /data/spatial-hub/assets' , false )
95
+ AssetPipelineConfigHolder . registerResolver(resolver)
96
+ }
97
+ }
98
+ } catch (err) {
99
+ log. error(" External assets are not available." , err)
100
+ }
101
+ }
102
+
34
103
def destroy = {
35
104
}
36
105
0 commit comments