use of org.apache.sling.api.scripting.SlingBindings in project sling by apache.
the class CallTag method doEndTag.
@Override
public int doEndTag() throws JspException {
final SlingBindings bindings = (SlingBindings) pageContext.getRequest().getAttribute(SlingBindings.class.getName());
final SlingScriptHelper scriptHelper = bindings.getSling();
final ServletResolver servletResolver = scriptHelper.getService(ServletResolver.class);
final RequestProgressTracker tracker = TagUtil.getRequest(pageContext).getRequestProgressTracker();
String servletName = null;
final Servlet servlet;
if (!ignoreComponentHierarchy) {
final Resource resource = bindings.getResource();
servlet = servletResolver.resolveServlet(resource, this.script);
if (servlet != null) {
servletName = RequestUtil.getServletName(servlet);
tracker.log("Including script {0} for path={1}, type={2}: {3}", script, resource.getPath(), resource.getResourceType(), servletName);
}
} else {
final ResourceResolver resolver = bindings.getRequest().getResourceResolver();
final String scriptPath;
if (!script.startsWith("/")) {
// resolve relative script
String parentPath = ResourceUtil.getParent(scriptHelper.getScript().getScriptResource().getPath());
// check if parent resides on search path
for (String sp : resolver.getSearchPath()) {
if (parentPath.startsWith(sp)) {
parentPath = parentPath.substring(sp.length());
break;
}
}
scriptPath = parentPath + "/" + script;
} else {
scriptPath = this.script;
}
servlet = servletResolver.resolveServlet(resolver, scriptPath);
if (servlet != null) {
servletName = RequestUtil.getServletName(servlet);
tracker.log("Including script {0} (ignoring component hierarchy): {1}", script, servletName);
}
}
if (servlet == null) {
throw new JspException("Could not find script " + script);
}
try {
if (flush && !(pageContext.getOut() instanceof BodyContent)) {
// might throw an IOException of course
pageContext.getOut().flush();
}
// wrap the response to get the correct output order
SlingHttpServletResponse response = new JspSlingHttpServletResponseWrapper(pageContext);
tracker.startTimer(servletName);
servlet.service(pageContext.getRequest(), response);
tracker.logTimer(servletName);
return EVAL_PAGE;
} catch (Exception e) {
throw new JspException("Error while executing script " + script, e);
}
}
use of org.apache.sling.api.scripting.SlingBindings in project sling by apache.
the class GetPropertyTag method getClassLoader.
/**
* Method for retrieving the classloader from the OSGi console.
*
* @return the classloader
*/
protected ClassLoader getClassLoader() {
final SlingBindings bindings = (SlingBindings) pageContext.getRequest().getAttribute(SlingBindings.class.getName());
final SlingScriptHelper scriptHelper = bindings.getSling();
final DynamicClassLoaderManager dynamicClassLoaderManager = scriptHelper.getService(DynamicClassLoaderManager.class);
final ClassLoader classLoader = dynamicClassLoaderManager.getDynamicClassLoader();
return classLoader;
}
use of org.apache.sling.api.scripting.SlingBindings in project acs-aem-commons by Adobe-Consulting-Services.
the class IncludeDesignLibrariesTag method doEndTag.
/**
* {@inheritDoc}
*/
@Override
public int doEndTag() throws JspException {
final SlingHttpServletRequest request = TagUtil.getRequest(pageContext);
final SlingBindings bindings = (SlingBindings) request.getAttribute(SlingBindings.class.getName());
final DesignHtmlLibraryManager manager = bindings.getSling().getService(DesignHtmlLibraryManager.class);
if (manager != null) {
try {
if (js && css) {
manager.writeIncludes(request, getDesign(), region, pageContext.getOut());
} else if (js) {
manager.writeJsInclude(request, getDesign(), region, pageContext.getOut());
} else if (css) {
manager.writeCssInclude(request, getDesign(), region, pageContext.getOut());
}
} catch (IOException e) {
throw new JspException("Unable to write client library includes", e);
}
}
reset();
return EVAL_PAGE;
}
use of org.apache.sling.api.scripting.SlingBindings in project acs-aem-commons by Adobe-Consulting-Services.
the class DefineObjects method doEndTag.
@Override
public int doEndTag() {
SlingBindings bindings = (SlingBindings) this.pageContext.getRequest().getAttribute(SlingBindings.class.getName());
pageContext.setAttribute("globalProperties", bindings.get("globalProperties"));
pageContext.setAttribute("sharedProperties", bindings.get("sharedProperties"));
pageContext.setAttribute("mergedProperties", bindings.get("mergedProperties"));
return EVAL_PAGE;
}
use of org.apache.sling.api.scripting.SlingBindings in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class CarouselImplTest method getCarouselUnderTest.
private Carousel getCarouselUnderTest(@NotNull final String resourcePath) {
Utils.enableDataLayer(context, true);
context.currentResource(Objects.requireNonNull(context.resourceResolver().getResource(resourcePath)));
Component component = mock(Component.class);
when(component.getResourceType()).thenReturn(CarouselImpl.RESOURCE_TYPE);
MockSlingHttpServletRequest request = context.request();
SlingBindings slingBindings = (SlingBindings) request.getAttribute(SlingBindings.class.getName());
slingBindings.put(WCMBindings.COMPONENT, component);
request.setAttribute(SlingBindings.class.getName(), slingBindings);
return context.request().adaptTo(Carousel.class);
}
Aggregations