protected void doGet()

in core/src/main/java/org/apache/sling/cms/core/internal/servlets/PathSuggestionServlet.java [69:112]


    protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
            throws ServletException, IOException {
        String path = request.getParameter("path");

        if (StringUtils.isEmpty(path)) {
            path = "/";
        }
        if (log.isDebugEnabled()) {
            log.debug("Finding valid paths under {}", CommonUtils.escapeLogMessage(path));
        }
        
        String type = request.getParameter("type");
        if (!typeFilters.containsKey(type)) {
            type = "all";
        }
        if (log.isDebugEnabled()) {
            log.debug("Filtering by type: {}", CommonUtils.escapeLogMessage(type));
        }

        JsonArrayBuilder arrBuilder = Json.createArrayBuilder();
        Resource parent = request.getResourceResolver().getResource(path);

        if (parent == null) {
            path = StringUtils.left(path, path.lastIndexOf('/'));
            if (StringUtils.isEmpty(path)) {
                path = "/";
            }

            if (log.isDebugEnabled()) {
                log.debug("Using stemmed path {}", CommonUtils.escapeLogMessage(path));
            }
            parent = request.getResourceResolver().getResource(path);
        }
        if (parent != null) {
            for (Resource child : parent.getChildren()) {
                if (isIncluded(child, type)) {
                    arrBuilder.add(child.getPath());
                }
            }
        }

        response.setContentType("application/json");
        response.getWriter().write(arrBuilder.build().toString());
    }