use of org.apache.sling.scripting.sightly.SightlyException in project sling by apache.
the class ResourceRuntimeExtension method includeResource.
private void includeResource(final Bindings bindings, PrintWriter out, String path, String dispatcherOptions, String resourceType) {
if (StringUtils.isEmpty(path)) {
throw new SightlyException("Resource path cannot be empty");
} else {
SlingHttpServletRequest request = BindingsUtils.getRequest(bindings);
Resource includeRes = request.getResourceResolver().resolve(path);
if (ResourceUtil.isNonExistingResource(includeRes)) {
includeRes = new SyntheticResource(request.getResourceResolver(), path, resourceType);
}
includeResource(bindings, out, includeRes, dispatcherOptions, resourceType);
}
}
use of org.apache.sling.scripting.sightly.SightlyException in project sling by apache.
the class ResourceRuntimeExtension method includeResource.
private void includeResource(final Bindings bindings, PrintWriter out, Resource includeRes, String dispatcherOptions, String resourceType) {
if (includeRes == null) {
throw new SightlyException("Resource cannot be null");
} else {
SlingHttpServletResponse customResponse = new PrintWriterResponseWrapper(out, BindingsUtils.getResponse(bindings));
SlingHttpServletRequest request = BindingsUtils.getRequest(bindings);
RequestDispatcherOptions opts = new RequestDispatcherOptions(dispatcherOptions);
if (StringUtils.isNotEmpty(resourceType)) {
opts.setForceResourceType(resourceType);
}
RequestDispatcher dispatcher = request.getRequestDispatcher(includeRes, opts);
try {
if (dispatcher != null) {
dispatcher.include(request, customResponse);
} else {
throw new SightlyException("Failed to include resource " + includeRes.getPath());
}
} catch (Exception e) {
throw new SightlyException("Failed to include resource " + includeRes.getPath(), e);
}
}
}
Aggregations