use of org.craftercms.engine.service.context.SiteContext in project engine by craftercms.
the class CircularQueueLogAppender method append.
@Override
@SuppressWarnings("unchecked")
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);
}
}
}
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 ScriptFilterTest method createSiteContext.
private SiteContext createSiteContext(ContentStoreService storeService) throws Exception {
SiteContext siteContext = mock(SiteContext.class);
ScriptFactory scriptFactory = createScriptFactory(siteContext);
XMLConfiguration config = ConfigUtils.readXmlConfiguration(new ClassPathResource("config/site-config.xml"), ',');
config.setListDelimiterHandler(new DefaultListDelimiterHandler(','));
when(siteContext.getSiteName()).thenReturn("default");
when(siteContext.getContext()).thenReturn(mock(Context.class));
when(siteContext.getStoreService()).thenReturn(storeService);
when(siteContext.getConfig()).thenReturn(config);
when(siteContext.getScriptFactory()).thenReturn(scriptFactory);
return siteContext;
}
use of org.craftercms.engine.service.context.SiteContext in project engine by craftercms.
the class ConfigurationScriptJobResolver method getJobsUnderFolder.
protected List<JobContext> getJobsUnderFolder(SiteContext siteContext, HierarchicalConfiguration jobFolderConfig) {
List<JobContext> jobContexts = null;
String folderPath = jobFolderConfig.getString(PATH_KEY);
String cronExpression = jobFolderConfig.getString(CRON_EXPRESSION_KEY);
ContentStoreService storeService = siteContext.getStoreService();
Context context = siteContext.getContext();
if (StringUtils.isNotEmpty(folderPath) && StringUtils.isNotEmpty(cronExpression)) {
List<String> scriptPaths = ContentStoreUtils.findChildrenUrl(storeService, context, folderPath);
if (CollectionUtils.isNotEmpty(scriptPaths)) {
for (String scriptPath : scriptPaths) {
if (scriptPath.endsWith(scriptSuffix)) {
if (jobContexts == null) {
jobContexts = new ArrayList<>();
}
jobContexts.add(SchedulingUtils.createJobContext(siteContext, scriptPath, cronExpression, servletContext));
}
}
}
}
return jobContexts;
}
use of org.craftercms.engine.service.context.SiteContext in project engine by craftercms.
the class ConfigAwareUrlAccessRestrictionCheckingProcessor method getUrlRestrictions.
@Override
@SuppressWarnings("unchecked")
protected Map<String, Expression> getUrlRestrictions() {
Callback<Map<String, Expression>> callback = new Callback<Map<String, Expression>>() {
@Override
public Map<String, Expression> execute() {
HierarchicalConfiguration config = ConfigUtils.getCurrentConfig();
Map<String, Expression> customRestrictions = null;
if (config != null) {
List<HierarchicalConfiguration> restrictionsConfig = config.configurationsAt(URL_RESTRICTION_KEY);
if (CollectionUtils.isNotEmpty(restrictionsConfig)) {
customRestrictions = new LinkedHashMap<>(restrictionsConfig.size());
ExpressionParser parser = new SpelExpressionParser();
for (HierarchicalConfiguration restrictionConfig : restrictionsConfig) {
String url = restrictionConfig.getString(URL_RESTRICTION_URL_KEY);
String expression = restrictionConfig.getString(URL_RESTRICTION_EXPRESSION_KEY);
if (StringUtils.isNotEmpty(url) && StringUtils.isNotEmpty(expression)) {
try {
customRestrictions.put(url, parser.parseExpression(expression));
} catch (ParseException e) {
throw new ConfigurationException(expression + " is not a valid SpEL expression", e);
}
}
}
}
}
if (customRestrictions != null) {
return customRestrictions;
} else {
return urlRestrictions;
}
}
};
SiteContext siteContext = SiteContext.getCurrent();
if (siteContext != null) {
return cacheTemplate.getObject(siteContext.getContext(), callback, URL_RESTRICTIONS_CACHE_KEY);
} else {
return urlRestrictions;
}
}
Aggregations