コード例 #1
0
  private boolean removeNode(String path) {

    Resource templateResource = resourceResolver.getResource(path);
    if (templateResource != null) {
      Node nodeToDelete = templateResource.adaptTo(Node.class);

      if (nodeToDelete != null) {
        try {
          nodeToDelete.remove();
          TemplateUtils.saveNode(nodeToDelete);
          session.save();
          return true;
        } catch (VersionException ex) {
          java.util.logging.Logger.getLogger(TemplateManagerDeleteServlet.class.getName())
              .log(Level.SEVERE, null, ex);
        } catch (LockException ex) {
          java.util.logging.Logger.getLogger(TemplateManagerDeleteServlet.class.getName())
              .log(Level.SEVERE, null, ex);
        } catch (ConstraintViolationException ex) {
          java.util.logging.Logger.getLogger(TemplateManagerDeleteServlet.class.getName())
              .log(Level.SEVERE, null, ex);
        } catch (AccessDeniedException ex) {
          java.util.logging.Logger.getLogger(TemplateManagerDeleteServlet.class.getName())
              .log(Level.SEVERE, null, ex);
        } catch (RepositoryException ex) {
          java.util.logging.Logger.getLogger(TemplateManagerDeleteServlet.class.getName())
              .log(Level.SEVERE, null, ex);
        } finally {
          session.logout();
        }
      }
    }
    return false;
  }
コード例 #2
0
  @Override
  protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
      throws ServletException, IOException {
    String path = TemplateUtils.getParameterValue("path", request);
    boolean success = false;

    if (path != null) {
      resourceResolver = request.getResourceResolver();
      session = resourceResolver.adaptTo(Session.class);
      success = removeNode(path);
    }

    response.getWriter().write("{\"success\":" + success + "}");
  }