use of org.craftercms.engine.service.context.SiteContext in project engine by craftercms.
the class ExecuteControllerDirective method executeController.
protected void executeController(String path, Environment env) throws TemplateException {
Map<String, Object> scriptVariables = createScriptVariables(env);
SiteContext siteContext = SiteContext.getCurrent();
if (siteContext != null) {
ScriptFactory scriptFactory = siteContext.getScriptFactory();
if (scriptFactory == null) {
throw new IllegalStateException("No script factory associate to current site context '" + siteContext.getSiteName() + "'");
}
Script script;
try {
script = scriptFactory.getScript(path);
} catch (Exception e) {
throw new TemplateException("Unable to load controller at '" + path + "'", e, env);
}
executeController(script, scriptVariables, env);
} else {
throw new IllegalStateException("No current site context found");
}
}
use of org.craftercms.engine.service.context.SiteContext in project engine by craftercms.
the class GroovyScriptUtils method addSiteConfigVariable.
private static void addSiteConfigVariable(Map<String, Object> variables) {
SiteContext siteContext = SiteContext.getCurrent();
Configuration config = null;
if (siteContext != null) {
config = siteContext.getConfig();
}
variables.put(VARIABLE_SITE_CONFIG, config);
}
use of org.craftercms.engine.service.context.SiteContext in project engine by craftercms.
the class GroovyScriptUtils method addJobScriptVariables.
public static void addJobScriptVariables(Map<String, Object> variables, ServletContext servletContext) {
SiteContext siteContext = SiteContext.getCurrent();
if (siteContext != null && siteContext.getApplicationContext() != null) {
ApplicationContextAccessor appContext = new ApplicationContextAccessor();
appContext.setApplicationContext(siteContext.getApplicationContext());
variables.put(VARIABLE_APPLICATION_CONTEXT, appContext);
}
variables.put(VARIABLE_APPLICATION, servletContext);
variables.put(VARIABLE_LOGGER, GROOVY_SCRIPT_LOGGER);
addSiteContextVariable(variables);
addSiteConfigVariable(variables);
}
use of org.craftercms.engine.service.context.SiteContext in project engine by craftercms.
the class RejectIndexFilesItemFilterTest method setUpCurrentConfig.
private void setUpCurrentConfig() {
XMLConfiguration config = mock(XMLConfiguration.class);
when(config.getString(INDEX_FILE_NAME_CONFIG_KEY, DEFAULT_INDEX_FILE_NAME)).thenReturn(DEFAULT_INDEX_FILE_NAME);
when(config.getBoolean(TARGETING_ENABLED_CONFIG_KEY, false)).thenReturn(true);
SiteContext siteContext = mock(SiteContext.class);
when(siteContext.getSiteName()).thenReturn("test");
when(siteContext.getConfig()).thenReturn(config);
SiteContext.setCurrent(siteContext);
}
use of org.craftercms.engine.service.context.SiteContext in project engine by craftercms.
the class CircularQueueLogAppender method append.
@Override
protected void append(final LoggingEvent event) {
final SiteContext ctx = SiteContext.getCurrent();
if (ctx != null) {
final String siteName = ctx.getSiteName();
if (StringUtils.isNoneBlank(siteName)) {
Map<String, Object> mappy = new HashMap<>();
mappy.put("site", siteName);
mappy.put("level", event.getLevel().toString());
mappy.put("message", event.getRenderedMessage());
mappy.put("thread", event.getThreadName());
mappy.put("exception", subAppend(event));
mappy.put("timestamp", dateFormat.format(new Date(event.getTimeStamp())));
mappy.put("timestampm", event.getTimeStamp());
buffer.add(mappy);
}
}
}
Aggregations