@Override
  public boolean hasPermission(
      PermissionChecker permissionChecker,
      String entryClassName,
      long entryClassPK,
      String actionId)
      throws Exception {

    return DLFileEntryPermission.contains(permissionChecker, entryClassPK, ActionKeys.VIEW);
  }
  protected List<DocLibFileEntry> findViewableDocuments() {
    List<DocLibFileEntry> viewableDocuments = new ArrayList<DocLibFileEntry>();

    try {
      long folderGroupId = dlFolder.getGroupId();
      long folderId = dlFolder.getFolderId();

      List<DLFileEntry> dlFileEntries = null;

      if (DLFolderPermission.contains(
          permissionChecker, folderGroupId, folderId, ActionKeys.VIEW)) {
        OrderByComparator orderByComparator =
            DocumentComparatorFactory.getComparator(getSortColumn(), isSortAscending());

        dlFileEntries =
            DLFileEntryServiceUtil.getFileEntries(
                folderGroupId, folderId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, orderByComparator);
      }

      if (dlFileEntries != null) {

        for (DLFileEntry dlFileEntry : dlFileEntries) {
          boolean permittedToViewDocument = false;

          try {
            permittedToViewDocument =
                DLFileEntryPermission.contains(permissionChecker, dlFileEntry, ActionKeys.VIEW);
          } catch (Exception e) {
            logger.error(e.getMessage(), e);
          }

          viewableDocuments.add(
              new DocLibFileEntry(
                  dlFileEntry, portalURL, pathContext, folderGroupId, permittedToViewDocument));
        }
      }
    } catch (Exception e) {
      logger.error(e.getMessage(), e);
    }

    return viewableDocuments;
  }
  public boolean isShowImageEditorAction() throws PortalException {
    if (_isShowImageEditorAction != null) {
      return _isShowImageEditorAction;
    }

    if (!isShowActions()) {
      _isShowImageEditorAction = false;
    } else if (!DLFileEntryPermission.contains(
            _themeDisplay.getPermissionChecker(), _fileEntry, ActionKeys.UPDATE)
        || (_fileEntry.isCheckedOut() && !_fileEntry.hasLock())) {

      _isShowImageEditorAction = false;
    } else if (!ArrayUtil.contains(
        PropsValues.DL_FILE_ENTRY_PREVIEW_IMAGE_MIME_TYPES, _fileEntry.getMimeType())) {

      _isShowImageEditorAction = false;
    } else {
      _isShowImageEditorAction = true;
    }

    return _isShowImageEditorAction;
  }
  @Override
  public boolean hasPermission(PermissionChecker permissionChecker, long classPK, String actionId)
      throws Exception {

    return DLFileEntryPermission.contains(permissionChecker, classPK, actionId);
  }
  @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();");
  }
  @Override
  public boolean hasViewPermission(PermissionChecker permissionChecker) throws PortalException {

    return DLFileEntryPermission.contains(
        permissionChecker, _fileEntry.getFileEntryId(), ActionKeys.VIEW);
  }
  public boolean hasDeletePermission(PermissionChecker permissionChecker) throws PortalException {

    return DLFileEntryPermission.contains(
        permissionChecker, _fileEntry.getFileEntryId(), ActionKeys.DELETE);
  }
