use of org.apache.sling.api.resource.ResourceMetadata in project sling by apache.
the class StreamRendererServlet method processRequest.
private void processRequest(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
// whether this servlet is called as of a request include
final boolean included = request.getAttribute(SlingConstants.ATTR_REQUEST_SERVLET) != null;
// ensure no extension or "res"
String ext = request.getRequestPathInfo().getExtension();
if (ext != null && !ext.equals(EXT_RES)) {
request.getRequestProgressTracker().log("StreamRendererServlet does not support for extension " + ext);
if (included || response.isCommitted()) {
log.error("StreamRendererServlet does not support extension {}", ext);
} else {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
}
return;
}
Resource resource = request.getResource();
if (ResourceUtil.isNonExistingResource(resource)) {
throw new ResourceNotFoundException("No data to render.");
}
if ("/".equals(request.getRequestPathInfo().getSuffix())) {
renderDirectory(request, response, included);
return;
}
// check the last modification time and If-Modified-Since header
if (!included) {
ResourceMetadata meta = resource.getResourceMetadata();
long modifTime = meta.getModificationTime();
if (unmodified(request, modifTime)) {
response.setStatus(SC_NOT_MODIFIED);
return;
}
}
// fall back to plain text rendering if the resource has no stream
if (resource.getResourceType().equals(JcrConstants.NT_LINKEDFILE)) {
final ValueMap vm = resource.adaptTo(ValueMap.class);
final String actualResourcePath = vm.get(JcrConstants.JCR_CONTENT, String.class);
resource = request.getResourceResolver().getResource(actualResourcePath);
}
InputStream stream = resource.adaptTo(InputStream.class);
if (stream != null) {
if (isHeadRequest(request)) {
setContentLength(response, resource.getResourceMetadata().getContentLength());
setHeaders(resource, response);
return;
}
streamResource(resource, stream, included, request, response);
} else {
// the resource is the root, do not redirect, immediately index
if (isRootResourceRequest(resource)) {
renderDirectory(request, response, included);
} else if (included || response.isCommitted()) {
// request is included or committed, not redirecting
request.getRequestProgressTracker().log("StreamRendererServlet: Not redirecting with trailing slash, response is committed or request included");
log.warn("StreamRendererServlet: Not redirecting with trailing slash, response is committed or request included");
} else {
// redirect to this with trailing slash to render the index
String url = request.getResourceResolver().map(request, resource.getPath()) + "/";
response.sendRedirect(url);
}
}
}
use of org.apache.sling.api.resource.ResourceMetadata in project acs-aem-commons by Adobe-Consulting-Services.
the class RadioComponent method buildComponentResource.
@Override
public Resource buildComponentResource() {
AbstractResourceImpl component = (AbstractResourceImpl) super.buildComponentResource();
AbstractResourceImpl options = new AbstractResourceImpl("items", null, null, new ResourceMetadata());
component.addChild(options);
String defaultValue = getOption("default").orElse(null);
getOptions().forEach((value, name) -> {
final ResourceMetadata meta = new ResourceMetadata();
final String nodeName = JcrUtil.escapeIllegalJcrChars(value);
if (value.equals(defaultValue)) {
meta.put("checked", true);
}
meta.put("name", getName());
meta.put("value", value);
meta.put("text", name);
AbstractResourceImpl option = new AbstractResourceImpl("option_" + nodeName, "granite/ui/components/foundation/form/radio", "granite/ui/components/foundation/form/field", meta);
options.addChild(option);
});
return component;
}
use of org.apache.sling.api.resource.ResourceMetadata in project acs-aem-commons by Adobe-Consulting-Services.
the class FolderRelocatorTest method getEnhancedMockResolver.
private ResourceResolver getEnhancedMockResolver() throws RepositoryException, LoginException {
ResourceResolver rr = getFreshMockResolver();
when(rr.hasChanges()).thenReturn(true);
AbstractResourceImpl mockFolderA = new AbstractResourceImpl("/content/folderA", "", "", new ResourceMetadata());
when(rr.getResource("/content/folderA")).thenReturn(mockFolderA);
AbstractResourceImpl mockFolderB = new AbstractResourceImpl("/content/folderB", "", "", new ResourceMetadata());
when(rr.getResource("/content/folderB")).thenReturn(mockFolderB);
AbstractResourceImpl mockFolder = new AbstractResourceImpl("/content", "", "", new ResourceMetadata());
when(rr.getResource("/content")).thenReturn(mockFolder);
mockFolder.addChild(mockFolderA);
mockFolder.addChild(mockFolderB);
Session ses = mock(Session.class);
when(rr.adaptTo(Session.class)).thenReturn(ses);
AccessControlManager acm = mock(AccessControlManager.class);
when(ses.getAccessControlManager()).thenReturn(acm);
when(acm.privilegeFromName(any())).thenReturn(mock(Privilege.class));
return rr;
}
use of org.apache.sling.api.resource.ResourceMetadata in project acs-aem-commons by Adobe-Consulting-Services.
the class PageRelocatorTest method getEnhancedMockResolver.
private ResourceResolver getEnhancedMockResolver(final boolean aclChecksPass) throws RepositoryException, LoginException {
ResourceResolver rr = getFreshMockResolver();
when(rr.hasChanges()).thenReturn(true);
AbstractResourceImpl pageA = new AbstractResourceImpl("/content/pageA", "cq:Page", "cq:Page", new ResourceMetadata());
when(rr.getResource("/content/pageA")).thenReturn(pageA);
AbstractResourceImpl pageAcontent = new AbstractResourceImpl("/content/pageA/jcr:content", "cq:PageContent", "cq:PageContent", new ResourceMetadata());
when(rr.getResource("/content/pageA/jcr:content")).thenReturn(pageAcontent);
AbstractResourceImpl pageB = new AbstractResourceImpl("/content/pageB", "cq:Page", "cq:Page", new ResourceMetadata());
when(rr.getResource("/content/pageB")).thenReturn(pageB);
AbstractResourceImpl content = new AbstractResourceImpl("/content", "cq:Page", "cq:Page", new ResourceMetadata());
AbstractResourceImpl pageBcontent = new AbstractResourceImpl("/content/pageB/jcr:content", "cq:PageContent", "cq:PageContent", new ResourceMetadata());
when(rr.getResource("/content/pageB/jcr:content")).thenReturn(pageBcontent);
when(rr.getResource("/content")).thenReturn(content);
content.addChild(pageA);
content.addChild(pageB);
AbstractResourceImpl processes = new AbstractResourceImpl(ProcessInstanceImpl.BASE_PATH, null, null, new ResourceMetadata());
when(rr.getResource(ProcessInstanceImpl.BASE_PATH)).thenReturn(processes);
Session ses = mock(Session.class);
when(rr.adaptTo(Session.class)).thenReturn(ses);
AccessControlManager acm = mock(AccessControlManager.class);
when(ses.getAccessControlManager()).thenReturn(acm);
when(acm.privilegeFromName(any())).thenReturn(mock(Privilege.class));
when(acm.hasPrivileges(any(), any())).thenReturn(aclChecksPass);
return rr;
}
use of org.apache.sling.api.resource.ResourceMetadata in project acs-aem-commons by Adobe-Consulting-Services.
the class PageRelocatorTest method initInstance.
private void initInstance(ProcessInstance instance, ResourceResolver rr) throws RepositoryException, DeserializeException {
Map<String, Object> values = new HashMap<>();
values.put("sourcePath", "/content/pageA");
values.put("destinationPath", "/content/pageB");
values.put("maxReferences", "0");
values.put("mode", PageRelocator.Mode.MOVE.toString());
values.put("publishMethod", PageRelocator.PublishMethod.SELF_MANAGED.toString());
values.put("createVerionsOnReplicate", "false");
values.put("updateStatus", "true");
values.put("dryRun", "false");
instance.init(rr, values);
AbstractResourceImpl processNode = new AbstractResourceImpl(instance.getPath(), null, null, new ResourceMetadata());
when(rr.getResource(instance.getPath())).thenReturn(processNode);
AbstractResourceImpl processContentNode = new AbstractResourceImpl(instance.getPath() + "/jcr:content", null, null, new ResourceMetadata());
when(rr.getResource(instance.getPath() + "/jcr:content")).thenReturn(processContentNode);
AbstractResourceImpl processResultNode = new AbstractResourceImpl(instance.getPath() + "/jcr:content/result", null, null, new ResourceMetadata());
when(rr.getResource(instance.getPath() + "/jcr:content/result")).thenReturn(processResultNode);
AbstractResourceImpl failuresNode = new AbstractResourceImpl(instance.getPath() + "/jcr:content/failures", null, null, new ResourceMetadata());
when(rr.getResource(instance.getPath() + "/jcr:content/failures")).thenReturn(processResultNode);
when(rr.getResource(instance.getPath() + "/jcr:content/failures/step1")).thenReturn(processResultNode);
}
Aggregations