import grails.util.GrailsUtil import org.codehaus.groovy.grails.commons.ConfigurationHolder as CH import groovy.xml.StreamingMarkupBuilder class CachefilterGrailsPlugin { // the plugin version def version = "0.2" // the version or versions of Grails the plugin is designed for def grailsVersion = "1.1 > *" // the other plugins this plugin depends on def dependsOn = [:] // resources that are excluded from plugin packaging def pluginExcludes = [ "grails-app/views/error.gsp" ] // TODO Fill in these fields def author = "Jean-Guy Avelin" def authorEmail = "avelin@univ-brest.fr" def title = "cache html generated page and binary content" def description = '''\\ use oscache CacheFilter servlet filter to cache html and binary content. prevent unecessary calls to controllers and DB. ''' // URL to the plugin's documentation def documentation = "http://grails.org/Cachefilter+Plugin" def doWithSpring = { // TODO Implement runtime spring config (optional) } def doWithApplicationContext = { applicationContext -> // TODO Implement post initialization spring config (optional) } def doWithWebDescriptor = { webXml -> def contextParam = webXml.'context-param' def cache = application.config.cachefilter //System.err.println cache if (!cache) { System.out.println 'No CacheFilter config : no filter added' return true; } //System.err.println 'Flat '+org.codehaus.groovy.grails.commons.ConfigurationHolder.getFlatConfig() cache.filters.each {cacheFilterName,v -> println "Cache Filter :"+cacheFilterName+' -> '+v if (v.enabled) { contextParam[contextParam.size() - 1] + { 'filter' { 'filter-name'(cacheFilterName ?: 'CacheFilter') 'filter-class'('com.opensymphony.oscache.web.filter.CacheFilter') v.each {k,val -> println ' '+k+'->'+val if (k!='enabled' && k!= 'pattern') { 'init-param' { 'param-name'(k) 'param-value'(val) } } } } } } } def filter = webXml.'filter' filter[filter.size() - 1] + { cache.filters.each {cacheFilterName,v -> println "filter :"+cacheFilterName+' ->url pattern '+v['pattern'] if (v.enabled) { def pat = v['pattern'] if (pat) { pat.split(',').each { url -> def pattern = url.toString() 'filter-mapping'{ 'filter-name'(cacheFilterName) 'url-pattern'(pattern) } } } else { 'filter-mapping'{ 'filter-name'(cacheFilterName) 'url-pattern'('/*') } } } } } // println new StreamingMarkupBuilder().bind{ out << webXml.'filter' } } def doWithDynamicMethods = { ctx -> // TODO Implement registering dynamic methods to classes (optional) } def onChange = { event -> // TODO Implement code that is executed when any artefact that this plugin is // watching is modified and reloaded. The event contains: event.source, // event.application, event.manager, event.ctx, and event.plugin. } def onConfigChange = { event -> // TODO Implement code that is executed when the project configuration changes. // The event is the same as for 'onChange'. } }