Exemple #8
0
  protected void getFile(
      long fileEntryId,
      long folderId,
      String name,
      String title,
      String version,
      long fileShortcutId,
      String uuid,
      long groupId,
      String targetExtension,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    if (name.startsWith("DLFE-")) {
      name = name.substring(5);
    }

    name = FileUtil.stripExtension(name);

    FileEntry fileEntry = null;

    if (Validator.isNotNull(uuid) && (groupId > 0)) {
      fileEntry = DLAppServiceUtil.getFileEntryByUuidAndGroupId(uuid, groupId);

      folderId = fileEntry.getFolderId();
    }

    if (fileEntryId > 0) {
      fileEntry = DLAppServiceUtil.getFileEntry(fileEntryId);
    } else if (fileShortcutId <= 0) {
      if (Validator.isNotNull(title)) {
        fileEntry = DLAppServiceUtil.getFileEntry(groupId, folderId, title);
      } else if (Validator.isNotNull(name)) {
        DLFileEntry dlFileEntry =
            DLFileEntryLocalServiceUtil.fetchFileEntryByName(groupId, folderId, name);

        if (dlFileEntry == null) {

          // LPS-30374

          List<DLFileEntry> dlFileEntries =
              DLFileEntryLocalServiceUtil.getFileEntries(folderId, name);

          if (!dlFileEntries.isEmpty()) {
            dlFileEntry = dlFileEntries.get(0);
          }
        }

        if (dlFileEntry != null) {
          ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

          PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();

          DLFileEntryPermission.check(permissionChecker, dlFileEntry, ActionKeys.VIEW);

          fileEntry = new LiferayFileEntry(dlFileEntry);
        }
      }
    } else {
      DLFileShortcut fileShortcut = DLAppServiceUtil.getFileShortcut(fileShortcutId);

      fileEntryId = fileShortcut.getToFileEntryId();

      fileEntry = DLAppServiceUtil.getFileEntry(fileEntryId);
    }

    if (Validator.isNull(version)) {
      if ((fileEntry != null) && Validator.isNotNull(fileEntry.getVersion())) {

        version = fileEntry.getVersion();
      } else {
        throw new NoSuchFileEntryException();
      }
    }

    FileVersion fileVersion = fileEntry.getFileVersion(version);

    InputStream is = fileVersion.getContentStream(true);
    String fileName = fileVersion.getTitle();
    long contentLength = fileVersion.getSize();
    String contentType = fileVersion.getMimeType();

    if (Validator.isNotNull(targetExtension)) {
      String id = DLUtil.getTempFileId(fileEntry.getFileEntryId(), version);

      String sourceExtension = fileVersion.getExtension();

      if (!fileName.endsWith(StringPool.PERIOD + sourceExtension)) {
        fileName += StringPool.PERIOD + sourceExtension;
      }

      File convertedFile = DocumentConversionUtil.convert(id, is, sourceExtension, targetExtension);

      if (convertedFile != null) {
        fileName =
            FileUtil.stripExtension(fileName).concat(StringPool.PERIOD).concat(targetExtension);
        is = new FileInputStream(convertedFile);
        contentLength = convertedFile.length();
        contentType = MimeTypesUtil.getContentType(fileName);
      }
    }

    ServletResponseUtil.sendFile(request, response, fileName, is, contentLength, contentType);
  }
  protected SocialActivityFeedEntry doInterpret(SocialActivity activity, ThemeDisplay themeDisplay)
      throws Exception {

    PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();

    DLFileEntry fileEntry = DLFileEntryLocalServiceUtil.getDLFileEntry(activity.getClassPK());

    if (!DLFileEntryPermission.contains(permissionChecker, fileEntry, ActionKeys.VIEW)) {

      return null;
    }

    String groupName = StringPool.BLANK;

    if (activity.getGroupId() != themeDisplay.getScopeGroupId()) {
      groupName = getGroupName(activity.getGroupId(), themeDisplay);
    }

    String creatorUserName = getUserName(activity.getUserId(), themeDisplay);

    int activityType = activity.getType();

    // Link

    String link =
        themeDisplay.getPortalURL()
            + themeDisplay.getPathMain()
            + "/document_library/get_file?groupId="
            + fileEntry.getGroupId()
            + "&folderId="
            + fileEntry.getFolderId()
            + "&name="
            + fileEntry.getName();

    // Title

    String titlePattern = null;

    if (activityType == DLActivityKeys.ADD_FILE_ENTRY) {
      titlePattern = "activity-document-library-add-file";
    } else if (activityType == DLActivityKeys.UPDATE_FILE_ENTRY) {
      titlePattern = "activity-document-library-update-file";
    }

    if (Validator.isNotNull(groupName)) {
      titlePattern += "-in";
    }

    String fileTitle = wrapLink(link, HtmlUtil.escape(cleanContent(fileEntry.getTitle())));

    Object[] titleArguments = new Object[] {groupName, creatorUserName, fileTitle};

    String title = themeDisplay.translate(titlePattern, titleArguments);

    // Body

    StringBundler sb = new StringBundler(3);

    String fileEntryLink =
        themeDisplay.getPortalURL()
            + themeDisplay.getPathMain()
            + "/document_library/find_file_entry?fileEntryId="
            + fileEntry.getFileEntryId();

    sb.append(wrapLink(fileEntryLink, "view-document", themeDisplay));
    sb.append(StringPool.SPACE);

    String folderLink =
        themeDisplay.getPortalURL()
            + themeDisplay.getPathMain()
            + "/document_library/find_folder?groupId="
            + fileEntry.getGroupId()
            + "&folderId="
            + fileEntry.getFolderId();

    sb.append(wrapLink(folderLink, "go-to-folder", themeDisplay));

    String body = sb.toString();

    return new SocialActivityFeedEntry(link, title, body);
  }