use of org.craftercms.engine.scripting.Script in project engine by craftercms.
the class ScriptFilter method doFilter.
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
List<FilterMapping> filterMappings = getFilterMappings();
if (CollectionUtils.isNotEmpty(filterMappings)) {
HttpServletRequest httpRequest = (HttpServletRequest) request;
String requestUri = HttpUtils.getRequestUriWithoutContextPath(httpRequest);
List<Script> scripts = new ArrayList<>();
for (FilterMapping mapping : filterMappings) {
if (!excludeRequest(requestUri, mapping.excludes) && includeRequest(requestUri, mapping.includes)) {
scripts.add(mapping.script);
}
}
if (CollectionUtils.isNotEmpty(scripts)) {
chain = new ScriptFilterChainImpl(scripts.iterator(), chain, servletContext);
}
}
chain.doFilter(request, response);
}
use of org.craftercms.engine.scripting.Script in project engine by craftercms.
the class PageRenderController method handleRequestInternal.
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
String pageUrl;
SiteContext siteContext = SiteContext.getCurrent();
if (siteContext != null) {
if (siteContext.isFallback()) {
logger.warn("Rendering fallback page [" + fallbackPageUrl + "]");
pageUrl = fallbackPageUrl;
} else {
pageUrl = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
if (StringUtils.isEmpty(pageUrl)) {
throw new IllegalStateException("Required request attribute '" + HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE + "' is not set");
}
Script controllerScript = getControllerScript(siteContext, request, pageUrl);
if (controllerScript != null) {
Map<String, Object> model = new HashMap<>();
Map<String, Object> variables = createScriptVariables(request, response, model);
String viewName = executeScript(controllerScript, variables);
if (StringUtils.isNotEmpty(viewName)) {
if (logger.isDebugEnabled()) {
logger.debug("Rendering view " + viewName + " returned by script " + controllerScript);
}
return new ModelAndView(viewName, model);
} else {
return null;
}
}
if (logger.isDebugEnabled()) {
logger.debug("Rendering page [" + pageUrl + "]");
}
}
} else {
throw new IllegalStateException("No current site context found");
}
return new ModelAndView(pageUrl);
}
Aggregations