@Override
  public String getPortletFileEntryURL(
      ThemeDisplay themeDisplay, FileEntry fileEntry, String queryString, boolean absoluteURL) {

    StringBundler sb = new StringBundler(10);

    if (themeDisplay != null) {
      if (absoluteURL) {
        sb.append(themeDisplay.getPortalURL());
      }
    }

    sb.append(PortalUtil.getPathContext());
    sb.append("/documents/");
    sb.append(WebServerServlet.PATH_PORTLET_FILE_ENTRY);
    sb.append(StringPool.SLASH);
    sb.append(fileEntry.getGroupId());
    sb.append(StringPool.SLASH);

    String title = fileEntry.getTitle();

    if (fileEntry.isInTrash()) {
      title = TrashUtil.getOriginalTitle(fileEntry.getTitle());
    }

    sb.append(HttpUtil.encodeURL(HtmlUtil.unescape(title)));

    sb.append(StringPool.SLASH);
    sb.append(HttpUtil.encodeURL(fileEntry.getUuid()));

    if (themeDisplay != null) {
      PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

      if (portletDisplay != null) {
        String portletId = portletDisplay.getId();

        if (portletId.equals(PortletKeys.TRASH) && !queryString.contains("status=")) {

          if (Validator.isNotNull(queryString)) {
            queryString += StringPool.AMPERSAND;
          }

          queryString += "status=" + WorkflowConstants.STATUS_IN_TRASH;
        }
      }
    }

    if (Validator.isNotNull(queryString)) {
      sb.append(StringPool.QUESTION);
      sb.append(queryString);
    }

    String portletFileEntryURL = sb.toString();

    if ((themeDisplay != null) && themeDisplay.isAddSessionIdToURL()) {
      return PortalUtil.getURLWithSessionId(portletFileEntryURL, themeDisplay.getSessionId());
    }

    return portletFileEntryURL;
  }
  private void _init(
      HttpServletRequest request, DLFileEntryType dlFileEntryType, FileEntry fileEntry)
      throws PortalException {

    _request = request;
    _dlFileEntryType = dlFileEntryType;
    _fileEntry = fileEntry;

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

    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

    _dlPortletInstanceSettings =
        DLPortletInstanceSettings.getInstance(themeDisplay.getLayout(), portletDisplay.getId());
    _fileEntryDisplayContextHelper =
        new FileEntryDisplayContextHelper(themeDisplay.getPermissionChecker(), _fileEntry);

    if ((_dlFileEntryType == null) && (_fileEntry != null)) {
      _dlFileEntryType = _fileEntryDisplayContextHelper.getDLFileEntryType();
    }

    if (fileEntry != null) {
      _fileVersion = fileEntry.getFileVersion();
    }

    _fileVersionDisplayContextHelper = new FileVersionDisplayContextHelper(_fileVersion);
  }
  protected String[] getAllowedFileExtensions(
      PortletConfig portletConfig, PortletRequest portletRequest, PortletResponse portletResponse)
      throws PortalException {

    String portletName = portletConfig.getPortletName();

    if (!portletName.equals(DLPortletKeys.MEDIA_GALLERY_DISPLAY)) {
      return PrefsPropsUtil.getStringArray(PropsKeys.DL_FILE_EXTENSIONS, StringPool.COMMA);
    } else {
      ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

      PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

      DLPortletInstanceSettings dlPortletInstanceSettings =
          DLPortletInstanceSettings.getInstance(themeDisplay.getLayout(), portletDisplay.getId());

      Set<String> extensions = new HashSet<>();

      String[] mimeTypes = dlPortletInstanceSettings.getMimeTypes();

      for (String mimeType : mimeTypes) {
        extensions.addAll(MimeTypesUtil.getExtensions(mimeType));
      }

      return extensions.toArray(new String[extensions.size()]);
    }
  }
 public void copyFrom(PortletDisplay master) {
   _access = master.isAccess();
   _active = master.isActive();
   _columnId = master.getColumnId();
   _content = master.getContent();
   _customCSSClassName = master.getCustomCSSClassName();
   _description = master.getDescription();
   _id = master.getId();
   _instanceId = master.getInstanceId();
   _modeAbout = master.isModeAbout();
   _modeConfig = master.isModeConfig();
   _modeEdit = master.isModeEdit();
   _modeEditDefaults = master.isModeEditDefaults();
   _modeEditGuest = master.isModeEditGuest();
   _modeHelp = master.isModeHelp();
   _modePreview = master.isModePreview();
   _modePrint = master.isModePrint();
   _namespace = master.getNamespace();
   _portletName = master.getPortletName();
   _portletSetup = master.getPortletSetup();
   _resourcePK = master.getResourcePK();
   _restoreCurrentView = master.isRestoreCurrentView();
   _rootPortletId = master.getRootPortletId();
   _showBackIcon = master.isShowBackIcon();
   _showCloseIcon = master.isShowCloseIcon();
   _showConfigurationIcon = master.isShowConfigurationIcon();
   _showEditDefaultsIcon = master.isShowEditDefaultsIcon();
   _showEditGuestIcon = master.isShowEditGuestIcon();
   _showEditIcon = master.isShowEditIcon();
   _showHelpIcon = master.isShowHelpIcon();
   _showMaxIcon = master.isShowMaxIcon();
   _showMinIcon = master.isShowMinIcon();
   _showMoveIcon = master.isShowMoveIcon();
   _showPortletCssIcon = master.isShowPortletCssIcon();
   _showPortletIcon = master.isShowPortletIcon();
   _showPrintIcon = master.isShowPrintIcon();
   _showRefreshIcon = master.isShowRefreshIcon();
   _stateExclusive = master.isStateExclusive();
   _stateMax = master.isStateMax();
   _stateMin = master.isStateMin();
   _stateNormal = master.isStateNormal();
   _statePopUp = master.isStatePopUp();
   _themeDisplay = master.getThemeDisplay();
   _title = master.getTitle();
   _urlBack = master.getURLBack();
   _urlClose = master.getURLClose();
   _urlConfiguration = master.getURLConfiguration();
   _urlEdit = master.getURLEdit();
   _urlEditDefaults = master.getURLEditDefaults();
   _urlExportImport = master.getURLExportImport();
   _urlHelp = master.getURLHelp();
   _urlMax = master.getURLMax();
   _urlMin = master.getURLMin();
   _urlPortlet = master.getURLPortlet();
   _urlPortletCss = master.getURLPortletCss();
   _urlPrint = master.getURLPrint();
   _urlRefresh = master.getURLRefresh();
   _webDAVEnabled = master.isWebDAVEnabled();
 }
  @Override
  public String getOnClick() {
    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

    StringBuilder sb = new StringBuilder(11);

    sb.append("Liferay.Portlet.openWindow('#p_p_id_");
    sb.append(portletDisplay.getId());
    sb.append("_', '");
    sb.append(portletDisplay.getId());
    sb.append("', '");
    sb.append(HtmlUtil.escapeJS(portletDisplay.getURLConfiguration()));
    sb.append("', '");
    sb.append(portletDisplay.getNamespace());
    sb.append("', '");
    sb.append(LanguageUtil.get(themeDisplay.getLocale(), "configuration"));
    sb.append("'); return false;");

    return sb.toString();
  }
  @Override
  public boolean isShow() {
    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

    PortletPreferences portletSetup =
        PortletPreferencesFactoryUtil.getStrictLayoutPortletSetup(
            themeDisplay.getLayout(), portletDisplay.getId());

    boolean lfrNetvibesShowAddAppLink =
        GetterUtil.getBoolean(portletSetup.getValue("lfrNetvibesShowAddAppLink", StringPool.BLANK));

    if (lfrNetvibesShowAddAppLink) {
      return true;
    }

    return false;
  }
  protected void addPortletTitleAddCategoryMenuItem(
      List<MenuItem> menuItems,
      long categoryId,
      ThemeDisplay themeDisplay,
      PortletRequest portletRequest)
      throws PortalException {

    if (!containsPermission(
        themeDisplay.getPermissionChecker(),
        themeDisplay.getScopeGroupId(),
        categoryId,
        ActionKeys.ADD_CATEGORY)) {

      return;
    }

    URLMenuItem urlMenuItem = new URLMenuItem();

    String key = "category[message-board]";

    if (categoryId != MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID) {
      key = "subcategory[message-board]";
    }

    urlMenuItem.setLabel(LanguageUtil.get(PortalUtil.getHttpServletRequest(portletRequest), key));

    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

    PortletURL portletURL =
        PortletURLFactoryUtil.create(
            portletRequest,
            portletDisplay.getId(),
            themeDisplay.getPlid(),
            PortletRequest.RENDER_PHASE);

    portletURL.setParameter("mvcRenderCommandName", "/message_boards/edit_category");
    portletURL.setParameter("redirect", PortalUtil.getCurrentURL(portletRequest));
    portletURL.setParameter("parentCategoryId", String.valueOf(categoryId));

    urlMenuItem.setURL(portletURL.toString());

    menuItems.add(urlMenuItem);
  }
  protected WikiPortletInstanceSettings getWikiPortletInstanceSettings(ActionRequest actionRequest)
      throws PortalException {

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

    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

    WikiWebSettingsProvider wikiWebSettingsProvider =
        WikiWebSettingsProvider.getWikiWebSettingsProvider();

    PortletInstanceSettingsProvider<WikiPortletInstanceSettings> portletIntanceSettingsProvider =
        wikiWebSettingsProvider.getPortletInstanceSettingsProvider();

    WikiPortletInstanceSettings wikiPortletInstanceSettings =
        portletIntanceSettingsProvider.getPortletInstanceSettings(
            themeDisplay.getLayout(), portletDisplay.getId());

    return wikiPortletInstanceSettings;
  }
  protected JSONArray getJSONArray(HttpServletRequest request) throws PortalException {

    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();

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

    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

    SocialInteractionsConfiguration socialInteractionsConfiguration =
        SocialInteractionsConfigurationUtil.getSocialInteractionsConfiguration(
            themeDisplay.getCompanyId(), portletDisplay.getId());

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

    List<User> users =
        MentionsUserFinderUtil.getUsers(
            themeDisplay.getCompanyId(),
            themeDisplay.getUserId(),
            query,
            socialInteractionsConfiguration);

    for (User user : users) {
      if (user.isDefaultUser() || (themeDisplay.getUserId() == user.getUserId())) {

        continue;
      }

      JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

      jsonObject.put("fullName", user.getFullName());
      jsonObject.put("portraitURL", user.getPortraitURL(themeDisplay));
      jsonObject.put("profileURL", user.getDisplayURL(themeDisplay));
      jsonObject.put("screenName", user.getScreenName());

      jsonArray.put(jsonObject);
    }

    return jsonArray;
  }
  protected void addPortletTitleAddMessageMenuItem(
      List<MenuItem> menuItems,
      long categoryId,
      ThemeDisplay themeDisplay,
      PortletRequest portletRequest)
      throws PortalException {

    if (!containsPermission(
        themeDisplay.getPermissionChecker(),
        themeDisplay.getScopeGroupId(),
        categoryId,
        ActionKeys.ADD_MESSAGE)) {

      return;
    }

    URLMenuItem urlMenuItem = new URLMenuItem();

    urlMenuItem.setLabel(
        LanguageUtil.get(PortalUtil.getHttpServletRequest(portletRequest), "thread"));

    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

    PortletURL portletURL =
        PortletURLFactoryUtil.create(
            portletRequest,
            portletDisplay.getId(),
            themeDisplay.getPlid(),
            PortletRequest.RENDER_PHASE);

    portletURL.setParameter("mvcRenderCommandName", "/message_boards/edit_message");
    portletURL.setParameter("redirect", PortalUtil.getCurrentURL(portletRequest));
    portletURL.setParameter("mbCategoryId", String.valueOf(categoryId));

    urlMenuItem.setURL(portletURL.toString());

    menuItems.add(urlMenuItem);
  }
  protected FileEntry updateFileEntry(
      PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest);

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

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

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

    long repositoryId = ParamUtil.getLong(uploadPortletRequest, "repositoryId");
    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");
    boolean majorVersion = ParamUtil.getBoolean(uploadPortletRequest, "majorVersion");

    if (folderId > 0) {
      Folder folder = _dlAppService.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 ((cmd.equals(Constants.ADD) || cmd.equals(Constants.ADD_DYNAMIC)) && (size == 0)) {

        contentType = MimeTypesUtil.getContentType(title);
      }

      if (cmd.equals(Constants.ADD) || cmd.equals(Constants.ADD_DYNAMIC) || (size > 0)) {

        String portletName = portletConfig.getPortletName();

        if (portletName.equals(DLPortletKeys.MEDIA_GALLERY_DISPLAY)) {
          PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

          DLPortletInstanceSettings dlPortletInstanceSettings =
              DLPortletInstanceSettings.getInstance(
                  themeDisplay.getLayout(), portletDisplay.getId());

          String[] mimeTypes = dlPortletInstanceSettings.getMimeTypes();

          if (Arrays.binarySearch(mimeTypes, contentType) < 0) {
            throw new FileMimeTypeException(contentType);
          }
        }
      }

      inputStream = uploadPortletRequest.getFileAsStream("file");

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

      FileEntry fileEntry = null;

      if (cmd.equals(Constants.ADD) || cmd.equals(Constants.ADD_DYNAMIC)) {

        // Add file entry

        fileEntry =
            _dlAppService.addFileEntry(
                repositoryId,
                folderId,
                sourceFileName,
                contentType,
                title,
                description,
                changeLog,
                inputStream,
                size,
                serviceContext);

        if (cmd.equals(Constants.ADD_DYNAMIC)) {
          JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

          jsonObject.put("fileEntryId", fileEntry.getFileEntryId());

          JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject);
        }
      } else if (cmd.equals(Constants.UPDATE_AND_CHECKIN)) {

        // Update file entry and checkin

        fileEntry =
            _dlAppService.updateFileEntryAndCheckIn(
                fileEntryId,
                sourceFileName,
                contentType,
                title,
                description,
                changeLog,
                majorVersion,
                inputStream,
                size,
                serviceContext);
      } else {

        // Update file entry

        fileEntry =
            _dlAppService.updateFileEntry(
                fileEntryId,
                sourceFileName,
                contentType,
                title,
                description,
                changeLog,
                majorVersion,
                inputStream,
                size,
                serviceContext);
      }

      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);
    }
  }
