protected FileEntry getTempImageFileEntry(PortletRequest portletRequest) throws PortalException {

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

    return TempFileEntryUtil.getTempFileEntry(
        themeDisplay.getScopeGroupId(), themeDisplay.getUserId(),
        getTempImageFolderName(), getTempImageFileName(portletRequest));
  }
Ejemplo n.º 2
0
  protected void addMultipleFileEntries(
      PortletConfig portletConfig,
      ActionRequest actionRequest,
      ActionResponse actionResponse,
      String selectedFileName,
      List<KeyValuePair> validFileNameKVPs,
      List<KeyValuePair> invalidFileNameKVPs)
      throws Exception {

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

    long nodeId = ParamUtil.getLong(actionRequest, "nodeId");
    String title = ParamUtil.getString(actionRequest, "title");

    FileEntry tempFileEntry = null;

    try {
      tempFileEntry =
          TempFileEntryUtil.getTempFileEntry(
              themeDisplay.getScopeGroupId(),
              themeDisplay.getUserId(),
              _TEMP_FOLDER_NAME,
              selectedFileName);

      String originalSelectedFileName =
          TempFileEntryUtil.getOriginalTempFileName(tempFileEntry.getFileName());
      InputStream inputStream = tempFileEntry.getContentStream();
      String mimeType = tempFileEntry.getMimeType();

      FileEntry fileEntry =
          _wikiPageService.addPageAttachment(
              nodeId, title, originalSelectedFileName, inputStream, mimeType);

      validFileNameKVPs.add(new KeyValuePair(fileEntry.getTitle(), selectedFileName));
    } catch (Exception e) {
      String errorMessage =
          getAddMultipleFileEntriesErrorMessage(portletConfig, actionRequest, actionResponse, e);

      invalidFileNameKVPs.add(new KeyValuePair(selectedFileName, errorMessage));
    } finally {
      if (tempFileEntry != null) {
        TempFileEntryUtil.deleteTempFileEntry(tempFileEntry.getFileEntryId());
      }
    }
  }
  protected void addMultipleFileEntries(
      PortletConfig portletConfig,
      ActionRequest actionRequest,
      ActionResponse actionResponse,
      String selectedFileName,
      List<KeyValuePair> validFileNameKVPs,
      List<KeyValuePair> invalidFileNameKVPs)
      throws Exception {

    String originalSelectedFileName = selectedFileName;

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

    long repositoryId = ParamUtil.getLong(actionRequest, "repositoryId");
    long folderId = ParamUtil.getLong(actionRequest, "folderId");
    String description = ParamUtil.getString(actionRequest, "description");
    String changeLog = ParamUtil.getString(actionRequest, "changeLog");

    FileEntry tempFileEntry = null;

    try {
      tempFileEntry =
          TempFileEntryUtil.getTempFileEntry(
              themeDisplay.getScopeGroupId(),
              themeDisplay.getUserId(),
              TEMP_FOLDER_NAME,
              selectedFileName);

      selectedFileName =
          DLUtil.getFileName(
              tempFileEntry.getGroupId(), tempFileEntry.getFolderId(), tempFileEntry.getFileName());

      String mimeType = tempFileEntry.getMimeType();

      InputStream inputStream = tempFileEntry.getContentStream();
      long size = tempFileEntry.getSize();

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

      _dlAppService.addFileEntry(
          repositoryId,
          folderId,
          selectedFileName,
          mimeType,
          selectedFileName,
          description,
          changeLog,
          inputStream,
          size,
          serviceContext);

      validFileNameKVPs.add(new KeyValuePair(selectedFileName, originalSelectedFileName));

      return;
    } catch (Exception e) {
      String errorMessage =
          getAddMultipleFileEntriesErrorMessage(portletConfig, actionRequest, actionResponse, e);

      invalidFileNameKVPs.add(new KeyValuePair(originalSelectedFileName, errorMessage));
    } finally {
      if (tempFileEntry != null) {
        TempFileEntryUtil.deleteTempFileEntry(tempFileEntry.getFileEntryId());
      }
    }
  }