tags:

views:

30

answers:

2

I have a plugin that relies on a custom url mapping. When i install the plugin i need to copy the content of the UrlMappings.groovy of the plugin and merge it with the one in the application where the plugin is installed

I would like however to register these url mappings directly into the grails framework without copying the content into the application itself. I don't want the user to change these mappings as they are core to how the plugins works.

Anyone can give me hints where to venture to achieve that.

Thank you

-ken

+1  A: 

Create another file in grails-app/config/ with a name ending in UrlMappings.groovy and put the customized mappings in there, for example myUrlMappings.groovy

Aaron Saunders
That's not what I want necessarily. There is not need for that to be in the application at all and my question is about informing the grails framework of such a mapping when the plugin is run. There is no need for the application to know about that.
ken
@ken the framework your are talking about "is" the application... your application will not be able to resolve a UrlMapping unless it is specified in the application.
Aaron Saunders
Aaron, Thank you but that's a given buddy. I already have my UrlMappings.groovy defined with everything i need but i don't want to expose that in the application i'm using. If i put the URLMappings.groovy in my plugin only, grails doesn't recognize it.
ken
A: 

Seems like i need to interface with UrlMappingsHolderFactoryBean directly to be able to do that. I was hoping that there might be an easier way to do that. The code below is taken from the UrlMappingPlugin itself, the only source that i found to help me solve my problem.

        if (application.isUrlMappingsClass(event.source)) {
        application.addArtefact(UrlMappingsArtefactHandler.TYPE, event.source)

        BeanBuilder beans = beans {
            grailsUrlMappingsHolderBean(UrlMappingsHolderFactoryBean) {
                grailsApplication = application
            }
        }

        ApplicationContext appCtx = event.ctx
        beans.registerBeans(appCtx)

        HotSwappableTargetSource ts = appCtx.getBean("urlMappingsTargetSource")
        ts.swap appCtx.getBean("grailsUrlMappingsHolderBean")
    }
ken