protected FileEntry getFileEntry(String[] pathArray) throws Exception {
    if (pathArray.length == 1) {
      long dlFileShortcutId = GetterUtil.getLong(pathArray[0]);

      DLFileShortcut dlFileShortcut = DLAppServiceUtil.getFileShortcut(dlFileShortcutId);

      return DLAppServiceUtil.getFileEntry(dlFileShortcut.getToFileEntryId());
    } else if (pathArray.length == 2) {
      long groupId = GetterUtil.getLong(pathArray[0]);

      return DLAppServiceUtil.getFileEntryByUuidAndGroupId(pathArray[1], groupId);
    } else if (pathArray.length == 3) {
      long groupId = GetterUtil.getLong(pathArray[0]);
      long folderId = GetterUtil.getLong(pathArray[1]);

      String fileName = pathArray[2];

      if (fileName.contains(StringPool.QUESTION)) {
        fileName = fileName.substring(0, fileName.indexOf(StringPool.QUESTION));
      }

      return DLAppServiceUtil.getFileEntry(groupId, folderId, fileName);
    } else {
      long groupId = GetterUtil.getLong(pathArray[0]);

      String uuid = pathArray[3];

      return DLAppServiceUtil.getFileEntryByUuidAndGroupId(uuid, groupId);
    }
  }
  protected void trashFileEntry() throws Exception {
    Group group = ServiceTestUtil.addGroup();

    ServiceContext serviceContext = ServiceTestUtil.getServiceContext();

    serviceContext.setScopeGroupId(group.getGroupId());

    BaseModel<?> parentBaseModel = getParentBaseModel(group, serviceContext);

    int initialBaseModelsCount = getBaseModelsNotInTrashCount(parentBaseModel);
    int initialTrashEntriesCount = getTrashEntriesCount(group.getGroupId());

    BaseModel<?> baseModel = addBaseModel(parentBaseModel, true, serviceContext);

    DLFileShortcut dlFileShortcut = (DLFileShortcut) baseModel;

    FileEntry fileEntry = DLAppServiceUtil.getFileEntry(dlFileShortcut.getToFileEntryId());

    Assert.assertEquals(initialBaseModelsCount + 1, getBaseModelsNotInTrashCount(parentBaseModel));
    Assert.assertEquals(initialTrashEntriesCount, getTrashEntriesCount(group.getGroupId()));

    DLAppServiceUtil.moveFileEntryToTrash(fileEntry.getFileEntryId());

    Assert.assertEquals(initialBaseModelsCount, getBaseModelsNotInTrashCount(parentBaseModel));
    Assert.assertEquals(initialTrashEntriesCount + 1, getTrashEntriesCount(group.getGroupId()));

    DLAppServiceUtil.restoreFileEntryFromTrash(fileEntry.getFileEntryId());

    Assert.assertEquals(initialBaseModelsCount + 1, getBaseModelsNotInTrashCount(parentBaseModel));
  }
  protected void compareVersions(RenderRequest renderRequest) throws Exception {

    long fileEntryId = ParamUtil.getLong(renderRequest, "fileEntryId");

    String sourceVersion = ParamUtil.getString(renderRequest, "sourceVersion");
    String targetVersion = ParamUtil.getString(renderRequest, "targetVersion");

    FileEntry fileEntry = DLAppServiceUtil.getFileEntry(fileEntryId);

    String extension = fileEntry.getExtension();

    FileVersion sourceFileVersion = fileEntry.getFileVersion(sourceVersion);

    String sourceTitle = sourceFileVersion.getTitle();

    FileVersion targetFileVersion = fileEntry.getFileVersion(targetVersion);

    String targetTitle = targetFileVersion.getTitle();

    InputStream sourceIs = fileEntry.getContentStream(sourceVersion);
    InputStream targetIs = fileEntry.getContentStream(targetVersion);

    if (extension.equals("htm") || extension.equals("html") || extension.equals("xml")) {

      String escapedSource = HtmlUtil.escape(StringUtil.read(sourceIs));
      String escapedTarget = HtmlUtil.escape(StringUtil.read(targetIs));

      sourceIs = new UnsyncByteArrayInputStream(escapedSource.getBytes(StringPool.UTF8));
      targetIs = new UnsyncByteArrayInputStream(escapedTarget.getBytes(StringPool.UTF8));
    }

    if (DocumentConversionUtil.isEnabled()
        && DocumentConversionUtil.isConvertBeforeCompare(extension)) {

      String sourceTempFileId = DLUtil.getTempFileId(fileEntryId, sourceVersion);
      String targetTempFileId = DLUtil.getTempFileId(fileEntryId, targetVersion);

      sourceIs =
          new FileInputStream(
              DocumentConversionUtil.convert(sourceTempFileId, sourceIs, extension, "txt"));
      targetIs =
          new FileInputStream(
              DocumentConversionUtil.convert(targetTempFileId, targetIs, extension, "txt"));
    }

    List<DiffResult>[] diffResults =
        DiffUtil.diff(new InputStreamReader(sourceIs), new InputStreamReader(targetIs));

    renderRequest.setAttribute(WebKeys.SOURCE_NAME, sourceTitle + StringPool.SPACE + sourceVersion);
    renderRequest.setAttribute(WebKeys.TARGET_NAME, targetTitle + StringPool.SPACE + targetVersion);
    renderRequest.setAttribute(WebKeys.DIFF_RESULTS, diffResults);
  }
  protected void sendFile(
      HttpServletResponse response, User user, long groupId, long folderId, String title)
      throws Exception {

    FileEntry fileEntry = DLAppServiceUtil.getFileEntry(groupId, folderId, title);

    String contentType = fileEntry.getMimeType();

    response.setContentType(contentType);

    InputStream inputStream = fileEntry.getContentStream();

    ServletResponseUtil.write(response, inputStream);
  }
