public static Folder getGadgetEditorRootFolder(long repositoryId) throws Exception {

    Folder folder = null;

    try {
      folder =
          DLAppServiceUtil.getFolder(
              repositoryId,
              DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
              _GADGET_EDITOR_ROOT_FOLDER_NAME);
    } catch (Exception e) {
    }

    if (folder == null) {
      ServiceContext serviceContext = new ServiceContext();

      serviceContext.setAddGroupPermissions(true);
      serviceContext.setAddGuestPermissions(true);
      serviceContext.setScopeGroupId(repositoryId);

      folder =
          DLAppServiceUtil.addFolder(
              repositoryId,
              DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
              _GADGET_EDITOR_ROOT_FOLDER_NAME,
              StringPool.BLANK,
              serviceContext);
    }

    return folder;
  }
示例#2
0
  public static void getFolder(HttpServletRequest request) throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    long folderId = ParamUtil.getLong(request, "folderId");

    Folder folder = null;

    if ((folderId > 0) && (folderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID)) {

      folder = DLAppServiceUtil.getFolder(folderId);

      if (folder.getModel() instanceof DLFolder) {
        DLFolder dlFolder = (DLFolder) folder.getModel();

        if (dlFolder.isInTrash() || dlFolder.isInTrashContainer()) {
          throw new NoSuchFolderException();
        }
      }
    } else {
      DLPermission.check(
          themeDisplay.getPermissionChecker(), themeDisplay.getScopeGroupId(), ActionKeys.VIEW);
    }

    request.setAttribute(WebKeys.DOCUMENT_LIBRARY_FOLDER, folder);
  }
