private void _getFolders(CommandArgument commandArgument, Document document, Node rootNode)
      throws Exception {

    Element foldersElement = document.createElement("Folders");

    rootNode.appendChild(foldersElement);

    if (commandArgument.getCurrentFolder().equals(StringPool.SLASH)) {
      getRootFolders(commandArgument, document, foldersElement);
    } else {
      Group group = commandArgument.getCurrentGroup();

      Folder folder = _getFolder(group.getGroupId(), commandArgument.getCurrentFolder());

      List<Folder> folders = DLAppServiceUtil.getFolders(group.getGroupId(), folder.getFolderId());

      for (Folder curFolder : folders) {
        Element folderElement = document.createElement("Folder");

        foldersElement.appendChild(folderElement);

        folderElement.setAttribute("name", curFolder.getName());
      }
    }
  }
  private Folder _getFolder(long groupId, String folderName) throws Exception {

    DLFolder dlFolder = new DLFolderImpl();

    dlFolder.setFolderId(DLFolderConstants.DEFAULT_PARENT_FOLDER_ID);
    dlFolder.setGroupId(groupId);

    Folder folder = new LiferayFolder(dlFolder);

    if (folderName.equals(StringPool.SLASH)) {
      return folder;
    }

    StringTokenizer st = new StringTokenizer(folderName, StringPool.SLASH);

    while (st.hasMoreTokens()) {
      String curFolderName = st.nextToken();

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

      for (Folder curFolder : folders) {
        if (curFolder.getName().equals(curFolderName)) {
          folder = curFolder;

          break;
        }
      }
    }

    return folder;
  }
Ejemplo n.º 3
0
  public static java.util.List<com.liferay.portal.kernel.repository.model.Folder> getFolders(
      long repositoryId, long parentFolderId, int start, int end) throws RemoteException {
    try {
      java.util.List<com.liferay.portal.kernel.repository.model.Folder> returnValue =
          DLAppServiceUtil.getFolders(repositoryId, parentFolderId, start, end);

      return returnValue;
    } catch (Exception e) {
      _log.error(e, e);

      throw new RemoteException(e.getMessage());
    }
  }
  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);
  }