Пример #5
0
  public static String getFileEntryURL(String portalURL, long fileEntryId)
      throws PortalException, SystemException {

    FileEntry fileEntry = DLAppServiceUtil.getFileEntry(fileEntryId);

    StringBundler sb = new StringBundler(6);

    sb.append(portalURL);
    sb.append(PortalUtil.getPathContext());
    sb.append("/documents/");
    sb.append(fileEntry.getRepositoryId());
    sb.append(StringPool.SLASH);
    sb.append(fileEntry.getUuid());

    return sb.toString();
  }
Пример #6
0
  public static void getFileEntries(HttpServletRequest request) throws Exception {

    List<FileEntry> fileEntries = new ArrayList<FileEntry>();

    long[] fileEntryIds = StringUtil.split(ParamUtil.getString(request, "fileEntryIds"), 0L);

    for (long fileEntryId : fileEntryIds) {
      try {
        FileEntry fileEntry = DLAppServiceUtil.getFileEntry(fileEntryId);

        fileEntries.add(fileEntry);
      } catch (NoSuchFileEntryException nsfee) {
      }
    }

    request.setAttribute(WebKeys.DOCUMENT_LIBRARY_FILE_ENTRIES, fileEntries);
  }
Пример #7
0
  public static void getFileEntry(HttpServletRequest request) throws Exception {

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

    FileEntry fileEntry = null;

    if (fileEntryId > 0) {
      fileEntry = DLAppServiceUtil.getFileEntry(fileEntryId);
    }

    request.setAttribute(WebKeys.DOCUMENT_LIBRARY_FILE_ENTRY, fileEntry);

    String version = ParamUtil.getString(request, "version");

    if (fileEntry != null) {
      FileVersion fileVersion = null;

      if (Validator.isNotNull(version)) {
        fileVersion = fileEntry.getFileVersion(version);

        request.setAttribute(WebKeys.DOCUMENT_LIBRARY_FILE_VERSION, fileVersion);
      } else {
        fileVersion = fileEntry.getFileVersion();
      }

      RawMetadataProcessorUtil.generateMetadata(fileVersion);

      String cmd = ParamUtil.getString(request, Constants.CMD);

      if ((fileVersion.isInTrash() || fileVersion.isInTrashContainer())
          && !cmd.equals(Constants.MOVE_FROM_TRASH)) {

        throw new NoSuchFileEntryException();
      }
    }
  }
Пример #8
0
  @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();");
  }
Пример #9
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);
  }