@Test public void testDisabled() 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, "false"); includeFilter.doFilter(context.request(), context.response(), Mockito.mock(FilterChain.class)); assertEquals("", 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; }