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);
}
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());
}
Aggregations