Beispiel #12
0
  public static PortletURL getAddPortletURL(
      LiferayPortletRequest liferayPortletRequest,
      LiferayPortletResponse liferayPortletResponse,
      long groupId,
      String className,
      long classTypeId,
      long[] allAssetCategoryIds,
      String[] allAssetTagNames,
      String redirect)
      throws Exception {

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

    AssetRendererFactory<?> assetRendererFactory =
        AssetRendererFactoryRegistryUtil.getAssetRendererFactoryByClassName(className);

    if ((assetRendererFactory == null)
        || !assetRendererFactory.hasAddPermission(
            themeDisplay.getPermissionChecker(), groupId, classTypeId)) {

      return null;
    }

    PortletURL addPortletURL =
        assetRendererFactory.getURLAdd(liferayPortletRequest, liferayPortletResponse, classTypeId);

    if (addPortletURL == null) {
      return null;
    }

    if (redirect != null) {
      addPortletURL.setParameter("redirect", redirect);
    }

    String referringPortletResource = ParamUtil.getString(liferayPortletRequest, "portletResource");

    if (Validator.isNotNull(referringPortletResource)) {
      addPortletURL.setParameter("referringPortletResource", referringPortletResource);
    } else {
      PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

      addPortletURL.setParameter("referringPortletResource", portletDisplay.getId());

      if (allAssetCategoryIds != null) {
        Map<Long, String> assetVocabularyAssetCategoryIds = new HashMap<>();

        for (long assetCategoryId : allAssetCategoryIds) {
          AssetCategory assetCategory =
              AssetCategoryLocalServiceUtil.fetchAssetCategory(assetCategoryId);

          if (assetCategory == null) {
            continue;
          }

          long assetVocabularyId = assetCategory.getVocabularyId();

          if (assetVocabularyAssetCategoryIds.containsKey(assetVocabularyId)) {

            String assetCategoryIds = assetVocabularyAssetCategoryIds.get(assetVocabularyId);

            assetVocabularyAssetCategoryIds.put(
                assetVocabularyId, assetCategoryIds + StringPool.COMMA + assetCategoryId);
          } else {
            assetVocabularyAssetCategoryIds.put(assetVocabularyId, String.valueOf(assetCategoryId));
          }
        }

        for (Map.Entry<Long, String> entry : assetVocabularyAssetCategoryIds.entrySet()) {

          long assetVocabularyId = entry.getKey();
          String assetCategoryIds = entry.getValue();

          addPortletURL.setParameter("assetCategoryIds_" + assetVocabularyId, assetCategoryIds);
        }
      }

      if (allAssetTagNames != null) {
        addPortletURL.setParameter("assetTagNames", StringUtil.merge(allAssetTagNames));
      }
    }

    addPortletURL.setPortletMode(PortletMode.VIEW);
    addPortletURL.setWindowState(LiferayWindowState.POP_UP);

    return addPortletURL;
  }