示例#3
0
  public static void getFolders(HttpServletRequest request) throws Exception {
    long[] folderIds = StringUtil.split(ParamUtil.getString(request, "folderIds"), 0L);

    List<Folder> folders = new ArrayList<Folder>();

    for (long folderId : folderIds) {
      try {
        Folder folder = DLAppServiceUtil.getFolder(folderId);

        folders.add(folder);
      } catch (NoSuchFolderException nsfee) {
      }
    }

    request.setAttribute(WebKeys.DOCUMENT_LIBRARY_FOLDERS, folders);
  }
  protected FileEntry addFileEntry(ActionRequest actionRequest) throws Exception {

    UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest);

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    long folderId = ParamUtil.getLong(uploadPortletRequest, "folderId");
    String sourceFileName = uploadPortletRequest.getFileName("file");
    String title = ParamUtil.getString(uploadPortletRequest, "title");
    String description = ParamUtil.getString(uploadPortletRequest, "description");
    String changeLog = ParamUtil.getString(uploadPortletRequest, "changeLog");

    if (folderId > 0) {
      Folder folder = DLAppServiceUtil.getFolder(folderId);

      if (folder.getGroupId() != themeDisplay.getScopeGroupId()) {
        throw new NoSuchFolderException("{folderId=" + folderId + "}");
      }
    }

    InputStream inputStream = null;

    try {
      String contentType = uploadPortletRequest.getContentType("file");

      long size = uploadPortletRequest.getSize("file");

      if (size == 0) {
        contentType = MimeTypesUtil.getContentType(title);
      }

      if (size > 0) {
        HttpServletRequest request = PortalUtil.getHttpServletRequest(actionRequest);

        String[] mimeTypes = DocumentSelectorUtil.getMimeTypes(request);

        if (ArrayUtil.isNotEmpty(mimeTypes) && !ArrayUtil.contains(mimeTypes, contentType)) {

          throw new FileMimeTypeException(contentType);
        }
      }

      inputStream = uploadPortletRequest.getFileAsStream("file");

      ServiceContext serviceContext =
          ServiceContextFactory.getInstance(DLFileEntry.class.getName(), uploadPortletRequest);

      FileEntry fileEntry =
          DLAppServiceUtil.addFileEntry(
              themeDisplay.getScopeGroupId(),
              folderId,
              sourceFileName,
              contentType,
              title,
              description,
              changeLog,
              inputStream,
              size,
              serviceContext);

      AssetPublisherUtil.addRecentFolderId(actionRequest, DLFileEntry.class.getName(), folderId);

      return fileEntry;
    } catch (Exception e) {
      UploadException uploadException =
          (UploadException) actionRequest.getAttribute(WebKeys.UPLOAD_EXCEPTION);

      if (uploadException != null) {
        if (uploadException.isExceededLiferayFileItemSizeLimit()) {
          throw new LiferayFileItemException();
        } else if (uploadException.isExceededSizeLimit()) {
          throw new FileSizeException(uploadException.getCause());
        }
      }

      throw e;
    } finally {
      StreamUtil.cleanUp(inputStream);
    }
  }
  @Override
  public String getRowCheckBox(boolean checked, boolean disabled, String primaryKey) {

    DLFileShortcut dlFileShortcut = null;
    FileEntry fileEntry = null;
    Folder folder = null;

    long entryId = GetterUtil.getLong(primaryKey);

    try {
      fileEntry = DLAppServiceUtil.getFileEntry(entryId);
    } catch (Exception e1) {
      if (e1 instanceof NoSuchFileEntryException || e1 instanceof NoSuchRepositoryEntryException) {

        try {
          dlFileShortcut = DLAppServiceUtil.getFileShortcut(entryId);
        } catch (Exception e2) {
          if (e2 instanceof NoSuchFileShortcutException) {
            try {
              folder = DLAppServiceUtil.getFolder(entryId);
            } catch (Exception e3) {
              return StringPool.BLANK;
            }
          } else {
            return StringPool.BLANK;
          }
        }
      } else {
        return StringPool.BLANK;
      }
    }

    boolean showInput = false;

    String name = null;

    if (fileEntry != null) {
      name = FileEntry.class.getSimpleName();

      try {
        if (DLFileEntryPermission.contains(_permissionChecker, fileEntry, ActionKeys.DELETE)
            || DLFileEntryPermission.contains(_permissionChecker, fileEntry, ActionKeys.UPDATE)) {

          showInput = true;
        }
      } catch (Exception e) {
      }
    } else if (dlFileShortcut != null) {
      name = DLFileShortcut.class.getSimpleName();

      try {
        if (DLFileShortcutPermission.contains(_permissionChecker, dlFileShortcut, ActionKeys.DELETE)
            || DLFileShortcutPermission.contains(
                _permissionChecker, dlFileShortcut, ActionKeys.UPDATE)) {

          showInput = true;
        }
      } catch (Exception e) {
      }
    } else if (folder != null) {
      name = Folder.class.getSimpleName();

      try {
        if (DLFolderPermission.contains(_permissionChecker, folder, ActionKeys.DELETE)
            || DLFolderPermission.contains(_permissionChecker, folder, ActionKeys.UPDATE)) {

          showInput = true;
        }
      } catch (Exception e) {
      }
    }

    if (!showInput) {
      return StringPool.BLANK;
    }

    StringBundler sb = new StringBundler();

    sb.append("['");
    sb.append(_liferayPortletResponse.getNamespace());
    sb.append(RowChecker.ROW_IDS);
    sb.append(Folder.class.getSimpleName());
    sb.append("Checkbox', '");
    sb.append(_liferayPortletResponse.getNamespace());
    sb.append(RowChecker.ROW_IDS);
    sb.append(DLFileShortcut.class.getSimpleName());
    sb.append("Checkbox', '");
    sb.append(_liferayPortletResponse.getNamespace());
    sb.append(RowChecker.ROW_IDS);
    sb.append(FileEntry.class.getSimpleName());
    sb.append("Checkbox']");

    String checkBoxRowIds = sb.toString();

    return getRowCheckBox(
        checked,
        disabled,
        _liferayPortletResponse.getNamespace() + RowChecker.ROW_IDS + name + "Checkbox",
        primaryKey,
        checkBoxRowIds,
        "'#" + getAllRowIds() + "Checkbox'",
        _liferayPortletResponse.getNamespace() + "toggleActionsButton();");
  }
  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);
  }