-
Notifications
You must be signed in to change notification settings - Fork 47
/
WeceemGrailsPlugin.groovy
204 lines (168 loc) · 7.89 KB
/
WeceemGrailsPlugin.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
import org.apache.commons.logging.LogFactory
import grails.util.Environment
import org.springframework.core.io.support.PathMatchingResourcePatternResolver
class WeceemGrailsPlugin {
def _log = LogFactory.getLog('org.weceem.WeceemGrailsPlugin')
// the plugin version
def version = "1.4.3-SNAPSHOT"
// the version or versions of Grails the plugin is designed for
def grailsVersion = "2.3 > *"
def observe = ["hibernate", 'services']
def loadAfter = ['logging']
def loadBefore = ['controllers', 'ckeditor', 'elasticsearch'] // Make sure taglib sees configured service
// resources that are excluded from plugin packaging
def pluginExcludes = [
"grails-app/views/error.gsp",
"web-app/WeceemFiles/**/*",
"web-app/testing/**/*",
"src/docs/**"
]
def author = "OpusCapita Software GmbH"
def authorEmail = "info@weceem.org"
def title = "Weceem CMS"
def description = '''Weceem CMS is a free, open source content management system.'''
// URL to the plugin's documentation
def documentation = "http://grails.org/plugin/weceem"
def license = "APACHE"
def organization = [name: "OpusCapita Software GmbH", url: "http://www.opuscapita.com/"]
def developers = [
[ name: "Marc Palmer", email: "marc@grailsrocks.com" ]
]
def issueManagement = [system: "GitHub", url: "https://github.com/OpusCapita/weceem-plugin/issues"]
def scm = [ url: "https://github.com/OpusCapita/weceem-plugin" ]
def getWebXmlFilterOrder() {
def FilterManager = getClass().getClassLoader().loadClass('grails.plugin.webxml.FilterManager')
[ WeceemFileFilter: FilterManager.URL_MAPPING_POSITION + 10000 ]
}
def doWithSpring = {
simpleSpaceExporter(org.weceem.export.SimpleSpaceExporter) {
grailsApplication = ref('grailsApplication')
proxyHandler = ref('proxyHandler')
}
simpleSpaceImporter(org.weceem.export.SimpleSpaceImporter) {
grailsApplication = ref('grailsApplication')
proxyHandler = ref('proxyHandler')
}
confluenceSpaceImporter(org.weceem.export.ConfluenceSpaceImporter) {
grailsApplication = ref('grailsApplication')
}
wcmRenderEngine(org.weceem.content.RenderEngine) {
// We can't wire up here, dependency pain
proxyHandler = ref('proxyHandler')
}
// Register our custom binding beans
customPropertyEditorRegistrar(org.weceem.binding.CustomPropertyEditorRegistrar)
uploadConfigHandler(org.weceem.upload.CKEditorUploadConfigHandler) {
grailsApplication = ref('grailsApplication')
}
// Configure caching
boolean hasEhCacheConfigXML = new PathMatchingResourcePatternResolver().getResource('classpath:/ehcache.xml').exists()
if (hasEhCacheConfigXML) {
// We assume app dev is managing cache with their own ehcache.xml
println "Weceem: Initializing ehcache with default ehcache.xml from application"
weceemCacheManager(net.sf.ehcache.CacheManager) { bean ->
bean.destroyMethod = 'shutdown'
}
} else {
// init with default Weceem caching
def configRes = new PathMatchingResourcePatternResolver().getResource('classpath:/weceem-default-ehcache.xml')
println "Weceem: Initializing ehcache with default weceem ehcache.xml from plugin resource: ${configRes}"
weceemCacheManager(net.sf.ehcache.CacheManager, configRes.URL) { bean ->
bean.destroyMethod = 'shutdown'
}
}
//configure defaults for elasticsearch plugin here
if (!application.config.elasticSearch.datastoreImpl) {
def searchableConfig = new ConfigObject()
searchableConfig.elasticSearch.datastoreImpl = 'hibernateDatastore'
application.config.merge(searchableConfig)
}
def searchableConfig = new ConfigObject()
searchableConfig.elasticSearch.unmarshallComponents = false
application.config.merge(searchableConfig)
}
def doWithApplicationContext = { applicationContext ->
_log.info "Weceem plugin running with data source ${applicationContext.dataSource.dump()}"
_log.info "Weceem plugin running with grails configuration ${applicationContext.grailsApplication.config}"
def repSvc = applicationContext.wcmContentRepositoryService
repSvc.loadConfig()
applicationContext.wcmEditorService.cacheEditorInfo()
configureCKEditor(repSvc.uploadDir, repSvc.uploadUrl, application)
repSvc.createDefaultStatuses()
def createDefSpace = application.config.weceem.create.default.space
if (createDefSpace instanceof ConfigObject) {
createDefSpace = true
} else {
createDefSpace = createDefSpace instanceof Boolean ? createDefSpace : createDefSpace.asBoolean()
}
if (createDefSpace) {
if (Environment.current != Environment.TEST) {
repSvc.createDefaultSpace()
}
}
applicationContext.wcmContentDependencyService.reset()
applicationContext.wcmRenderEngine.wcmSecurityService = applicationContext.wcmSecurityService
applicationContext.wcmRenderEngine.wcmContentRepositoryService = applicationContext.wcmContentRepositoryService
}
def configureCKEditor(dir, url, application) {
def settings = application.config
def co = new ConfigObject()
co.ckeditor.upload.basedir = dir.toString()
co.ckeditor.upload.baseurl = url.toString()
co.ckeditor.upload.overwrite = false
co.ckeditor.defaultFileBrowser = "wcmofm"
co.ckeditor.upload.image.browser = true
co.ckeditor.upload.image.upload = true
co.ckeditor.upload.image.allowed = ['jpg', 'gif', 'jpeg', 'png']
co.ckeditor.upload.image.denied = []
co.ckeditor.upload.link.browser = true
co.ckeditor.upload.link.upload = true
co.ckeditor.upload.link.allowed = ['pdf', 'doc', 'docx', 'zip', 'jpg', 'jpeg', 'png']
co.ckeditor.upload.media.upload = true
co.ckeditor.upload.media.allowed = ['mpg','mpeg','avi','wmv','asf','mov']
co.ckeditor.upload.media.denied = []
co.ckeditor.upload.flash.upload = true
co.ckeditor.upload.flash.allowed = ['swf']
co.ckeditor.upload.flash.denied = []
settings.merge(co)
}
def doWithWebDescriptor = { webXml ->
// TODO Implement additions to web.xml (optional)
// Install filter for /$uploadUrl that
// extracts space URI part, converts back to space
// asks sec svc if current user can view that uri
// returns file if so
log.info("Adding servlet filter")
def listeners = webXml.listener[0]
listeners + {
'listener' {
'listener-class'("org.weceem.servlet.SessionChangeListener")
}
}
def filters = webXml.filter[0]
filters + {
'filter' {
'filter-name'("WeceemFileFilter")
'filter-class'("org.weceem.filter.UploadedFileFilter")
}
}
def filterMappings = webXml."filter-mapping"
def lastMapping = filterMappings[filterMappings.size() - 1]
lastMapping + {
'filter-mapping' {
'filter-name'("WeceemFileFilter")
'url-pattern'("/*")
}
}
}
def doWithDynamicMethods = { ctx ->
}
def onChange = { event ->
// Reload all if service / whole app reloaded
applicationContext.wcmEditorService.cacheEditorInfo()
}
def onConfigChange = { event ->
// TODO Implement code that is executed when the project configuration changes.
// The event is the same as for 'onChange'.
}
}