use of org.apache.sling.api.scripting.SlingBindings in project sling by apache.
the class SightlyCompiledScript method eval.
@Override
public Object eval(ScriptContext context) throws ScriptException {
Bindings bindings = context.getBindings(ScriptContext.ENGINE_SCOPE);
SlingBindings slingBindings = new SlingBindings();
slingBindings.putAll(bindings);
SlingHttpServletRequest request = slingBindings.getRequest();
if (request == null) {
throw new SightlyException("Missing SlingHttpServletRequest from ScriptContext.");
}
Object oldBindings = request.getAttribute(SlingBindings.class.getName());
try {
request.setAttribute(SlingBindings.class.getName(), slingBindings);
RenderContext renderContext = new RenderContextImpl(context);
PrintWriter out = new PrintWriter(context.getWriter());
renderUnit.render(out, renderContext, new SimpleBindings());
} finally {
request.setAttribute(SlingBindings.class.getName(), oldBindings);
}
return null;
}
use of org.apache.sling.api.scripting.SlingBindings in project sling by apache.
the class SlingContextImpl method request.
/**
* @return Sling request
*/
public final MockSlingHttpServletRequest request() {
if (this.request == null) {
this.request = new MockSlingHttpServletRequest(this.resourceResolver(), this.bundleContext());
// initialize sling bindings
SlingBindings bindings = new SlingBindings();
bindings.put(SlingBindings.REQUEST, this.request);
bindings.put(SlingBindings.RESPONSE, response());
bindings.put(SlingBindings.SLING, slingScriptHelper());
this.request.setAttribute(SlingBindings.class.getName(), bindings);
}
return this.request;
}
use of org.apache.sling.api.scripting.SlingBindings in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class HiddenImplTest method prepareHiddenFieldForTest.
private Field prepareHiddenFieldForTest(String resourcePath) {
MockSlingHttpServletRequest request = new MockSlingHttpServletRequest(CONTEXT.resourceResolver(), CONTEXT.bundleContext());
Resource resource = CONTEXT.resourceResolver().getResource(resourcePath);
request.setResource(resource);
Page currentPage = CONTEXT.pageManager().getPage(CONTAINING_PAGE);
SlingBindings slingBindings = new SlingBindings();
slingBindings.put(WCMBindings.CURRENT_PAGE, currentPage);
slingBindings.put(SlingBindings.RESOURCE, resource);
slingBindings.put(WCMBindings.PROPERTIES, resource.getValueMap());
request.setAttribute(SlingBindings.class.getName(), slingBindings);
return request.adaptTo(Field.class);
}
use of org.apache.sling.api.scripting.SlingBindings in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class BreadcrumbImplTest method setUp.
@Before
public void setUp() throws Exception {
Page page = context.currentPage(CURRENT_PAGE);
slingBindings = (SlingBindings) context.request().getAttribute(SlingBindings.class.getName());
slingBindings.put(WCMBindings.CURRENT_PAGE, page);
}
use of org.apache.sling.api.scripting.SlingBindings in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class TextImplTest method setUp.
@Before
public void setUp() {
Page page = context.currentPage(CONTAINING_PAGE);
slingBindings = (SlingBindings) context.request().getAttribute(SlingBindings.class.getName());
slingBindings.put(WCMBindings.CURRENT_PAGE, page);
context.registerService(FormStructureHelperFactory.class, new FormStructureHelperFactory() {
@Override
public FormStructureHelper getFormStructureHelper(Resource formElement) {
return null;
}
});
FormsHelperStubber.createStub();
}
Aggregations