Beispiel #13
0
  @Override
  public String getPreviewURL(
      FileEntry fileEntry,
      FileVersion fileVersion,
      ThemeDisplay themeDisplay,
      String queryString,
      boolean appendVersion,
      boolean absoluteURL) {

    StringBundler sb = new StringBundler(17);

    if (themeDisplay != null) {
      if (absoluteURL) {
        sb.append(themeDisplay.getPortalURL());
      }
    }

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

    String title = fileEntry.getTitle();

    if (fileEntry.isInTrash()) {
      title = TrashUtil.getOriginalTitle(fileEntry.getTitle());
    }

    sb.append(HttpUtil.encodeURL(HtmlUtil.unescape(title)));

    sb.append(StringPool.SLASH);
    sb.append(fileEntry.getUuid());

    if (appendVersion) {
      sb.append("?version=");
      sb.append(fileVersion.getVersion());
    }

    if (ImageProcessorUtil.isImageSupported(fileVersion)) {
      if (appendVersion) {
        sb.append("&t=");
      } else {
        sb.append("?t=");
      }

      Date modifiedDate = fileVersion.getModifiedDate();

      sb.append(modifiedDate.getTime());
    }

    sb.append(queryString);

    if (themeDisplay != null) {
      PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

      if (portletDisplay != null) {
        String portletId = portletDisplay.getId();

        if (portletId.equals(PortletKeys.TRASH)) {
          sb.append("&status=");
          sb.append(WorkflowConstants.STATUS_IN_TRASH);
        }
      }
    }

    String previewURL = sb.toString();

    if ((themeDisplay != null) && themeDisplay.isAddSessionIdToURL()) {
      return PortalUtil.getURLWithSessionId(previewURL, themeDisplay.getSessionId());
    }

    return previewURL;
  }