forked from OpusCapita/weceem-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WeceemGrailsPlugin.groovy
208 lines (170 loc) · 8.26 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
205
206
207
208
import org.apache.commons.logging.LogFactory
import org.weceem.services.WcmContentRepositoryService
import grails.util.Environment
class WeceemGrailsPlugin {
def _log = LogFactory.getLog('org.weceem.WeceemGrailsPlugin')
// the plugin version
def version = "1.1.3-SNAPSHOT"
// the version or versions of Grails the plugin is designed for
def grailsVersion = "2.1 > *"
def observe = ["hibernate", 'services']
def loadAfter = ['logging', 'hibernate', 'services']
def loadBefore = ['controllers'] // 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/**/*"
]
def author = "jCatalog AG"
def authorEmail = "info@weceem.org"
def title = "Weceem CMS"
def description = '''\\
A CMS that you can install into your own applications, as used by the Weceem CMS application
'''
// URL to the plugin's documentation
def documentation = "http://grails.org/plugin/weceem"
def license = "APACHE"
def organization = [ name: "jCatalog AG", url: "http://weceem.org/" ]
def developers = [
[ name: "Marc Palmer", email: "marc@grailsrocks.com" ]
]
def issueManagement = [ system: "JIRA", url: "http://jira.jcatalog.com/browse/WCM" ]
def scm = [ url: "https://github.com/jCatalog/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)
// Configure caching
boolean hasEhCacheConfigXML = application.parentContext.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 = application.parentContext.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'
}
}
}
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}"
applicationContext.navigationService.registerItem( 'weceem',
[controller:'wcmRepository', action:'treeTable', title:'content', path:'contentrepo', order:0])
applicationContext.navigationService.registerItem( 'weceem',
[controller:'wcmPortal', action:'administration', title:'administration', path:'admin',order:2])
// Register the standard admin sections
[
[controller:'wcmSpace', action:'list', title:'spaces', path:'admin/spaces', order: 0],
[controller:'wcmSynchronization', action:'list', title:'synchronize', path:'admin/files/synchronize', order: 1],
[controller:'wcmPortal', action:'comingsoon', title:'plugins', path:'admin/plugins', order: 2],
[controller:'wcmPortal', action:'licenses', title:'licenses', path:'admin/licenses', order: 3],
[controller:'wcmPortal', action:'comingsoon', title:'linkcheck', path:'admin/linkchecker', order: 4] ].each { item ->
applicationContext.navigationService.registerItem( 'weceem.plugin.admin', item)
}
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 = "ofm"
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'.
}
}