protected SocialActivityFeedEntry doInterpret(SocialActivity activity, ThemeDisplay themeDisplay)
      throws Exception {

    PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();

    if (!CalEventPermission.contains(permissionChecker, activity.getClassPK(), 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

    CalEvent event = CalEventLocalServiceUtil.getEvent(activity.getClassPK());

    String link =
        themeDisplay.getPortalURL()
            + themeDisplay.getPathMain()
            + "/calendar/find_event?redirect="
            + themeDisplay.getURLCurrent()
            + "&eventId="
            + activity.getClassPK();

    // Title

    String titlePattern = null;

    if (activityType == CalendarActivityKeys.ADD_EVENT) {
      titlePattern = "activity-calendar-add-event";
    } else if (activityType == CalendarActivityKeys.UPDATE_EVENT) {
      titlePattern = "activity-calendar-update-event";
    }

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

    String eventTitle = wrapLink(link, HtmlUtil.escape(cleanContent(event.getTitle())));

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

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

    // Body

    String body = StringPool.BLANK;

    return new SocialActivityFeedEntry(link, title, body);
  }
Example #2
0
  @Override
  public String getAbsolutePath(PortletRequest portletRequest, long folderId)
      throws PortalException, SystemException {

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

    if (folderId == DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
      return themeDisplay.translate("home");
    }

    Folder folder = DLAppLocalServiceUtil.getFolder(folderId);

    List<Folder> folders = folder.getAncestors();

    Collections.reverse(folders);

    StringBundler sb = new StringBundler((folders.size() * 3) + 5);

    sb.append(themeDisplay.translate("home"));
    sb.append(StringPool.SPACE);

    for (Folder curFolder : folders) {
      sb.append(StringPool.RAQUO);
      sb.append(StringPool.SPACE);
      sb.append(curFolder.getName());
    }

    sb.append(StringPool.RAQUO);
    sb.append(StringPool.SPACE);
    sb.append(folder.getName());

    return sb.toString();
  }
Example #3
0
  public static String getAbsolutePath(PortletRequest portletRequest, long mbCategoryId)
      throws PortalException, SystemException {

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

    if (mbCategoryId == MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID) {
      return themeDisplay.translate("home");
    }

    MBCategory mbCategory = MBCategoryLocalServiceUtil.fetchMBCategory(mbCategoryId);

    List<MBCategory> categories = mbCategory.getAncestors();

    Collections.reverse(categories);

    StringBundler sb = new StringBundler((categories.size() * 3) + 5);

    sb.append(themeDisplay.translate("home"));
    sb.append(StringPool.SPACE);

    for (MBCategory curCategory : categories) {
      sb.append(StringPool.RAQUO);
      sb.append(StringPool.SPACE);
      sb.append(curCategory.getName());
    }

    sb.append(StringPool.RAQUO);
    sb.append(StringPool.SPACE);
    sb.append(mbCategory.getName());

    return sb.toString();
  }
  @Override
  public String getScopeDescriptiveName(ThemeDisplay themeDisplay)
      throws PortalException, SystemException {

    if (getGroupId() == themeDisplay.getScopeGroupId()) {
      StringBundler sb = new StringBundler(5);

      sb.append(themeDisplay.translate("current-site"));
      sb.append(StringPool.SPACE);
      sb.append(StringPool.OPEN_PARENTHESIS);
      sb.append(HtmlUtil.escape(getDescriptiveName(themeDisplay.getLocale())));
      sb.append(StringPool.CLOSE_PARENTHESIS);

      return sb.toString();
    } else if (isLayout() && (getClassPK() == themeDisplay.getPlid())) {
      StringBundler sb = new StringBundler(5);

      sb.append(themeDisplay.translate("current-page"));
      sb.append(StringPool.SPACE);
      sb.append(StringPool.OPEN_PARENTHESIS);
      sb.append(HtmlUtil.escape(getDescriptiveName(themeDisplay.getLocale())));
      sb.append(StringPool.CLOSE_PARENTHESIS);

      return sb.toString();
    } else if (isLayoutPrototype()) {
      return themeDisplay.translate("default");
    } else {
      return HtmlUtil.escape(getDescriptiveName(themeDisplay.getLocale()));
    }
  }
Example #5
0
  @Override
  public void addPortletBreadcrumbEntries(
      Folder folder, HttpServletRequest request, RenderResponse renderResponse) throws Exception {

    String strutsAction = ParamUtil.getString(request, "struts_action");

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

    PortletURL portletURL = renderResponse.createRenderURL();

    if (strutsAction.equals("/document_library/select_file_entry")
        || strutsAction.equals("/document_library/select_folder")
        || strutsAction.equals("/document_library_display/select_folder")
        || strutsAction.equals("/dynamic_data_mapping/select_document_library")
        || strutsAction.equals("/image_gallery_display/select_folder")) {

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

      portletURL.setParameter("struts_action", strutsAction);
      portletURL.setParameter("groupId", String.valueOf(groupId));
      portletURL.setWindowState(LiferayWindowState.POP_UP);

      PortalUtil.addPortletBreadcrumbEntry(
          request, themeDisplay.translate("home"), portletURL.toString());
    } else {
      portletURL.setParameter("struts_action", "/document_library/view");
    }

    addPortletBreadcrumbEntries(folder, request, portletURL);
  }
  protected void deleteTempFileEntry(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

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

    long folderId = ParamUtil.getLong(actionRequest, "folderId");
    String fileName = ParamUtil.getString(actionRequest, "fileName");

    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

    try {
      _dlAppService.deleteTempFileEntry(
          themeDisplay.getScopeGroupId(), folderId, TEMP_FOLDER_NAME, fileName);

      jsonObject.put("deleted", Boolean.TRUE);
    } catch (Exception e) {
      String errorMessage =
          themeDisplay.translate("an-unexpected-error-occurred-while-deleting-the-file");

      jsonObject.put("deleted", Boolean.FALSE);
      jsonObject.put("errorMessage", errorMessage);
    }

    JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject);
  }
  @Override
  public String getScopeDescriptiveName(ThemeDisplay themeDisplay) throws PortalException {

    if (getGroupId() == themeDisplay.getScopeGroupId()) {
      return StringUtil.appendParentheticalSuffix(
          themeDisplay.translate("current-site"),
          HtmlUtil.escape(getDescriptiveName(themeDisplay.getLocale())));
    } else if (isLayout() && (getClassPK() == themeDisplay.getPlid())) {
      return StringUtil.appendParentheticalSuffix(
          themeDisplay.translate("current-page"),
          HtmlUtil.escape(getDescriptiveName(themeDisplay.getLocale())));
    } else if (isLayoutPrototype()) {
      return themeDisplay.translate("default");
    } else {
      return HtmlUtil.escape(getDescriptiveName(themeDisplay.getLocale()));
    }
  }
  @Override
  protected SocialActivityFeedEntry doInterpret(SocialActivity activity, ThemeDisplay themeDisplay)
      throws Exception {

    PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();

    if (!WikiPagePermission.contains(permissionChecker, activity.getClassPK(), 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

    WikiPageResource pageResource =
        WikiPageResourceLocalServiceUtil.getPageResource(activity.getClassPK());

    String link =
        themeDisplay.getPortalURL()
            + themeDisplay.getPathMain()
            + "/wiki/find_page?pageResourcePrimKey="
            + activity.getClassPK();

    // Title

    String titlePattern = null;

    if (activityType == WikiActivityKeys.ADD_PAGE) {
      titlePattern = "activity-wiki-add-page";
    } else if (activityType == WikiActivityKeys.UPDATE_PAGE) {
      titlePattern = "activity-wiki-update-page";
    }

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

    String pageTitle = wrapLink(link, HtmlUtil.escape(cleanContent(pageResource.getTitle())));

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

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

    // Body

    String body = StringPool.BLANK;

    return new SocialActivityFeedEntry(link, title, body);
  }
  protected SocialActivityFeedEntry doInterpret(SocialActivity activity, ThemeDisplay themeDisplay)
      throws Exception {

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

    User receiverUser = UserLocalServiceUtil.getUserById(activity.getReceiverUserId());

    if (!SocialRelationLocalServiceUtil.hasRelation(
            themeDisplay.getUserId(),
            activity.getReceiverUserId(),
            SocialRelationConstants.TYPE_BI_FRIEND)
        && (themeDisplay.getUserId() != activity.getReceiverUserId())) {

      return null;
    }

    int activityType = activity.getType();

    // Link

    WallEntry wallEntry = WallEntryLocalServiceUtil.getWallEntry(activity.getClassPK());

    String link =
        themeDisplay.getPortalURL()
            + themeDisplay.getPathFriendlyURLPublic()
            + StringPool.SLASH
            + HtmlUtil.escapeURL(receiverUser.getScreenName())
            + "/profile/-/wall/"
            + activity.getClassPK();

    // Title

    String title = StringPool.BLANK;

    if (activityType == WallActivityKeys.ADD_ENTRY) {
      title =
          themeDisplay.translate(
              "activity-social-networking-wall-add-entry",
              new Object[] {creatorUserName, receiverUserName});
    }

    // Body

    StringBuilder sb = new StringBuilder();

    sb.append("<a href=\"");
    sb.append(link);
    sb.append("\">");
    sb.append(HtmlUtil.escape(cleanContent(wallEntry.getComments())));
    sb.append("</a>");

    String body = sb.toString();

    return new SocialActivityFeedEntry(link, title, body);
  }
  public static void addPortletBreadcrumbEntries(
      Folder folder, HttpServletRequest request, RenderResponse renderResponse) throws Exception {

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

    PortletURL portletURL = renderResponse.createRenderURL();

    if (mvcRenderCommandName.equals("/document_library/select_folder")) {
      ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

      portletURL.setParameter("mvcRenderCommandName", mvcRenderCommandName);
      portletURL.setWindowState(LiferayWindowState.POP_UP);

      PortalUtil.addPortletBreadcrumbEntry(
          request, themeDisplay.translate("home"), portletURL.toString());
    } else {
      portletURL.setParameter("mvcRenderCommandName", "/image_gallery_display/view");
    }

    long defaultFolderId = getDefaultFolderId(request);

    List<Folder> ancestorFolders = Collections.emptyList();

    if ((folder != null) && (folder.getFolderId() != defaultFolderId)) {
      ancestorFolders = folder.getAncestors();

      int indexOfRootFolder = -1;

      for (int i = 0; i < ancestorFolders.size(); i++) {
        Folder ancestorFolder = ancestorFolders.get(i);

        if (defaultFolderId == ancestorFolder.getFolderId()) {
          indexOfRootFolder = i;
        }
      }

      if (indexOfRootFolder > -1) {
        ancestorFolders = ancestorFolders.subList(0, indexOfRootFolder);
      }
    }

    Collections.reverse(ancestorFolders);

    for (Folder ancestorFolder : ancestorFolders) {
      portletURL.setParameter("folderId", String.valueOf(ancestorFolder.getFolderId()));

      PortalUtil.addPortletBreadcrumbEntry(
          request, ancestorFolder.getName(), portletURL.toString());
    }

    portletURL.setParameter("folderId", String.valueOf(folder.getFolderId()));

    PortalUtil.addPortletBreadcrumbEntry(request, folder.getName(), portletURL.toString());
  }
  @Override
  public String render(
      PortletConfig portletConfig, RenderRequest renderRequest, RenderResponse renderResponse)
      throws Exception {

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

    if (!_openId.isEnabled(themeDisplay.getCompanyId())) {
      return _forwards.get("portlet.login.login");
    }

    renderResponse.setTitle(themeDisplay.translate("open-id"));

    return _forwards.get("portlet.login.open_id");
  }
  @Override
  public ActionForward render(
      ActionMapping mapping,
      ActionForm form,
      PortletConfig portletConfig,
      RenderRequest renderRequest,
      RenderResponse renderResponse)
      throws Exception {

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

    String portletName = portletConfig.getPortletName();

    if (!portletName.equals(PortletKeys.FAST_LOGIN)) {
      return mapping.findForward("portlet.login.login");
    }

    renderResponse.setTitle(themeDisplay.translate("anonymous-account"));

    return mapping.findForward("portlet.login.create_anonymous_account");
  }
  public static void addPortletBreadcrumbEntries(
      Folder folder, HttpServletRequest request, LiferayPortletResponse liferayPortletResponse)
      throws Exception {

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

    PortletURL portletURL = liferayPortletResponse.createRenderURL();

    portletURL.setParameter("struts_action", "/document_library/view");
    portletURL.setParameter("viewEntries", Boolean.TRUE.toString());
    portletURL.setParameter("viewFolders", Boolean.TRUE.toString());

    Map<String, Object> data = new HashMap<String, Object>();

    data.put("folder-id", _getDefaultFolderId(request));

    PortalUtil.addPortletBreadcrumbEntry(
        request, themeDisplay.translate("home"), portletURL.toString(), data);

    addPortletBreadcrumbEntries(folder, request, portletURL);
  }
Example #14
0
  public static void addPortletBreadcrumbEntries(
      BookmarksFolder folder, HttpServletRequest request, RenderResponse renderResponse)
      throws Exception {

    String strutsAction = ParamUtil.getString(request, "struts_action");

    PortletURL portletURL = renderResponse.createRenderURL();

    if (strutsAction.equals("/bookmarks/select_folder")) {
      ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

      portletURL.setWindowState(LiferayWindowState.POP_UP);

      portletURL.setParameter("struts_action", "/bookmarks/select_folder");

      PortalUtil.addPortletBreadcrumbEntry(
          request, themeDisplay.translate("home"), portletURL.toString());
    } else {
      portletURL.setParameter("struts_action", "/bookmarks/view");
    }

    List<BookmarksFolder> ancestorFolders = folder.getAncestors();

    Collections.reverse(ancestorFolders);

    for (BookmarksFolder ancestorFolder : ancestorFolders) {
      portletURL.setParameter("folderId", String.valueOf(ancestorFolder.getFolderId()));

      PortalUtil.addPortletBreadcrumbEntry(
          request, ancestorFolder.getName(), portletURL.toString());
    }

    portletURL.setParameter("folderId", String.valueOf(folder.getFolderId()));

    if (folder.getFolderId() != BookmarksFolderConstants.DEFAULT_PARENT_FOLDER_ID) {

      PortalUtil.addPortletBreadcrumbEntry(request, folder.getName(), portletURL.toString());
    }
  }
Example #15
0
  public static void addPortletBreadcrumbEntries(
      MBCategory category, HttpServletRequest request, RenderResponse renderResponse)
      throws Exception {

    String strutsAction = ParamUtil.getString(request, "struts_action");

    boolean selectCategory = strutsAction.equals("/message_boards/select_category");

    PortletURL portletURL = renderResponse.createRenderURL();

    if (selectCategory) {
      ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

      portletURL.setWindowState(LiferayWindowState.POP_UP);

      portletURL.setParameter("struts_action", "/message_boards/select_category");

      PortalUtil.addPortletBreadcrumbEntry(
          request, themeDisplay.translate("categories"), portletURL.toString());
    } else {
      portletURL.setParameter("struts_action", "/message_boards/view");
      portletURL.setParameter("tabs1", "categories");
    }

    List<MBCategory> ancestorCategories = category.getAncestors();

    Collections.reverse(ancestorCategories);

    for (MBCategory curCategory : ancestorCategories) {
      portletURL.setParameter("mbCategoryId", String.valueOf(curCategory.getCategoryId()));

      PortalUtil.addPortletBreadcrumbEntry(request, curCategory.getName(), portletURL.toString());
    }

    portletURL.setParameter("mbCategoryId", String.valueOf(category.getCategoryId()));

    PortalUtil.addPortletBreadcrumbEntry(request, category.getName(), portletURL.toString());
  }
  public static void addPortletBreadcrumbEntries(
      Folder folder, HttpServletRequest request, RenderResponse renderResponse) throws Exception {

    String strutsAction = ParamUtil.getString(request, "struts_action");

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

    PortletURL portletURL = renderResponse.createRenderURL();

    if (strutsAction.equals("/journal/select_document_library")
        || strutsAction.equals("/document_library/select_file_entry")
        || strutsAction.equals("/document_library/select_folder")
        || strutsAction.equals("/document_library_display/select_folder")
        || strutsAction.equals("/image_gallery_display/select_folder")) {

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

      portletURL.setWindowState(LiferayWindowState.POP_UP);

      portletURL.setParameter("struts_action", strutsAction);
      portletURL.setParameter("groupId", String.valueOf(groupId));

      Map<String, Object> data = new HashMap<String, Object>();

      data.put("folder-id", _getDefaultFolderId(request));
      data.put("view-entries", Boolean.TRUE.toString());
      data.put("view-folders", Boolean.TRUE.toString());

      PortalUtil.addPortletBreadcrumbEntry(
          request, themeDisplay.translate("home"), portletURL.toString(), data);
    } else {
      portletURL.setParameter("struts_action", "/document_library/view");
    }

    addPortletBreadcrumbEntries(folder, request, portletURL);
  }
Example #17
0
  /** TODO: Remove. This should extend from EditFileEntryAction once it is modularized. */
  protected void handleUploadException(
      PortletConfig portletConfig,
      ActionRequest actionRequest,
      ActionResponse actionResponse,
      String cmd,
      Exception e)
      throws Exception {

    if (e instanceof AssetCategoryException || e instanceof AssetTagException) {

      SessionErrors.add(actionRequest, e.getClass(), e);
    } else if (e instanceof AntivirusScannerException
        || e instanceof DuplicateFileEntryException
        || e instanceof DuplicateFolderNameException
        || e instanceof FileExtensionException
        || e instanceof FileMimeTypeException
        || e instanceof FileNameException
        || e instanceof FileSizeException
        || e instanceof LiferayFileItemException
        || e instanceof NoSuchFolderException
        || e instanceof SourceFileNameException
        || e instanceof StorageFieldRequiredException) {

      if (!cmd.equals(Constants.ADD_DYNAMIC)
          && !cmd.equals(Constants.ADD_MULTIPLE)
          && !cmd.equals(Constants.ADD_TEMP)) {

        if (e instanceof AntivirusScannerException) {
          SessionErrors.add(actionRequest, e.getClass(), e);
        } else {
          SessionErrors.add(actionRequest, e.getClass());
        }

        return;
      } else if (cmd.equals(Constants.ADD_TEMP)) {
        hideDefaultErrorMessage(actionRequest);
      }

      if (e instanceof AntivirusScannerException
          || e instanceof DuplicateFileEntryException
          || e instanceof FileExtensionException
          || e instanceof FileNameException
          || e instanceof FileSizeException) {

        HttpServletResponse response = PortalUtil.getHttpServletResponse(actionResponse);

        response.setContentType(ContentTypes.TEXT_HTML);
        response.setStatus(HttpServletResponse.SC_OK);

        String errorMessage = StringPool.BLANK;
        int errorType = 0;

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

        if (e instanceof AntivirusScannerException) {
          AntivirusScannerException ase = (AntivirusScannerException) e;

          errorMessage = themeDisplay.translate(ase.getMessageKey());
          errorType = ServletResponseConstants.SC_FILE_ANTIVIRUS_EXCEPTION;
        }

        if (e instanceof DuplicateFileEntryException) {
          errorMessage = themeDisplay.translate("please-enter-a-unique-document-name");
          errorType = ServletResponseConstants.SC_DUPLICATE_FILE_EXCEPTION;
        } else if (e instanceof FileExtensionException) {
          errorMessage =
              themeDisplay.translate(
                  "please-enter-a-file-with-a-valid-extension-x",
                  StringUtil.merge(
                      getAllowedFileExtensions(portletConfig, actionRequest, actionResponse)));
          errorType = ServletResponseConstants.SC_FILE_EXTENSION_EXCEPTION;
        } else if (e instanceof FileNameException) {
          errorMessage = themeDisplay.translate("please-enter-a-file-with-a-valid-file-name");
          errorType = ServletResponseConstants.SC_FILE_NAME_EXCEPTION;
        } else if (e instanceof FileSizeException) {
          long fileMaxSize = PrefsPropsUtil.getLong(PropsKeys.DL_FILE_MAX_SIZE);

          if (fileMaxSize == 0) {
            fileMaxSize = PrefsPropsUtil.getLong(PropsKeys.UPLOAD_SERVLET_REQUEST_IMPL_MAX_SIZE);
          }

          errorMessage =
              themeDisplay.translate(
                  "please-enter-a-file-with-a-valid-file-size-no-larger" + "-than-x",
                  TextFormatter.formatStorageSize(fileMaxSize, themeDisplay.getLocale()));

          errorType = ServletResponseConstants.SC_FILE_SIZE_EXCEPTION;
        }

        JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

        jsonObject.put("message", errorMessage);
        jsonObject.put("status", errorType);

        JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject);
      }

      if (e instanceof AntivirusScannerException) {
        SessionErrors.add(actionRequest, e.getClass(), e);
      } else {
        SessionErrors.add(actionRequest, e.getClass());
      }
    } else if (e instanceof DuplicateLockException
        || e instanceof InvalidFileVersionException
        || e instanceof NoSuchFileEntryException
        || e instanceof PrincipalException) {

      if (e instanceof DuplicateLockException) {
        DuplicateLockException dle = (DuplicateLockException) e;

        SessionErrors.add(actionRequest, dle.getClass(), dle.getLock());
      } else {
        SessionErrors.add(actionRequest, e.getClass());
      }

      actionResponse.setRenderParameter("mvcPath", "/html/porltet/document_library/error.jsp");
    } else {
      Throwable cause = e.getCause();

      if (cause instanceof DuplicateFileEntryException) {
        SessionErrors.add(actionRequest, DuplicateFileEntryException.class);
      } else {
        throw e;
      }
    }
  }
Example #18
0
  /** TODO: Remove. This should extend from EditFileEntryAction once it is modularized. */
  protected String getAddMultipleFileEntriesErrorMessage(
      PortletConfig portletConfig,
      ActionRequest actionRequest,
      ActionResponse actionResponse,
      Exception e)
      throws Exception {

    String errorMessage = null;

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

    if (e instanceof AntivirusScannerException) {
      AntivirusScannerException ase = (AntivirusScannerException) e;

      errorMessage = themeDisplay.translate(ase.getMessageKey());
    } else if (e instanceof AssetCategoryException) {
      AssetCategoryException ace = (AssetCategoryException) e;

      AssetVocabulary assetVocabulary = ace.getVocabulary();

      String vocabularyTitle = StringPool.BLANK;

      if (assetVocabulary != null) {
        vocabularyTitle = assetVocabulary.getTitle(themeDisplay.getLocale());
      }

      if (ace.getType() == AssetCategoryException.AT_LEAST_ONE_CATEGORY) {
        errorMessage =
            themeDisplay.translate("please-select-at-least-one-category-for-x", vocabularyTitle);
      } else if (ace.getType() == AssetCategoryException.TOO_MANY_CATEGORIES) {

        errorMessage =
            themeDisplay.translate(
                "you-cannot-select-more-than-one-category-for-x", vocabularyTitle);
      }
    } else if (e instanceof DuplicateFileEntryException) {
      errorMessage =
          themeDisplay.translate(
              "the-folder-you-selected-already-has-an-entry-with-this-name."
                  + "-please-select-a-different-folder");
    } else if (e instanceof FileExtensionException) {
      errorMessage =
          themeDisplay.translate(
              "please-enter-a-file-with-a-valid-extension-x",
              StringUtil.merge(
                  getAllowedFileExtensions(portletConfig, actionRequest, actionResponse)));
    } else if (e instanceof FileNameException) {
      errorMessage = themeDisplay.translate("please-enter-a-file-with-a-valid-file-name");
    } else if (e instanceof FileSizeException) {
      long fileMaxSize = PrefsPropsUtil.getLong(PropsKeys.DL_FILE_MAX_SIZE);

      if (fileMaxSize == 0) {
        fileMaxSize = PrefsPropsUtil.getLong(PropsKeys.UPLOAD_SERVLET_REQUEST_IMPL_MAX_SIZE);
      }

      errorMessage =
          themeDisplay.translate(
              "please-enter-a-file-with-a-valid-file-size-no-larger-than-x",
              TextFormatter.formatStorageSize(fileMaxSize, themeDisplay.getLocale()));
    } else if (e instanceof InvalidFileEntryTypeException) {
      errorMessage =
          themeDisplay.translate("the-document-type-you-selected-is-not-valid-for-this-folder");
    } else {
      errorMessage =
          themeDisplay.translate("an-unexpected-error-occurred-while-saving-your-document");
    }

    return errorMessage;
  }
  protected void handleUploadException(
      ActionRequest actionRequest,
      ActionResponse actionResponse,
      String cmd,
      long maxFileSize,
      Exception e)
      throws Exception {

    if (e instanceof PrincipalException) {
      SessionErrors.add(actionRequest, e.getClass());

      setForward(actionRequest, "portal.error");
    } else if (e instanceof AntivirusScannerException
        || e instanceof FileExtensionException
        || e instanceof FileSizeException
        || e instanceof ImageTypeException
        || e instanceof NoSuchFileException
        || e instanceof UploadException) {

      if (cmd.equals(Constants.ADD_TEMP)) {
        hideDefaultErrorMessage(actionRequest);

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

        String errorMessage = StringPool.BLANK;

        if (e instanceof AntivirusScannerException) {
          AntivirusScannerException ase = (AntivirusScannerException) e;

          errorMessage = themeDisplay.translate(ase.getMessageKey());
        } else if (e instanceof FileExtensionException) {
          errorMessage =
              themeDisplay.translate(
                  "please-enter-a-file-with-a-valid-extension-x",
                  StringUtil.merge(PropsValues.DL_FILE_EXTENSIONS, StringPool.COMMA));
        } else if (e instanceof FileSizeException) {
          if (maxFileSize == 0) {
            maxFileSize = PrefsPropsUtil.getLong(PropsKeys.UPLOAD_SERVLET_REQUEST_IMPL_MAX_SIZE);
          }

          errorMessage =
              themeDisplay.translate(
                  "please-enter-a-file-with-a-valid-file-size-no" + "-larger-than-x",
                  TextFormatter.formatStorageSize(maxFileSize, themeDisplay.getLocale()));
        } else if (e instanceof ImageTypeException) {
          errorMessage = themeDisplay.translate("please-enter-a-file-with-a-valid-file-type");
        } else if (e instanceof NoSuchFileException || e instanceof UploadException) {

          errorMessage =
              themeDisplay.translate("an-unexpected-error-occurred-while-uploading" + "-your-file");
        }

        JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

        jsonObject.put("errorMessage", errorMessage);

        writeJSON(actionRequest, actionResponse, jsonObject);
      } else {
        SessionErrors.add(actionRequest, e.getClass(), e);
      }
    } else {
      throw e;
    }
  }
  protected Object[] updateGroup(ActionRequest actionRequest) throws Exception {

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

    long userId = PortalUtil.getUserId(actionRequest);

    long liveGroupId = ParamUtil.getLong(actionRequest, "liveGroupId");

    long parentGroupId =
        ParamUtil.getLong(
            actionRequest,
            "parentGroupSearchContainerPrimaryKeys",
            GroupConstants.DEFAULT_PARENT_GROUP_ID);
    String name = null;
    String description = null;
    int type = 0;
    String friendlyURL = null;
    boolean active = false;

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

    Group liveGroup = null;
    String oldFriendlyURL = null;
    String oldStagingFriendlyURL = null;

    if (liveGroupId <= 0) {

      // Add group

      name = ParamUtil.getString(actionRequest, "name");
      description = ParamUtil.getString(actionRequest, "description");
      type = ParamUtil.getInteger(actionRequest, "type");
      friendlyURL = ParamUtil.getString(actionRequest, "friendlyURL");
      active = ParamUtil.getBoolean(actionRequest, "active");

      liveGroup =
          GroupServiceUtil.addGroup(
              parentGroupId,
              GroupConstants.DEFAULT_LIVE_GROUP_ID,
              name,
              description,
              type,
              friendlyURL,
              true,
              active,
              serviceContext);

      LiveUsers.joinGroup(themeDisplay.getCompanyId(), liveGroup.getGroupId(), userId);
    } else {

      // Update group

      liveGroup = GroupLocalServiceUtil.getGroup(liveGroupId);

      oldFriendlyURL = liveGroup.getFriendlyURL();

      name = ParamUtil.getString(actionRequest, "name", liveGroup.getName());
      description = ParamUtil.getString(actionRequest, "description", liveGroup.getDescription());
      type = ParamUtil.getInteger(actionRequest, "type", liveGroup.getType());
      friendlyURL = ParamUtil.getString(actionRequest, "friendlyURL", liveGroup.getFriendlyURL());
      active = ParamUtil.getBoolean(actionRequest, "active", liveGroup.getActive());

      liveGroup =
          GroupServiceUtil.updateGroup(
              liveGroupId,
              parentGroupId,
              name,
              description,
              type,
              friendlyURL,
              active,
              serviceContext);

      if (type == GroupConstants.TYPE_SITE_OPEN) {
        List<MembershipRequest> membershipRequests =
            MembershipRequestLocalServiceUtil.search(
                liveGroupId,
                MembershipRequestConstants.STATUS_PENDING,
                QueryUtil.ALL_POS,
                QueryUtil.ALL_POS);

        for (MembershipRequest membershipRequest : membershipRequests) {
          MembershipRequestServiceUtil.updateStatus(
              membershipRequest.getMembershipRequestId(),
              themeDisplay.translate("your-membership-has-been-approved"),
              MembershipRequestConstants.STATUS_APPROVED,
              serviceContext);

          LiveUsers.joinGroup(
              themeDisplay.getCompanyId(),
              membershipRequest.getGroupId(),
              new long[] {membershipRequest.getUserId()});
        }
      }
    }

    // Settings

    UnicodeProperties typeSettingsProperties = liveGroup.getTypeSettingsProperties();

    String customJspServletContextName =
        ParamUtil.getString(
            actionRequest,
            "customJspServletContextName",
            typeSettingsProperties.getProperty("customJspServletContextName"));

    typeSettingsProperties.setProperty("customJspServletContextName", customJspServletContextName);

    typeSettingsProperties.setProperty(
        "defaultSiteRoleIds",
        ListUtil.toString(getRoles(actionRequest), Role.ROLE_ID_ACCESSOR, StringPool.COMMA));
    typeSettingsProperties.setProperty(
        "defaultTeamIds",
        ListUtil.toString(getTeams(actionRequest), Team.TEAM_ID_ACCESSOR, StringPool.COMMA));

    String[] analyticsTypes =
        PrefsPropsUtil.getStringArray(
            themeDisplay.getCompanyId(), PropsKeys.ADMIN_ANALYTICS_TYPES, StringPool.NEW_LINE);

    for (String analyticsType : analyticsTypes) {
      if (analyticsType.equalsIgnoreCase("google")) {
        String googleAnalyticsId =
            ParamUtil.getString(
                actionRequest,
                "googleAnalyticsId",
                typeSettingsProperties.getProperty("googleAnalyticsId"));

        typeSettingsProperties.setProperty("googleAnalyticsId", googleAnalyticsId);
      } else {
        String analyticsScript =
            ParamUtil.getString(
                actionRequest,
                SitesUtil.ANALYTICS_PREFIX + analyticsType,
                typeSettingsProperties.getProperty(analyticsType));

        typeSettingsProperties.setProperty(
            SitesUtil.ANALYTICS_PREFIX + analyticsType, analyticsScript);
      }
    }

    String publicRobots =
        ParamUtil.getString(
            actionRequest, "publicRobots", liveGroup.getTypeSettingsProperty("false-robots.txt"));
    String privateRobots =
        ParamUtil.getString(
            actionRequest, "privateRobots", liveGroup.getTypeSettingsProperty("true-robots.txt"));

    typeSettingsProperties.setProperty("false-robots.txt", publicRobots);
    typeSettingsProperties.setProperty("true-robots.txt", privateRobots);

    int trashEnabled =
        ParamUtil.getInteger(
            actionRequest,
            "trashEnabled",
            GetterUtil.getInteger(typeSettingsProperties.getProperty("trashEnabled")));

    typeSettingsProperties.setProperty("trashEnabled", String.valueOf(trashEnabled));

    int trashEntriesMaxAgeCompany =
        PrefsPropsUtil.getInteger(themeDisplay.getCompanyId(), PropsKeys.TRASH_ENTRIES_MAX_AGE);

    int defaultTrashEntriesMaxAgeGroup =
        GetterUtil.getInteger(
            typeSettingsProperties.getProperty("trashEntriesMaxAge"), trashEntriesMaxAgeCompany);

    int trashEntriesMaxAgeGroup =
        ParamUtil.getInteger(actionRequest, "trashEntriesMaxAge", defaultTrashEntriesMaxAgeGroup);

    if (trashEntriesMaxAgeGroup != trashEntriesMaxAgeCompany) {
      typeSettingsProperties.setProperty(
          "trashEntriesMaxAge", String.valueOf(trashEntriesMaxAgeGroup));
    } else {
      typeSettingsProperties.remove("trashEntriesMaxAge");
    }

    // Virtual hosts

    LayoutSet publicLayoutSet = liveGroup.getPublicLayoutSet();

    String publicVirtualHost =
        ParamUtil.getString(
            actionRequest, "publicVirtualHost", publicLayoutSet.getVirtualHostname());

    LayoutSetServiceUtil.updateVirtualHost(liveGroup.getGroupId(), false, publicVirtualHost);

    LayoutSet privateLayoutSet = liveGroup.getPrivateLayoutSet();

    String privateVirtualHost =
        ParamUtil.getString(
            actionRequest, "privateVirtualHost", privateLayoutSet.getVirtualHostname());

    LayoutSetServiceUtil.updateVirtualHost(liveGroup.getGroupId(), true, privateVirtualHost);

    // Staging

    if (liveGroup.hasStagingGroup()) {
      Group stagingGroup = liveGroup.getStagingGroup();

      oldStagingFriendlyURL = stagingGroup.getFriendlyURL();

      friendlyURL =
          ParamUtil.getString(actionRequest, "stagingFriendlyURL", stagingGroup.getFriendlyURL());

      GroupServiceUtil.updateFriendlyURL(stagingGroup.getGroupId(), friendlyURL);

      LayoutSet stagingPublicLayoutSet = stagingGroup.getPublicLayoutSet();

      publicVirtualHost =
          ParamUtil.getString(
              actionRequest,
              "stagingPublicVirtualHost",
              stagingPublicLayoutSet.getVirtualHostname());

      LayoutSetServiceUtil.updateVirtualHost(stagingGroup.getGroupId(), false, publicVirtualHost);

      LayoutSet stagingPrivateLayoutSet = stagingGroup.getPrivateLayoutSet();

      privateVirtualHost =
          ParamUtil.getString(
              actionRequest,
              "stagingPrivateVirtualHost",
              stagingPrivateLayoutSet.getVirtualHostname());

      LayoutSetServiceUtil.updateVirtualHost(stagingGroup.getGroupId(), true, privateVirtualHost);
    }

    liveGroup =
        GroupServiceUtil.updateGroup(liveGroup.getGroupId(), typeSettingsProperties.toString());

    // Layout set prototypes

    if (!liveGroup.isStaged()) {
      long privateLayoutSetPrototypeId =
          ParamUtil.getLong(actionRequest, "privateLayoutSetPrototypeId");
      long publicLayoutSetPrototypeId =
          ParamUtil.getLong(actionRequest, "publicLayoutSetPrototypeId");

      boolean privateLayoutSetPrototypeLinkEnabled =
          ParamUtil.getBoolean(
              actionRequest,
              "privateLayoutSetPrototypeLinkEnabled",
              privateLayoutSet.isLayoutSetPrototypeLinkEnabled());
      boolean publicLayoutSetPrototypeLinkEnabled =
          ParamUtil.getBoolean(
              actionRequest,
              "publicLayoutSetPrototypeLinkEnabled",
              publicLayoutSet.isLayoutSetPrototypeLinkEnabled());

      if ((privateLayoutSetPrototypeId == 0)
          && (publicLayoutSetPrototypeId == 0)
          && !privateLayoutSetPrototypeLinkEnabled
          && !publicLayoutSetPrototypeLinkEnabled) {

        long layoutSetPrototypeId = ParamUtil.getLong(actionRequest, "layoutSetPrototypeId");
        int layoutSetVisibility = ParamUtil.getInteger(actionRequest, "layoutSetVisibility");
        boolean layoutSetPrototypeLinkEnabled =
            ParamUtil.getBoolean(
                actionRequest, "layoutSetPrototypeLinkEnabled", (layoutSetPrototypeId > 0));

        if (layoutSetVisibility == _LAYOUT_SET_VISIBILITY_PRIVATE) {
          privateLayoutSetPrototypeId = layoutSetPrototypeId;

          privateLayoutSetPrototypeLinkEnabled = layoutSetPrototypeLinkEnabled;
        } else {
          publicLayoutSetPrototypeId = layoutSetPrototypeId;

          publicLayoutSetPrototypeLinkEnabled = layoutSetPrototypeLinkEnabled;
        }
      }

      SitesUtil.updateLayoutSetPrototypesLinks(
          liveGroup,
          publicLayoutSetPrototypeId,
          privateLayoutSetPrototypeId,
          publicLayoutSetPrototypeLinkEnabled,
          privateLayoutSetPrototypeLinkEnabled);
    }

    // Staging

    String redirect = ParamUtil.getString(actionRequest, "redirect");

    long refererPlid = GetterUtil.getLong(HttpUtil.getParameter(redirect, "refererPlid", false));

    if (!privateLayoutSet.isLayoutSetPrototypeLinkActive()
        && !publicLayoutSet.isLayoutSetPrototypeLinkActive()) {

      if ((refererPlid > 0)
          && liveGroup.hasStagingGroup()
          && (themeDisplay.getScopeGroupId() != liveGroup.getGroupId())) {

        Layout firstLayout =
            LayoutLocalServiceUtil.fetchFirstLayout(
                liveGroup.getGroupId(), false, LayoutConstants.DEFAULT_PARENT_LAYOUT_ID);

        if (firstLayout == null) {
          firstLayout =
              LayoutLocalServiceUtil.fetchFirstLayout(
                  liveGroup.getGroupId(), true, LayoutConstants.DEFAULT_PARENT_LAYOUT_ID);
        }

        if (firstLayout != null) {
          refererPlid = firstLayout.getPlid();
        } else {
          refererPlid = 0;
        }
      }

      StagingUtil.updateStaging(actionRequest, liveGroup);
    }

    return new Object[] {liveGroup, oldFriendlyURL, oldStagingFriendlyURL, refererPlid};
  }
  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);
  }