use of org.apache.sling.api.resource.ResourceResolver 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.resource.ResourceResolver 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.resource.ResourceResolver in project sling by apache.
the class FindResourcesTag method doEndTag.
/*
* (non-Javadoc)
*
* @see javax.servlet.jsp.tagext.TagSupport#doEndTag()
*/
@Override
public int doEndTag() {
log.trace("doEndTag");
log.debug("Finding resources using query: {} of language {}", query, language);
ResourceResolver resolver = getResourceResolver();
final Iterator<Resource> resources = resolver.findResources(query, language);
log.debug("Saving resources to variable {}", var);
pageContext.setAttribute(var, resources);
return EVAL_PAGE;
}
use of org.apache.sling.api.resource.ResourceResolver 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;
}
use of org.apache.sling.api.resource.ResourceResolver in project sling by apache.
the class TestAdaptObjectTag method init.
/**
* Initializes the fields for this test.
*/
@SuppressWarnings("serial")
@Before
public void init() {
log.info("init");
adaptToTag = new AdaptToTag() {
protected ClassLoader getClassLoader() {
return TestAdaptObjectTag.class.getClassLoader();
}
};
pageContext = new MockPageContext();
adaptToTag.setPageContext(pageContext);
ResourceResolver resolver = new MockResourceResolver();
resource = new MockResource(resolver, "/", "test");
log.info("init Complete");
}
Aggregations