@Test void testPageWithoutTemplate() { Page page = context.create().page("/content/mypage"); Resource resource = context.create().resource(page, "resource1"); context.currentResource(resource); assertFalse(isEditRestricted(WCMUtils.getComponentContext(context.request()))); EditableTemplateSupport model = AdaptTo.notNull(context.request(), EditableTemplateSupport.class); assertFalse(model.isEditRestricted()); }
public static boolean isEditRestricted(@NotNull ComponentContext wcmComponentContext) { Page page = wcmComponentContext.getPage(); if (page == null) { return false; } ResourceResolver resourceResolver = wcmComponentContext.getResource().getResourceResolver(); Template template = page.getTemplate(); if (template == null || isPageInTemplateDefinition(page) || !isEditableTemplate(template)) { return false; } String resourcePath = wcmComponentContext.getResource().getPath(); String templateStructurePath = template.getPath() + "/" + NN_EDITABLE_TEMPLATE_STRUCTURE + "/" + JCR_CONTENT; String resourcePathInStructure = null; if (StringUtils.startsWith(resourcePath, templateStructurePath + "/")) { resourcePathInStructure = resourcePath; } else { String relativePathInPage = StringUtils.substringAfter(resourcePath, page.getContentResource().getPath()); if (StringUtils.isNotEmpty(relativePathInPage)) { resourcePathInStructure = templateStructurePath + relativePathInPage; } } if (resourcePathInStructure == null) { return false; } Resource resourceInStructure = resourceResolver.getResource(resourcePathInStructure); if (resourceInStructure == null) { return false; } return !resourceInStructure.getValueMap().get(PN_EDITABLE, false); }
EditableTemplate { public static boolean isEditRestricted(@NotNull ComponentContext wcmComponentContext) { Page page = wcmComponentContext.getPage(); if (page == null) { return false; } ResourceResolver resourceResolver = wcmComponentContext.getResource().getResourceResolver(); Template template = page.getTemplate(); if (template == null || isPageInTemplateDefinition(page) || !isEditableTemplate(template)) { return false; } String resourcePath = wcmComponentContext.getResource().getPath(); String templateStructurePath = template.getPath() + "/" + NN_EDITABLE_TEMPLATE_STRUCTURE + "/" + JCR_CONTENT; String resourcePathInStructure = null; if (StringUtils.startsWith(resourcePath, templateStructurePath + "/")) { resourcePathInStructure = resourcePath; } else { String relativePathInPage = StringUtils.substringAfter(resourcePath, page.getContentResource().getPath()); if (StringUtils.isNotEmpty(relativePathInPage)) { resourcePathInStructure = templateStructurePath + relativePathInPage; } } if (resourcePathInStructure == null) { return false; } Resource resourceInStructure = resourceResolver.getResource(resourcePathInStructure); if (resourceInStructure == null) { return false; } return !resourceInStructure.getValueMap().get(PN_EDITABLE, false); } }
EditableTemplate { public static boolean isEditRestricted(@NotNull ComponentContext wcmComponentContext) { Page page = wcmComponentContext.getPage(); if (page == null) { return false; } ResourceResolver resourceResolver = wcmComponentContext.getResource().getResourceResolver(); Template template = page.getTemplate(); if (template == null || isPageInTemplateDefinition(page) || !isEditableTemplate(template)) { return false; } String resourcePath = wcmComponentContext.getResource().getPath(); String templateStructurePath = template.getPath() + "/" + NN_EDITABLE_TEMPLATE_STRUCTURE + "/" + JCR_CONTENT; String resourcePathInStructure = null; if (StringUtils.startsWith(resourcePath, templateStructurePath + "/")) { resourcePathInStructure = resourcePath; } else { String relativePathInPage = StringUtils.substringAfter(resourcePath, page.getContentResource().getPath()); if (StringUtils.isNotEmpty(relativePathInPage)) { resourcePathInStructure = templateStructurePath + relativePathInPage; } } if (resourcePathInStructure == null) { return false; } Resource resourceInStructure = resourceResolver.getResource(resourcePathInStructure); if (resourceInStructure == null) { return false; } return !resourceInStructure.getValueMap().get(PN_EDITABLE, false); } private  EditableTemplate(); }
EditableTemplate { public static boolean isEditRestricted(@NotNull ComponentContext wcmComponentContext) { Page page = wcmComponentContext.getPage(); if (page == null) { return false; } ResourceResolver resourceResolver = wcmComponentContext.getResource().getResourceResolver(); Template template = page.getTemplate(); if (template == null || isPageInTemplateDefinition(page) || !isEditableTemplate(template)) { return false; } String resourcePath = wcmComponentContext.getResource().getPath(); String templateStructurePath = template.getPath() + "/" + NN_EDITABLE_TEMPLATE_STRUCTURE + "/" + JCR_CONTENT; String resourcePathInStructure = null; if (StringUtils.startsWith(resourcePath, templateStructurePath + "/")) { resourcePathInStructure = resourcePath; } else { String relativePathInPage = StringUtils.substringAfter(resourcePath, page.getContentResource().getPath()); if (StringUtils.isNotEmpty(relativePathInPage)) { resourcePathInStructure = templateStructurePath + relativePathInPage; } } if (resourcePathInStructure == null) { return false; } Resource resourceInStructure = resourceResolver.getResource(resourcePathInStructure); if (resourceInStructure == null) { return false; } return !resourceInStructure.getValueMap().get(PN_EDITABLE, false); } private  EditableTemplate(); static boolean isEditRestricted(@NotNull ComponentContext wcmComponentContext); }
EditableTemplate { public static boolean isEditRestricted(@NotNull ComponentContext wcmComponentContext) { Page page = wcmComponentContext.getPage(); if (page == null) { return false; } ResourceResolver resourceResolver = wcmComponentContext.getResource().getResourceResolver(); Template template = page.getTemplate(); if (template == null || isPageInTemplateDefinition(page) || !isEditableTemplate(template)) { return false; } String resourcePath = wcmComponentContext.getResource().getPath(); String templateStructurePath = template.getPath() + "/" + NN_EDITABLE_TEMPLATE_STRUCTURE + "/" + JCR_CONTENT; String resourcePathInStructure = null; if (StringUtils.startsWith(resourcePath, templateStructurePath + "/")) { resourcePathInStructure = resourcePath; } else { String relativePathInPage = StringUtils.substringAfter(resourcePath, page.getContentResource().getPath()); if (StringUtils.isNotEmpty(relativePathInPage)) { resourcePathInStructure = templateStructurePath + relativePathInPage; } } if (resourcePathInStructure == null) { return false; } Resource resourceInStructure = resourceResolver.getResource(resourcePathInStructure); if (resourceInStructure == null) { return false; } return !resourceInStructure.getValueMap().get(PN_EDITABLE, false); } private  EditableTemplate(); static boolean isEditRestricted(@NotNull ComponentContext wcmComponentContext);  }