Search in sources :

Example 6 with ContentStoreService

use of org.craftercms.core.service.ContentStoreService in project engine by craftercms.

the class GroovyScriptFactoryTest method createContentStoreService.

private ContentStoreService createContentStoreService() {
    ContentStoreService storeService = mock(ContentStoreService.class);
    ContentStoreServiceMockUtils.setUpGetContentFromClassPath(storeService);
    return storeService;
}
Also used : ContentStoreService(org.craftercms.core.service.ContentStoreService)

Example 7 with ContentStoreService

use of org.craftercms.core.service.ContentStoreService 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;
}
Also used : SiteContext(org.craftercms.engine.service.context.SiteContext) Context(org.craftercms.core.service.Context) JobContext(org.craftercms.engine.util.quartz.JobContext) ServletContext(javax.servlet.ServletContext) ContentStoreService(org.craftercms.core.service.ContentStoreService) JobContext(org.craftercms.engine.util.quartz.JobContext)

Example 8 with ContentStoreService

use of org.craftercms.core.service.ContentStoreService in project engine by craftercms.

the class RestScriptsControllerTest method createContentStoreService.

private ContentStoreService createContentStoreService() {
    ContentStoreService storeService = mock(ContentStoreService.class);
    ContentStoreServiceMockUtils.setUpGetContentFromClassPath(storeService);
    return storeService;
}
Also used : ContentStoreService(org.craftercms.core.service.ContentStoreService)

Example 9 with ContentStoreService

use of org.craftercms.core.service.ContentStoreService in project engine by craftercms.

the class ScriptUrlTemplateScannerImpl method scan.

@Override
public List<UriTemplate> scan(SiteContext siteContext) {
    Context context = siteContext.getContext();
    ContentStoreService storeService = siteContext.getStoreService();
    ScriptFactory scriptFactory = siteContext.getScriptFactory();
    List<String> scriptUrls = new ArrayList<>();
    List<UriTemplate> urlTemplates = new ArrayList<>();
    findScripts(context, storeService, scriptFactory, scriptsFolder, scriptUrls);
    if (CollectionUtils.isNotEmpty(scriptUrls)) {
        for (String scriptUrl : scriptUrls) {
            Matcher matcher = urlVariablePlaceholderPattern.matcher(scriptUrl);
            if (matcher.find()) {
                urlTemplates.add(new UriTemplate(scriptUrl));
            }
        }
    }
    return urlTemplates;
}
Also used : SiteContext(org.craftercms.engine.service.context.SiteContext) Context(org.craftercms.core.service.Context) ContentStoreService(org.craftercms.core.service.ContentStoreService) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) UriTemplate(org.springframework.web.util.UriTemplate) ScriptFactory(org.craftercms.engine.scripting.ScriptFactory)

Example 10 with ContentStoreService

use of org.craftercms.core.service.ContentStoreService in project engine by craftercms.

the class ScriptFilter method getFilterMappings.

@SuppressWarnings("unchecked")
protected List<FilterMapping> getFilterMappings() {
    final SiteContext siteContext = SiteContext.getCurrent();
    if (siteContext != null) {
        Callback<List<FilterMapping>> callback = new Callback<List<FilterMapping>>() {

            @Override
            public List<FilterMapping> execute() {
                HierarchicalConfiguration config = ConfigUtils.getCurrentConfig();
                CachingAwareList<FilterMapping> mappings = new CachingAwareList<>();
                if (config != null) {
                    List<HierarchicalConfiguration> filtersConfig = config.configurationsAt(FILTER_KEY);
                    if (CollectionUtils.isNotEmpty(filtersConfig)) {
                        for (HierarchicalConfiguration filterConfig : filtersConfig) {
                            String scriptUrl = filterConfig.getString(SCRIPT_KEY);
                            String[] includes = filterConfig.getStringArray(INCLUDE_MAPPINGS_KEY);
                            String[] excludes = filterConfig.getStringArray(EXCLUDE_MAPPINGS_KEY);
                            if (StringUtils.isNotEmpty(scriptUrl) && ArrayUtils.isNotEmpty(includes)) {
                                ContentStoreService storeService = siteContext.getStoreService();
                                ScriptFactory scriptFactory = siteContext.getScriptFactory();
                                if (!storeService.exists(siteContext.getContext(), scriptUrl)) {
                                    throw new ConfigurationException("No filter script found at " + scriptUrl);
                                }
                                FilterMapping mapping = new FilterMapping();
                                mapping.script = scriptFactory.getScript(scriptUrl);
                                mapping.includes = includes;
                                mapping.excludes = excludes;
                                mappings.add(mapping);
                                mappings.addDependencyKey(mapping.script.getKey());
                            }
                        }
                    }
                }
                return mappings;
            }
        };
        return cacheTemplate.getObject(siteContext.getContext(), callback, FILTER_MAPPINGS_CACHE_KEY);
    } else {
        return null;
    }
}
Also used : ContentStoreService(org.craftercms.core.service.ContentStoreService) SiteContext(org.craftercms.engine.service.context.SiteContext) HierarchicalConfiguration(org.apache.commons.configuration2.HierarchicalConfiguration) Callback(org.craftercms.commons.lang.Callback) ConfigurationException(org.craftercms.engine.exception.ConfigurationException) ArrayList(java.util.ArrayList) CachingAwareList(org.craftercms.core.util.cache.impl.CachingAwareList) List(java.util.List) ScriptFactory(org.craftercms.engine.scripting.ScriptFactory) CachingAwareList(org.craftercms.core.util.cache.impl.CachingAwareList)

Aggregations

ContentStoreService (org.craftercms.core.service.ContentStoreService)10 SiteContext (org.craftercms.engine.service.context.SiteContext)4 Context (org.craftercms.core.service.Context)3 ArrayList (java.util.ArrayList)2 Item (org.craftercms.core.service.Item)2 ScriptFactory (org.craftercms.engine.scripting.ScriptFactory)2 UriTemplate (org.springframework.web.util.UriTemplate)2 List (java.util.List)1 Matcher (java.util.regex.Matcher)1 ServletContext (javax.servlet.ServletContext)1 HierarchicalConfiguration (org.apache.commons.configuration2.HierarchicalConfiguration)1 RequestContext (org.craftercms.commons.http.RequestContext)1 Callback (org.craftercms.commons.lang.Callback)1 CrafterException (org.craftercms.core.exception.CrafterException)1 CachingAwareList (org.craftercms.core.util.cache.impl.CachingAwareList)1 ConfigurationException (org.craftercms.engine.exception.ConfigurationException)1 JobContext (org.craftercms.engine.util.quartz.JobContext)1 Document (org.dom4j.Document)1