public void moveFolder(Folder folder) throws PortalException, SystemException {

    if (!isStagingGroup(folder.getGroupId())) {
      dlSyncLocalService.updateSync(
          folder.getFolderId(),
          folder.getParentFolderId(),
          folder.getName(),
          folder.getDescription(),
          DLSyncConstants.EVENT_UPDATE,
          "-1");
    }
  }
  public void addFolder(Folder folder, ServiceContext serviceContext)
      throws PortalException, SystemException {

    if (!isStagingGroup(folder.getGroupId())) {
      dlSyncLocalService.addSync(
          folder.getFolderId(),
          folder.getUuid(),
          folder.getCompanyId(),
          folder.getRepositoryId(),
          folder.getParentFolderId(),
          folder.getName(),
          folder.getDescription(),
          DLSyncConstants.TYPE_FOLDER,
          "-1");
    }
  }
  public void deleteFolder(Folder folder) throws PortalException, SystemException {

    // Sync

    if (!isStagingGroup(folder.getGroupId())) {
      dlSyncLocalService.updateSync(
          folder.getFolderId(),
          folder.getParentFolderId(),
          folder.getName(),
          folder.getDescription(),
          DLSyncConstants.EVENT_DELETE,
          "-1");
    }

    // Trash

    if (folder.getModel() instanceof DLFolder) {
      trashEntryLocalService.deleteEntry(DLFolderConstants.getClassName(), folder.getFolderId());
    }
  }
  protected void copyFolder(
      Repository repository, Folder srcFolder, Folder destFolder, ServiceContext serviceContext)
      throws PortalException, SystemException {

    List<FileEntry> srcFileEntries =
        repository.getFileEntries(
            srcFolder.getFolderId(), QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);

    for (FileEntry srcFileEntry : srcFileEntries) {
      try {
        FileEntry fileEntry =
            repository.copyFileEntry(
                destFolder.getGroupId(),
                srcFileEntry.getFileEntryId(),
                destFolder.getFolderId(),
                serviceContext);

        DLProcessorRegistryUtil.trigger(fileEntry);
      } catch (Exception e) {
        _log.error(e, e);

        continue;
      }
    }

    List<Folder> srcSubfolders =
        repository.getFolders(
            srcFolder.getFolderId(), false, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);

    for (Folder srcSubfolder : srcSubfolders) {
      Folder destSubfolder =
          repository.addFolder(
              destFolder.getFolderId(),
              srcSubfolder.getName(),
              srcSubfolder.getDescription(),
              serviceContext);

      copyFolder(repository, srcSubfolder, destSubfolder, serviceContext);
    }
  }
  protected void sendDocumentLibrary(
      HttpServletRequest request,
      HttpServletResponse response,
      User user,
      String path,
      String[] pathArray)
      throws Exception {

    if (!PropsValues.WEB_SERVER_SERVLET_DIRECTORY_INDEXING_ENABLED) {
      response.setStatus(HttpServletResponse.SC_FORBIDDEN);

      return;
    }

    long groupId = _getGroupId(user.getCompanyId(), pathArray[0]);
    long folderId = DLFolderConstants.DEFAULT_PARENT_FOLDER_ID;

    for (int i = 1; i < pathArray.length; i++) {
      String name = pathArray[i];

      try {
        Folder folder = DLAppServiceUtil.getFolder(groupId, folderId, name);

        folderId = folder.getFolderId();
      } catch (NoSuchFolderException nsfe) {
        if (i != (pathArray.length - 1)) {
          throw nsfe;
        }

        String title = name;

        sendFile(response, user, groupId, folderId, title);

        return;
      }
    }

    try {
      sendFile(response, user, groupId, folderId, "index.html");

      return;
    } catch (Exception e) {
      if ((e instanceof NoSuchFileEntryException) || (e instanceof PrincipalException)) {

        try {
          sendFile(response, user, groupId, folderId, "index.htm");

          return;
        } catch (NoSuchFileEntryException nsfee) {
        } catch (PrincipalException pe) {
        }
      } else {
        throw e;
      }
    }

    List<WebServerEntry> webServerEntries = new ArrayList<WebServerEntry>();

    webServerEntries.add(new WebServerEntry(path, "../"));

    List<Folder> folders = DLAppServiceUtil.getFolders(groupId, folderId);

    for (Folder folder : folders) {
      WebServerEntry webServerEntry =
          new WebServerEntry(
              path,
              folder.getName() + StringPool.SLASH,
              folder.getCreateDate(),
              folder.getModifiedDate(),
              folder.getDescription(),
              0);

      webServerEntries.add(webServerEntry);
    }

    List<FileEntry> fileEntries = DLAppServiceUtil.getFileEntries(groupId, folderId);

    for (FileEntry fileEntry : fileEntries) {
      WebServerEntry webServerEntry =
          new WebServerEntry(
              path,
              fileEntry.getTitle(),
              fileEntry.getCreateDate(),
              fileEntry.getModifiedDate(),
              fileEntry.getDescription(),
              fileEntry.getSize());

      webServerEntries.add(webServerEntry);
    }

    sendHTML(response, path, webServerEntries);
  }