use of org.apache.sling.api.scripting.SlingScriptHelper in project sling by apache.
the class AdaptToTag 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.SlingScriptHelper in project sling by apache.
the class DefineObjectsTag method doEndTag.
/**
* Creates Scripting variables for:
* <ul>
* <li><code>SlingHttpServletRequest</code>
* <li><code>SlingHttpServletResponse</code>
* <li>current <code>Resource</code>
* <li>current <code>Node</code> (if resource is adaptable to a node)
* <li>current <code>Logger</code>
* <li>current <code>SlingScriptHelper</code>
* </ul>
*
* @return always {@link #EVAL_PAGE}.
*/
public int doEndTag() {
final SlingBindings bindings = (SlingBindings) pageContext.getRequest().getAttribute(SlingBindings.class.getName());
final SlingScriptHelper scriptHelper = bindings.getSling();
pageContext.setAttribute(requestName, scriptHelper.getRequest());
pageContext.setAttribute(responseName, scriptHelper.getResponse());
final Resource resource = scriptHelper.getRequest().getResource();
pageContext.setAttribute(resourceName, resource);
pageContext.setAttribute(resourceResolverName, scriptHelper.getRequest().getResourceResolver());
pageContext.setAttribute(slingName, scriptHelper);
pageContext.setAttribute(logName, bindings.getLog());
pageContext.setAttribute(bindingsName, bindings);
if (JCR_NODE_CLASS != null) {
final Object node = resource.adaptTo(JCR_NODE_CLASS);
if (node != null) {
pageContext.setAttribute(nodeName, node);
}
}
return EVAL_PAGE;
}
use of org.apache.sling.api.scripting.SlingScriptHelper in project sling by apache.
the class EvalTagHandler method doEndTag.
/**
* Called after the body has been processed.
*
* @return whether additional evaluations of the body are desired
*/
public int doEndTag() throws JspException {
log.debug("EvalTagHandler doEndTag");
final SlingBindings bindings = (SlingBindings) pageContext.getRequest().getAttribute(SlingBindings.class.getName());
final SlingScriptHelper scriptHelper = bindings.getSling();
final ServletResolver servletResolver = scriptHelper.getService(ServletResolver.class);
final Servlet servlet;
if (!this.ignoreResourceTypeHierarchy) {
// detecte resource
final Resource resource;
if (this.resource != null) {
resource = this.resource;
} else if (this.resourceType != null) {
resource = new SyntheticResource(bindings.getRequest().getResourceResolver(), bindings.getResource().getPath(), this.resourceType);
} else {
resource = bindings.getResource();
}
servlet = servletResolver.resolveServlet(resource, this.script);
} else {
final ResourceResolver rr = 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 : rr.getSearchPath()) {
if (parentPath.startsWith(sp)) {
parentPath = parentPath.substring(sp.length());
break;
}
}
scriptPath = parentPath + '/' + script;
} else {
scriptPath = this.script;
}
servlet = servletResolver.resolveServlet(rr, scriptPath);
}
if (servlet == null) {
throw new JspException("Could not find script '" + script + "' referenced in jsp " + scriptHelper.getScript().getScriptResource().getPath());
}
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);
servlet.service(pageContext.getRequest(), response);
return EVAL_PAGE;
} catch (Exception e) {
log.error("Error while executing script " + script, e);
throw new JspException("Error while executing script " + script, e);
}
}
use of org.apache.sling.api.scripting.SlingScriptHelper in project sling by apache.
the class FindResourcesTag method getResourceResolver.
/**
* Method for retrieving the ResourceResolver from the page context.
*
* @return the resource resolver
*/
protected ResourceResolver getResourceResolver() {
final SlingBindings bindings = (SlingBindings) pageContext.getRequest().getAttribute(SlingBindings.class.getName());
final SlingScriptHelper scriptHelper = bindings.getSling();
final ResourceResolver resolver = scriptHelper.getRequest().getResourceResolver();
return resolver;
}
use of org.apache.sling.api.scripting.SlingScriptHelper in project sling by apache.
the class GetResourceTag method getResourceResolver.
/**
* Method for retrieving the ResourceResolver from the page context.
*
* @return the resource resolver
*/
protected ResourceResolver getResourceResolver() {
final SlingBindings bindings = (SlingBindings) pageContext.getRequest().getAttribute(SlingBindings.class.getName());
final SlingScriptHelper scriptHelper = bindings.getSling();
final ResourceResolver resolver = scriptHelper.getRequest().getResourceResolver();
return resolver;
}
Aggregations