use of org.craftercms.engine.model.SiteItem in project engine by craftercms.
the class SiteItemScriptResolverImplTest method testGetScriptUrlError.
@Test
public void testGetScriptUrlError() throws Exception {
SiteItem siteItem = mock(SiteItem.class);
when(siteItem.queryValue("content-type")).thenReturn("/page/mypage3");
when(siteItem.queryValues("scripts/item/key")).thenReturn(Arrays.asList("/scripts/pages/script1.groovy"));
List<String> scriptUrls = scriptResolver.getScriptUrls(siteItem);
assertNotNull(scriptUrls);
assertEquals(1, scriptUrls.size());
assertEquals("/scripts/pages/script1.groovy", scriptUrls.get(0));
}
use of org.craftercms.engine.model.SiteItem in project engine by craftercms.
the class ExecuteControllerDirective method createScriptVariables.
protected Map<String, Object> createScriptVariables(Environment env) throws TemplateException {
Map<String, Object> variables = new HashMap<String, Object>();
RequestContext context = RequestContext.getCurrent();
SiteItem contentModel = getContentModel(env);
Object templateModel = getTemplateModel(env);
if (context != null) {
GroovyScriptUtils.addSiteItemScriptVariables(variables, context.getRequest(), context.getResponse(), servletContext, contentModel, templateModel);
} else {
throw new IllegalStateException("No current request context found");
}
return variables;
}
use of org.craftercms.engine.model.SiteItem in project engine by craftercms.
the class RenderComponentDirective method execute.
@SuppressWarnings("unchecked")
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException {
TemplateModel componentParentParam = (TemplateModel) params.get(COMPONENT_PARENT_PARAM_NAME);
TemplateModel componentParam = (TemplateModel) params.get(COMPONENT_PARAM_NAME);
TemplateModel componentPathParam = (TemplateModel) params.get(COMPONENT_PATH_PARAM_NAME);
TemplateModel additionalModelParam = (TemplateModel) params.get(ADDITIONAL_MODEL_PARAM_NAME);
Map<String, Object> additionalModel = null;
SiteItem component;
if (componentParam == null && componentPathParam == null) {
throw new TemplateException("No '" + COMPONENT_PARAM_NAME + "' or '" + COMPONENT_PATH_PARAM_NAME + "' param specified", env);
} else if (componentParam != null) {
component = getComponentFromNode(componentParentParam, componentParam, env);
} else {
component = getComponentFromPath(componentPathParam, env);
}
if (additionalModelParam != null) {
additionalModel = unwrap(ADDITIONAL_MODEL_PARAM_NAME, additionalModelParam, Map.class, env);
}
Map<String, Object> templateModel = executeScripts(component, additionalModel, env);
SimpleHash model = getFullModel(component, templateModel, additionalModel);
Template template = getTemplate(component, env);
Writer output = env.getOut();
processComponentTemplate(template, model, output, env);
}
use of org.craftercms.engine.model.SiteItem in project engine by craftercms.
the class SiteItemServiceImpl method getSiteItem.
@Override
public SiteItem getSiteItem(String url, ItemProcessor processor, Predicate<Item> predicate) {
SiteContext context = getSiteContext();
if (!storeService.exists(context.getContext(), url)) {
return null;
}
if (CollectionUtils.isNotEmpty(defaultPredicates)) {
List<Predicate<Item>> predicates = new ArrayList<>(defaultPredicates);
if (predicate != null) {
predicates.add(predicate);
}
predicate = PredicateUtils.allPredicate(predicates);
}
if (CollectionUtils.isNotEmpty(defaultProcessors)) {
ItemProcessorPipeline processorPipeline = new ItemProcessorPipeline(new ArrayList<>(defaultProcessors));
if (processor != null) {
processorPipeline.addProcessor(processor);
}
processor = processorPipeline;
}
Item item = storeService.findItem(context.getContext(), null, url, processor);
if (item != null && (predicate == null || predicate.evaluate(item))) {
return createItemWrapper(item);
} else {
return null;
}
}
Aggregations