@Test public void testComponent() throws IOException, ServletException { context.currentResource("/content/apache/sling-apache-org/index/jcr:content/menu/richtext"); context.requestPathInfo().setExtension("html"); context.request().setAttribute(EditIncludeFilter.ENABLED_ATTR_NAME, "true"); includeFilter.doFilter(context.request(), context.response(), Mockito.mock(FilterChain.class)); assertEquals( "<div class=\"sling-cms-component\" data-reload=\"false\" data-component=\"/libs/sling-cms/components/general/richtext\" data-sling-cms-title=\"Rich Text Editor\" data-sling-cms-resource-path=\"/content/apache/sling-apache-org/index/jcr:content/menu/richtext\" data-sling-cms-resource-type=\"sling-cms/components/general/richtext\" data-sling-cms-edit=\"/libs/sling-cms/components/general/richtext/edit\" data-sling-cms-resource-name=\"richtext\">\n <div class=\"sling-cms-editor\" draggable=\"false\">\n <div class=\"level has-background-light\">\n <div class=\"level-left\">\n <div class=\"field has-addons\"><div class=\"control\">\n <a href=\"/cms/editor/edit.html/content/apache/sling-apache-org/index/jcr:content/menu/richtext?editor=/libs/sling-cms/components/general/richtext/edit\" class=\"level-item button is-small has-text-black-ter action-button\" title=\"Edit Rich Text Editor\">\n <span class=\"icon\">\n <span class=\"jam jam-pencil-f\">\n <span class=\"is-vhidden\">Edit Rich Text Editor</span>\n </span>\n </span>\n </a>\n</div><div class=\"control\">\n <a href=\"/cms/editor/delete.html/content/apache/sling-apache-org/index/jcr:content/menu/richtext\" class=\"level-item button is-small has-text-black-ter action-button\" title=\"Delete Component\">\n <span class=\"icon\">\n <span class=\"jam jam-trash\">\n <span class=\"is-vhidden\">Delete Rich Text Editor</span>\n </span>\n </span>\n </a>\n</div> </div> \n </div>\n <div class=\"level-right\">\n <div class=\"level-item has-text-black-ter\">Rich Text Editor</div>\n </div>\n </div>\n</div></div>", context.response().getOutputAsString()); }
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { boolean enabled = "true".equals(request.getAttribute(ENABLED_ATTR_NAME)); PrintWriter writer = null; if (enabled) { boolean includeEnd = false; SlingHttpServletRequest slingRequest = (SlingHttpServletRequest) request; Resource resource = slingRequest.getResource(); Boolean container = isContainer(resource); boolean writeDropTarget = shouldWriteDropTarget(slingRequest); writer = response.getWriter(); if (writeDropTarget) { this.writeDropTarget(resource, writer, "before " + resource.getName()); } includeEnd = writeHeader(slingRequest, writer, includeEnd); request.setAttribute(WRITE_DROP_TARGET_ATTR_NAME, container); chain.doFilter(request, response); request.setAttribute(WRITE_DROP_TARGET_ATTR_NAME, writeDropTarget); if (includeEnd) { writer.write("</div>"); } } else { chain.doFilter(request, response); } }
EditIncludeFilter implements Filter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { boolean enabled = "true".equals(request.getAttribute(ENABLED_ATTR_NAME)); PrintWriter writer = null; if (enabled) { boolean includeEnd = false; SlingHttpServletRequest slingRequest = (SlingHttpServletRequest) request; Resource resource = slingRequest.getResource(); Boolean container = isContainer(resource); boolean writeDropTarget = shouldWriteDropTarget(slingRequest); writer = response.getWriter(); if (writeDropTarget) { this.writeDropTarget(resource, writer, "before " + resource.getName()); } includeEnd = writeHeader(slingRequest, writer, includeEnd); request.setAttribute(WRITE_DROP_TARGET_ATTR_NAME, container); chain.doFilter(request, response); request.setAttribute(WRITE_DROP_TARGET_ATTR_NAME, writeDropTarget); if (includeEnd) { writer.write("</div>"); } } else { chain.doFilter(request, response); } } }
EditIncludeFilter implements Filter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { boolean enabled = "true".equals(request.getAttribute(ENABLED_ATTR_NAME)); PrintWriter writer = null; if (enabled) { boolean includeEnd = false; SlingHttpServletRequest slingRequest = (SlingHttpServletRequest) request; Resource resource = slingRequest.getResource(); Boolean container = isContainer(resource); boolean writeDropTarget = shouldWriteDropTarget(slingRequest); writer = response.getWriter(); if (writeDropTarget) { this.writeDropTarget(resource, writer, "before " + resource.getName()); } includeEnd = writeHeader(slingRequest, writer, includeEnd); request.setAttribute(WRITE_DROP_TARGET_ATTR_NAME, container); chain.doFilter(request, response); request.setAttribute(WRITE_DROP_TARGET_ATTR_NAME, writeDropTarget); if (includeEnd) { writer.write("</div>"); } } else { chain.doFilter(request, response); } }  }
EditIncludeFilter implements Filter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { boolean enabled = "true".equals(request.getAttribute(ENABLED_ATTR_NAME)); PrintWriter writer = null; if (enabled) { boolean includeEnd = false; SlingHttpServletRequest slingRequest = (SlingHttpServletRequest) request; Resource resource = slingRequest.getResource(); Boolean container = isContainer(resource); boolean writeDropTarget = shouldWriteDropTarget(slingRequest); writer = response.getWriter(); if (writeDropTarget) { this.writeDropTarget(resource, writer, "before " + resource.getName()); } includeEnd = writeHeader(slingRequest, writer, includeEnd); request.setAttribute(WRITE_DROP_TARGET_ATTR_NAME, container); chain.doFilter(request, response); request.setAttribute(WRITE_DROP_TARGET_ATTR_NAME, writeDropTarget); if (includeEnd) { writer.write("</div>"); } } else { chain.doFilter(request, response); } }  @Activate void activate(ComponentContext context); @Override void destroy(); @Override void doFilter(ServletRequest request, ServletResponse response, FilterChain chain); @Override void init(FilterConfig filterConfig); }
EditIncludeFilter implements Filter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { boolean enabled = "true".equals(request.getAttribute(ENABLED_ATTR_NAME)); PrintWriter writer = null; if (enabled) { boolean includeEnd = false; SlingHttpServletRequest slingRequest = (SlingHttpServletRequest) request; Resource resource = slingRequest.getResource(); Boolean container = isContainer(resource); boolean writeDropTarget = shouldWriteDropTarget(slingRequest); writer = response.getWriter(); if (writeDropTarget) { this.writeDropTarget(resource, writer, "before " + resource.getName()); } includeEnd = writeHeader(slingRequest, writer, includeEnd); request.setAttribute(WRITE_DROP_TARGET_ATTR_NAME, container); chain.doFilter(request, response); request.setAttribute(WRITE_DROP_TARGET_ATTR_NAME, writeDropTarget); if (includeEnd) { writer.write("</div>"); } } else { chain.doFilter(request, response); } }  @Activate void activate(ComponentContext context); @Override void destroy(); @Override void doFilter(ServletRequest request, ServletResponse response, FilterChain chain); @Override void init(FilterConfig filterConfig); static final String ENABLED_ATTR_NAME; static final String WRITE_DROP_TARGET_ATTR_NAME; }