Search in sources :

Example 1 with GroovyPagesTemplateEngine

use of org.grails.gsp.GroovyPagesTemplateEngine in project grails-core by grails.

the class GroovyPagesServlet method initFrameworkServlet.

@Override
protected void initFrameworkServlet() throws ServletException, BeansException {
    context = getServletContext();
    context.log("GSP servlet initialized");
    context.setAttribute(SERVLET_INSTANCE, this);
    final WebApplicationContext webApplicationContext = getWebApplicationContext();
    grailsAttributes = GrailsFactoriesLoader.loadFactoriesWithArguments(GrailsApplicationAttributes.class, getClass().getClassLoader(), new Object[] { context }).get(0);
    webApplicationContext.getAutowireCapableBeanFactory().autowireBeanProperties(this, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false);
    groovyPagesTemplateEngine = webApplicationContext.getBean(GroovyPagesTemplateEngine.BEAN_ID, GroovyPagesTemplateEngine.class);
}
Also used : GroovyPagesTemplateEngine(org.grails.gsp.GroovyPagesTemplateEngine) WebApplicationContext(org.springframework.web.context.WebApplicationContext)

Example 2 with GroovyPagesTemplateEngine

use of org.grails.gsp.GroovyPagesTemplateEngine in project grails-core by grails.

the class GrailsLayoutDecoratorMapperTests method buildMockRequest.

private GrailsWebRequest buildMockRequest(Config config) throws Exception {
    MockApplicationContext appCtx = new MockApplicationContext();
    appCtx.registerMockBean(GroovyPagesUriService.BEAN_ID, new DefaultGroovyPagesUriService());
    DefaultGrailsApplication grailsApplication = new DefaultGrailsApplication();
    grailsApplication.setConfig(config);
    Holders.setConfig(config);
    appCtx.registerMockBean(GrailsApplication.APPLICATION_ID, grailsApplication);
    GrailsConventionGroovyPageLocator pageLocator = new GrailsConventionGroovyPageLocator();
    pageLocator.setApplicationContext(appCtx);
    GroovyPagesTemplateEngine gpte = new GroovyPagesTemplateEngine();
    gpte.setResourceLoader(appCtx);
    gpte.setApplicationContext(appCtx);
    gpte.afterPropertiesSet();
    GroovyPageViewResolver grailsViewResolver = new GroovyPageViewResolver();
    grailsViewResolver.setApplicationContext(appCtx);
    grailsViewResolver.setGroovyPageLocator(pageLocator);
    grailsViewResolver.setTemplateEngine(gpte);
    GroovyPageLayoutFinder layoutFinder = new GroovyPageLayoutFinder();
    layoutFinder.setViewResolver(grailsViewResolver);
    @SuppressWarnings("rawtypes") Map flat = config != null ? config.flatten() : Collections.emptyMap();
    layoutFinder.setDefaultDecoratorName(flat.get("grails.sitemesh.default.layout") != null ? flat.get("grails.sitemesh.default.layout").toString() : "application");
    appCtx.registerMockBean("groovyPageLocator", pageLocator);
    appCtx.registerMockBean("groovyPageLayoutFinder", layoutFinder);
    DefaultCodecLookup codecLookup = new DefaultCodecLookup();
    codecLookup.setGrailsApplication(grailsApplication);
    codecLookup.afterPropertiesSet();
    appCtx.registerMockBean("codecLookup", codecLookup);
    appCtx.getServletContext().setAttribute(GrailsApplicationAttributes.APPLICATION_CONTEXT, appCtx);
    appCtx.getServletContext().setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, appCtx);
    grailsApplication.setMainContext(appCtx);
    return GrailsWebMockUtil.bindMockWebRequest(appCtx, new MockHttpServletRequest(appCtx.getServletContext()) {

        @Override
        public RequestDispatcher getRequestDispatcher(String path) {
            return null;
        }
    }, new MockHttpServletResponse());
}
Also used : GrailsConventionGroovyPageLocator(org.grails.web.gsp.io.GrailsConventionGroovyPageLocator) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) DefaultGroovyPagesUriService(org.grails.web.pages.DefaultGroovyPagesUriService) DefaultGrailsApplication(grails.core.DefaultGrailsApplication) GroovyPagesTemplateEngine(org.grails.gsp.GroovyPagesTemplateEngine) RequestDispatcher(javax.servlet.RequestDispatcher) MockApplicationContext(org.grails.support.MockApplicationContext) DefaultCodecLookup(org.grails.plugins.codecs.DefaultCodecLookup) GroovyPageViewResolver(org.grails.web.servlet.view.GroovyPageViewResolver) Map(java.util.Map) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse)

Aggregations

GroovyPagesTemplateEngine (org.grails.gsp.GroovyPagesTemplateEngine)2 DefaultGrailsApplication (grails.core.DefaultGrailsApplication)1 Map (java.util.Map)1 RequestDispatcher (javax.servlet.RequestDispatcher)1 DefaultCodecLookup (org.grails.plugins.codecs.DefaultCodecLookup)1 MockApplicationContext (org.grails.support.MockApplicationContext)1 GrailsConventionGroovyPageLocator (org.grails.web.gsp.io.GrailsConventionGroovyPageLocator)1 DefaultGroovyPagesUriService (org.grails.web.pages.DefaultGroovyPagesUriService)1 GroovyPageViewResolver (org.grails.web.servlet.view.GroovyPageViewResolver)1 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)1 WebApplicationContext (org.springframework.web.context.WebApplicationContext)1