예제 #1
0
  public static java.util.List<com.liferay.portal.kernel.repository.model.FileEntry> getFileEntries(
      long repositoryId, long folderId, long fileEntryTypeId) throws RemoteException {
    try {
      java.util.List<com.liferay.portal.kernel.repository.model.FileEntry> returnValue =
          DLAppServiceUtil.getFileEntries(repositoryId, folderId, fileEntryTypeId);

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

      throw new RemoteException(e.getMessage());
    }
  }
  private void _getFiles(CommandArgument commandArgument, Document document, Node rootNode)
      throws Exception {

    Element filesElement = document.createElement("Files");

    rootNode.appendChild(filesElement);

    if (Validator.isNull(commandArgument.getCurrentGroupName())) {
      return;
    }

    Group group = commandArgument.getCurrentGroup();

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

    List<FileEntry> fileEntries =
        DLAppServiceUtil.getFileEntries(group.getGroupId(), folder.getFolderId());

    for (FileEntry fileEntry : fileEntries) {
      Element fileElement = document.createElement("File");

      filesElement.appendChild(fileElement);

      fileElement.setAttribute("name", fileEntry.getTitle());
      fileElement.setAttribute("desc", fileEntry.getTitle());
      fileElement.setAttribute("size", getSize(fileEntry.getSize()));

      StringBundler url = new StringBundler(5);

      ThemeDisplay themeDisplay = commandArgument.getThemeDisplay();

      url.append(themeDisplay.getPathMain());
      url.append("/document_library/get_file?uuid=");
      url.append(fileEntry.getUuid());
      url.append("&groupId=");
      url.append(group.getGroupId());

      fileElement.setAttribute("url", url.toString());
    }
  }
  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);
  }