@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()));
    }
  }
Exemple #2
0
  protected void addBreadcrumbEntries(
      HttpServletRequest request,
      String className,
      long classPK,
      String paramName,
      PortletURL containerModelURL)
      throws PortalException {

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

    TrashHandler trashHandler = TrashHandlerRegistryUtil.getTrashHandler(className);

    List<ContainerModel> containerModels = trashHandler.getParentContainerModels(classPK);

    Collections.reverse(containerModels);

    containerModelURL.setParameter("struts_action", "/trash/view");

    PortalUtil.addPortletBreadcrumbEntry(
        request,
        LanguageUtil.get(themeDisplay.getLocale(), "recycle-bin"),
        containerModelURL.toString());

    for (ContainerModel containerModel : containerModels) {
      TrashHandler containerModelTrashHandler =
          TrashHandlerRegistryUtil.getTrashHandler(containerModel.getModelClassName());

      if (!containerModelTrashHandler.isInTrash(containerModel.getContainerModelId())) {

        continue;
      }

      containerModelURL.setParameter("struts_action", "/trash/view_content");

      containerModelURL.setParameter(
          paramName, String.valueOf(containerModel.getContainerModelId()));

      String name = containerModel.getContainerModelName();

      if (containerModelTrashHandler.isInTrash(containerModel.getContainerModelId())) {

        name = TrashUtil.getOriginalTitle(name);
      }

      PortalUtil.addPortletBreadcrumbEntry(request, name, containerModelURL.toString());
    }

    TrashRenderer trashRenderer = trashHandler.getTrashRenderer(classPK);

    PortalUtil.addPortletBreadcrumbEntry(
        request, trashRenderer.getTitle(themeDisplay.getLocale()), null);
  }
  protected void addBreadcrumbEntries(
      HttpServletRequest request,
      String className,
      long classPK,
      String paramName,
      PortletURL containerModelURL)
      throws PortalException, SystemException {

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

    TrashHandler trashHandler = TrashHandlerRegistryUtil.getTrashHandler(className);

    List<ContainerModel> containerModels = trashHandler.getParentContainerModels(classPK);

    Collections.reverse(containerModels);

    for (ContainerModel containerModel : containerModels) {
      containerModelURL.setParameter(
          paramName, String.valueOf(containerModel.getContainerModelId()));

      PortalUtil.addPortletBreadcrumbEntry(
          request, containerModel.getContainerModelName(), containerModelURL.toString());
    }

    TrashRenderer trashRenderer = trashHandler.getTrashRenderer(classPK);

    PortalUtil.addPortletBreadcrumbEntry(
        request, trashRenderer.getTitle(themeDisplay.getLocale()), null);
  }
Exemple #4
0
  public static List<CalEvent> getMonthEvent(ThemeDisplay themeDisplay, EventDisplayModel evModel) {
    List<CalEvent> lstEvents = new ArrayList<CalEvent>();
    TimeZone timeZone = themeDisplay.getTimeZone();
    Locale locale = themeDisplay.getLocale();
    java.util.Calendar curCal = CalendarFactoryUtil.getCalendar(timeZone, locale);

    int curDay = curCal.get(Calendar.DAY_OF_MONTH);
    int curMonth = curCal.get(Calendar.MONTH);
    int curYear = curCal.get(Calendar.YEAR);
    int maxDayOfMonth = curCal.getActualMaximum(Calendar.DATE);

    GregorianCalendar gregCal = new GregorianCalendar();
    gregCal.set(Calendar.MONTH, curMonth);
    gregCal.set(Calendar.YEAR, curYear);

    try {
      for (int i = 1; i < maxDayOfMonth; i++) {
        List<CalEvent> tempEvents = new ArrayList<CalEvent>();
        gregCal.set(Calendar.DATE, i);
        tempEvents.addAll(
            CalEventServiceUtil.getEvents(themeDisplay.getScopeGroupId(), gregCal, new String()));
        lstEvents.addAll(tempEvents);
      }
      return lstEvents;
    } catch (PortalException e) {
      // TODO Auto-generated catch block
      _log.error(e);
      return null;
    } catch (SystemException e) {
      // TODO Auto-generated catch block
      _log.error(e);
      return null;
    }
  }
Exemple #5
0
  @Override
  public void addContainerModelBreadcrumbEntries(
      HttpServletRequest request, String className, long classPK, PortletURL containerModelURL)
      throws PortalException {

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

    TrashHandler trashHandler = TrashHandlerRegistryUtil.getTrashHandler(className);

    String rootContainerModelName =
        LanguageUtil.get(themeDisplay.getLocale(), trashHandler.getRootContainerModelName());

    if (classPK == 0) {
      PortalUtil.addPortletBreadcrumbEntry(request, rootContainerModelName, null);

      return;
    }

    containerModelURL.setParameter("containerModelId", "0");

    PortalUtil.addPortletBreadcrumbEntry(
        request, rootContainerModelName, containerModelURL.toString());

    addBreadcrumbEntries(request, className, classPK, "containerModelId", containerModelURL);
  }
  /** @see FacesContextHelper#getLocale() */
  public Locale getLocale() {
    Locale locale = null;

    // Try and get the current user's locale from Liferay, since they can override the locale with
    // the Liferay
    // Language portlet.
    ThemeDisplay themeDisplay = getThemeDisplay();

    if (themeDisplay != null) {
      locale = themeDisplay.getLocale();
    }

    // If Liferay didn't return a locale, then try and get the locale from the JSF ViewRoot.
    if (locale == null) {

      locale = getViewRoot().getLocale();
    }

    // If the JSF ViewRoot didn't return a locale, then try and get it from the JSF Application.
    if (locale == null) {
      locale = getApplication().getDefaultLocale();
    }

    // Otherwise, if we couldn't determine the locale, just use the server's default value.
    if (locale == null) {
      locale = Locale.getDefault();
    }

    return locale;
  }
  protected String[][] getCategorySectionLabels() {
    if (_categorySections != null) {
      return _categorySections;
    }

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

    String[] categoryKeys = getCategoryKeys();

    String[][] categorySectionLabels = new String[0][];

    for (int i = 0; i < categoryKeys.length; i++) {
      String categoryKey = categoryKeys[i];

      categorySectionLabels =
          ArrayUtil.append(
              categorySectionLabels,
              FormNavigatorEntryUtil.getLabels(
                  _id,
                  categoryKey,
                  themeDisplay.getUser(),
                  _formModelBean,
                  themeDisplay.getLocale()));
    }

    return categorySectionLabels;
  }
  @Override
  public ActionForward render(
      ActionMapping mapping,
      ActionForm form,
      PortletConfig portletConfig,
      RenderRequest renderRequest,
      RenderResponse renderResponse)
      throws Exception {

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

    Map<String, List<SocialEquityActionMapping>> equityActionMappingsMap =
        new LinkedHashMap<String, List<SocialEquityActionMapping>>();

    String[] classNames = ResourceActionsUtil.getSocialEquityClassNames();

    Comparator<String> comparator = new ModelResourceComparator(themeDisplay.getLocale());

    Arrays.sort(classNames, comparator);

    for (String className : classNames) {
      List<SocialEquityActionMapping> mergedEquityActionMappings =
          getMergedEquityActionMappings(themeDisplay.getScopeGroupIdOrLiveGroupId(), className);

      equityActionMappingsMap.put(className, mergedEquityActionMappings);
    }

    renderRequest.setAttribute(WebKeys.SOCIAL_EQUITY_ACTION_MAPPINGS_MAP, equityActionMappingsMap);

    return mapping.findForward("portlet.social_equity_admin.view");
  }
Exemple #9
0
  @Override
  public String getNewName(
      ThemeDisplay themeDisplay, String className, long classPK, String oldName)
      throws PortalException {

    TrashRenderer trashRenderer = null;

    if (Validator.isNotNull(className) && (classPK > 0)) {
      TrashHandler trashHandler = TrashHandlerRegistryUtil.getTrashHandler(className);

      trashRenderer = trashHandler.getTrashRenderer(classPK);
    }

    Format dateFormatDateTime =
        FastDateFormatFactoryUtil.getDateTime(themeDisplay.getLocale(), themeDisplay.getTimeZone());

    StringBundler sb = new StringBundler(3);

    sb.append(StringPool.OPEN_PARENTHESIS);
    sb.append(
        StringUtil.replace(dateFormatDateTime.format(new Date()), CharPool.SLASH, CharPool.PERIOD));
    sb.append(StringPool.CLOSE_PARENTHESIS);

    if (trashRenderer != null) {
      return trashRenderer.getNewName(oldName, sb.toString());
    } else {
      return getNewName(oldName, sb.toString());
    }
  }
  @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()));
    }
  }
  protected void putMessage(
      HttpServletRequest request, JSONObject jsonObject, String key, Object... arguments) {

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

    String message = LanguageUtil.format(themeDisplay.getLocale(), key, arguments);

    jsonObject.put("message", message);
  }
Exemple #12
0
  public String getNewName(ThemeDisplay themeDisplay, String oldName) {
    Format dateFormatDateTime =
        FastDateFormatFactoryUtil.getDateTime(themeDisplay.getLocale(), themeDisplay.getTimeZone());

    StringBundler sb = new StringBundler(5);

    sb.append(oldName);
    sb.append(StringPool.SPACE);
    sb.append(StringPool.OPEN_PARENTHESIS);
    sb.append(
        StringUtil.replace(dateFormatDateTime.format(new Date()), CharPool.SLASH, CharPool.PERIOD));
    sb.append(StringPool.CLOSE_PARENTHESIS);

    return sb.toString();
  }
 @Override
 public void doView(RenderRequest renderRequest, RenderResponse renderResponse)
     throws IOException, PortletException {
   ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
   renderRequest.setAttribute(
       "portletList",
       LocationTrackerUtil.getPortletList(themeDisplay.getCompanyId(), themeDisplay.getLocale()));
   renderRequest.setAttribute(
       "searchContainer", LocationTrackerUtil.getSearchContainer(renderRequest, renderResponse));
   String portletId = ParamUtil.getString(renderRequest, "portletId");
   renderRequest.setAttribute("selectedPortletId", portletId);
   // renderRequest.setAttribute("portletDetailList",
   // LocationTrackerUtil.findPortlet(renderRequest));
   include(viewJSP, renderRequest, renderResponse);
 }
  protected String[] getCategoryLabels() {
    if (_categoryNames != null) {
      return _categoryNames;
    }

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

    String[] categoryLabels = FormNavigatorCategoryUtil.getLabels(_id, themeDisplay.getLocale());

    if (ArrayUtil.isEmpty(categoryLabels)) {
      categoryLabels = new String[] {""};
    }

    return categoryLabels;
  }
  private Locale _getLocale(HttpServletRequest request) {
    Locale locale = null;

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

    if (themeDisplay != null) {
      locale = themeDisplay.getLocale();
    } else {
      locale = request.getLocale();

      if (!isAvailableLocale(locale)) {
        locale = LocaleUtil.getDefault();
      }
    }

    return locale;
  }
  protected Map<String, Boolean> getActivitySettingsMap(ThemeDisplay themeDisplay)
      throws Exception {

    Map<String, Boolean> activitySettingsMap = new LinkedHashMap<>();

    List<SocialActivitySetting> activitySettings =
        SocialActivitySettingServiceUtil.getActivitySettings(
            themeDisplay.getSiteGroupIdOrLiveGroupId());

    String[] modelNames = SocialConfigurationUtil.getActivityModelNames();

    Comparator<String> comparator = new ModelResourceComparator(themeDisplay.getLocale());

    Arrays.sort(modelNames, comparator);

    for (String modelName : modelNames) {
      List<SocialActivityDefinition> activityDefinitions =
          SocialActivitySettingServiceUtil.getActivityDefinitions(
              themeDisplay.getScopeGroupId(), modelName);

      for (SocialActivityDefinition activityDefinition : activityDefinitions) {

        if (activityDefinition.isCountersEnabled()) {
          activitySettingsMap.put(modelName, false);

          break;
        }
      }
    }

    for (SocialActivitySetting activitySetting : activitySettings) {
      String name = activitySetting.getName();

      if (name.equals("enabled")
          && activitySettingsMap.containsKey(activitySetting.getClassName())) {

        activitySettingsMap.put(
            activitySetting.getClassName(), GetterUtil.getBoolean(activitySetting.getValue()));
      }
    }

    return activitySettingsMap;
  }
  /**
   * Adds the organisation.
   *
   * @param data the data
   * @param result the result
   * @param request the request
   * @param response the response
   * @param model the model
   */
  @ActionMapping(params = "action=addOrganisation")
  public void addOrganisation(
      @Valid @ModelAttribute("orgData") final RegistrationForm data,
      final BindingResult result,
      final ActionRequest request,
      final ActionResponse response,
      final Model model) {
    m_objLog.debug("addOrganisation::start");

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

    if (!result.hasErrors()) {
      this.m_objFormValidator.setThemeDisplay(themeDisplay);
      this.m_objFormValidator.validate(data, result);
    }

    if (!result.hasErrors()) {
      final User user =
          CustomPortalServiceHandler.createPortalUser(
              data.getName(),
              data.getHolder(),
              data.getMail(),
              themeDisplay.getCompanyId(),
              themeDisplay.getScopeGroupId(),
              themeDisplay.getLocale(),
              true);
      if (user != null) {
        final AHOrg org =
            CustomOrgServiceHandler.addOrganisation(
                this.getCompanyId(request), -1, this.getGroupId(request), data);
        if (org == null) {
          SessionErrors.add(request, "org.form.addOrg.failed.org");
        } else {
          response.setRenderParameter("jspPage", "registerSuccess");
        }

      } else {
        SessionErrors.add(request, "org.form.addOrg.failed.user");
      }
    }

    m_objLog.debug("addOrganisation::end");
  }
Exemple #18
0
  public static Map<String, String> getEmailFromDefinitionTerms(PortletRequest portletRequest) {

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

    Map<String, String> definitionTerms = new LinkedHashMap<>();

    definitionTerms.put(
        "[$COMPANY_ID$]",
        LanguageUtil.get(
            themeDisplay.getLocale(), "the-company-id-associated-with-the-message-board"));
    definitionTerms.put(
        "[$COMPANY_MX$]",
        LanguageUtil.get(
            themeDisplay.getLocale(), "the-company-mx-associated-with-the-message-board"));
    definitionTerms.put(
        "[$COMPANY_NAME$]",
        LanguageUtil.get(
            themeDisplay.getLocale(), "the-company-name-associated-with-the-message-board"));

    if (PropsValues.POP_SERVER_NOTIFICATIONS_ENABLED) {
      definitionTerms.put(
          "[$MAILING_LIST_ADDRESS$]",
          LanguageUtil.get(themeDisplay.getLocale(), "the-email-address-of-the-mailing-list"));
    }

    definitionTerms.put(
        "[$MESSAGE_USER_ADDRESS$]",
        LanguageUtil.get(
            themeDisplay.getLocale(), "the-email-address-of-the-user-who-added-the-message"));
    definitionTerms.put(
        "[$MESSAGE_USER_NAME$]",
        LanguageUtil.get(themeDisplay.getLocale(), "the-user-who-added-the-message"));

    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

    definitionTerms.put("[$PORTLET_NAME$]", HtmlUtil.escape(portletDisplay.getTitle()));

    definitionTerms.put(
        "[$SITE_NAME$]",
        LanguageUtil.get(
            themeDisplay.getLocale(), "the-site-name-associated-with-the-message-board"));

    return definitionTerms;
  }
Exemple #19
0
  @Override
  public void addTrashSessionMessages(
      ActionRequest actionRequest, List<TrashedModel> trashedModels, String cmd) {

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

    List<String> classNames = new ArrayList<String>();
    List<Long> restoreTrashEntryIds = new ArrayList<Long>();
    List<String> titles = new ArrayList<String>();

    for (int i = 0; i < trashedModels.size(); i++) {
      try {
        TrashedModel trashedModel = trashedModels.get(i);

        TrashEntry trashEntry = trashedModel.getTrashEntry();

        TrashHandler trashHandler = trashedModel.getTrashHandler();

        TrashRenderer trashRenderer =
            trashHandler.getTrashRenderer(trashedModel.getTrashEntryClassPK());

        classNames.add(trashRenderer.getClassName());
        restoreTrashEntryIds.add(trashEntry.getEntryId());
        titles.add(trashRenderer.getTitle(themeDisplay.getLocale()));
      } catch (Exception e) {
      }
    }

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

    data.put(Constants.CMD, new String[] {cmd});

    data.put("deleteEntryClassName", ArrayUtil.toStringArray(classNames.toArray()));
    data.put("deleteEntryTitle", ArrayUtil.toStringArray(titles.toArray()));
    data.put("restoreTrashEntryIds", ArrayUtil.toStringArray(restoreTrashEntryIds.toArray()));

    SessionMessages.add(
        actionRequest,
        PortalUtil.getPortletId(actionRequest) + SessionMessages.KEY_SUFFIX_DELETE_SUCCESS_DATA,
        data);
  }
  protected void setDDMStructure() throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY);

    _ddmStructureDisplayFieldValue = StringPool.BLANK;
    _ddmStructureFieldLabel = StringPool.BLANK;
    _ddmStructureFieldName = StringPool.BLANK;
    _ddmStructureFieldValue = null;

    long[] classNameIds = getClassNameIds();
    long[] classTypeIds = getClassTypeIds();

    if (isSubtypeFieldsFilterEnabled()
        && (classNameIds.length == 1)
        && (classTypeIds.length == 1)) {

      _ddmStructureDisplayFieldValue =
          GetterUtil.getString(
              _portletPreferences.getValue("ddmStructureDisplayFieldValue", StringPool.BLANK));
      _ddmStructureFieldName =
          GetterUtil.getString(
              _portletPreferences.getValue("ddmStructureFieldName", StringPool.BLANK));
      _ddmStructureFieldValue =
          _portletPreferences.getValue("ddmStructureFieldValue", StringPool.BLANK);

      if (Validator.isNotNull(_ddmStructureFieldName)
          && Validator.isNotNull(_ddmStructureFieldValue)) {

        AssetRendererFactory assetRendererFactory =
            AssetRendererFactoryRegistryUtil.getAssetRendererFactoryByClassName(
                PortalUtil.getClassName(classNameIds[0]));

        Tuple classTypeFieldName =
            assetRendererFactory.getClassTypeFieldName(
                classTypeIds[0], _ddmStructureFieldName, themeDisplay.getLocale());

        _ddmStructureFieldLabel = (String) classTypeFieldName.getObject(0);
      }
    }
  }
  private void _buildLayoutBreadcrumb(
      Layout selLayout,
      String selLayoutParam,
      PortletURL portletURL,
      ThemeDisplay themeDisplay,
      boolean selectedLayout,
      StringBundler sb)
      throws Exception {
    String layoutURL = _getBreadcrumbLayoutURL(selLayout, selLayoutParam, portletURL, themeDisplay);
    String target = PortalUtil.getLayoutTarget(selLayout);

    StringBundler breadCrumbSB = new StringBundler(7);

    breadCrumbSB.append("<li><span><a href=\"");
    breadCrumbSB.append(layoutURL);
    breadCrumbSB.append("\" ");
    breadCrumbSB.append(target);
    breadCrumbSB.append(">");

    breadCrumbSB.append(HtmlUtil.escape(selLayout.getName(themeDisplay.getLocale())));

    breadCrumbSB.append("</a></span></li>");

    Layout layoutParent = null;
    long layoutParentId = selLayout.getParentLayoutId();

    if (layoutParentId != LayoutConstants.DEFAULT_PARENT_LAYOUT_ID) {
      layoutParent =
          LayoutLocalServiceUtil.getLayout(
              selLayout.getGroupId(), selLayout.isPrivateLayout(), layoutParentId);

      _buildLayoutBreadcrumb(layoutParent, selLayoutParam, portletURL, themeDisplay, false, sb);

      sb.append(breadCrumbSB.toString());
    } else {
      sb.append(breadCrumbSB.toString());
    }
  }
  protected DDMFormFieldRenderingContext createDDMFormFieldRenderingContext(
      HttpServletRequest request, HttpServletResponse response) {

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

    String mode = ParamUtil.getString(request, "mode");
    String namespace = ParamUtil.getString(request, "namespace");
    String portletNamespace = ParamUtil.getString(request, "portletNamespace");
    boolean readOnly = ParamUtil.getBoolean(request, "readOnly");

    DDMFormFieldRenderingContext ddmFormFieldRenderingContext = new DDMFormFieldRenderingContext();

    request.setAttribute("aui:form:portletNamespace", portletNamespace);

    ddmFormFieldRenderingContext.setHttpServletRequest(request);
    ddmFormFieldRenderingContext.setHttpServletResponse(response);
    ddmFormFieldRenderingContext.setLocale(themeDisplay.getLocale());
    ddmFormFieldRenderingContext.setMode(mode);
    ddmFormFieldRenderingContext.setNamespace(namespace);
    ddmFormFieldRenderingContext.setPortletNamespace(portletNamespace);
    ddmFormFieldRenderingContext.setReadOnly(readOnly);

    return ddmFormFieldRenderingContext;
  }
Exemple #23
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;
      }
    }
  }
Exemple #24
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;
  }
  public void saveOrUpdateBrokerMessageListener(ActionRequest request, ActionResponse response)
      throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
    PortletConfig portletConfig =
        (PortletConfig) request.getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG);

    long brokerMessageListenerId = ParamUtil.getLong(request, "brokerMessageListenerId");
    boolean isNew = brokerMessageListenerId == 0;
    BrokerMessageListener bml = null;

    if (!isNew) {
      bml =
          BrokerMessageListenerLocalServiceUtil.fetchBrokerMessageListener(brokerMessageListenerId);

    } else {
      bml =
          BrokerMessageListenerLocalServiceUtil.createBrokerMessageListener(
              CounterLocalServiceUtil.increment(BrokerMessageListener.class.getName()));
      bml.setCreateDate(new Date());
    }

    if (isNew
            && BrokerModelPermission.contains(
                themeDisplay.getPermissionChecker(),
                themeDisplay.getScopeGroupId(),
                ActionKeys.ADD_ENTRY)
        || !isNew
            && BrokerMessageListenerPermission.contains(
                themeDisplay.getPermissionChecker(), bml, ActionKeys.UPDATE)) {
      try {
        String brokerMessageListenerName = ParamUtil.getString(request, "name");
        String brokerMessageListenerDescription = ParamUtil.getString(request, "description");
        long brokerId = ParamUtil.getLong(request, "brokerId");
        String[] topicsArr = ParamUtil.getParameterValues(request, "topic");
        StringBuilder topics = new StringBuilder();
        for (int i = 0; i < topicsArr.length; i++) {
          topics.append(topicsArr[i] + ";");
        }
        String typeStr = ParamUtil.getString(request, "type");
        BrokerMessageListenerType type = BrokerMessageListenerType.valueOf(typeStr);

        bml.setCompanyId(themeDisplay.getCompanyId());
        bml.setGroupId(themeDisplay.getCompanyGroupId());
        bml.setUserName(themeDisplay.getUser().getScreenName());
        bml.setUserId(themeDisplay.getUserId());
        bml.setModifiedDate(new Date());
        bml.setName(brokerMessageListenerName);
        bml.setDescription(brokerMessageListenerDescription);
        bml.setBrokerId(brokerId);
        bml.setTopics(topics.toString());
        bml.setType(typeStr);
        if (type.equals(BrokerMessageListenerType.MESSAGE_BUS)) {
          String messageBusDestination = ParamUtil.getString(request, "messageBusDestination");
          bml.setMessageBusDestination(messageBusDestination);
        }

        BrokerMessageListenerLocalServiceUtil.saveOrUpdateBrokerMessageListener(
            bml, themeDisplay.getLocale(), portletConfig);
      } catch (Exception e) {
        response.setRenderParameter("mvcPath", "/html/brokermessagelistener/edit.jsp");
        response.setRenderParameter("errorMessage", e.getMessage());
        request.setAttribute("brokerMessageListener", bml);
        SessionErrors.add(request, "it.acsoftware.brokerportlet.error");
      }
    }
  }
Exemple #26
0
  public static Map<String, String> getEmailDefinitionTerms(
      PortletRequest portletRequest, String emailFromAddress, String emailFromName) {

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

    Map<String, String> definitionTerms = new LinkedHashMap<String, String>();

    definitionTerms.put(
        "[$CATEGORY_NAME$]",
        LanguageUtil.get(
            themeDisplay.getLocale(), "the-category-in-which-the-message-has-been-posted"));
    definitionTerms.put(
        "[$COMPANY_ID$]",
        LanguageUtil.get(
            themeDisplay.getLocale(), "the-company-id-associated-with-the-message-board"));
    definitionTerms.put(
        "[$COMPANY_MX$]",
        LanguageUtil.get(
            themeDisplay.getLocale(), "the-company-mx-associated-with-the-message-board"));
    definitionTerms.put(
        "[$COMPANY_NAME$]",
        LanguageUtil.get(
            themeDisplay.getLocale(), "the-company-name-associated-with-the-message-board"));
    definitionTerms.put("[$FROM_ADDRESS$]", HtmlUtil.escape(emailFromAddress));
    definitionTerms.put("[$FROM_NAME$]", HtmlUtil.escape(emailFromName));

    if (PropsValues.POP_SERVER_NOTIFICATIONS_ENABLED) {
      definitionTerms.put(
          "[$MAILING_LIST_ADDRESS$]",
          LanguageUtil.get(themeDisplay.getLocale(), "the-email-address-of-the-mailing-list"));
    }

    definitionTerms.put(
        "[$MESSAGE_BODY$]", LanguageUtil.get(themeDisplay.getLocale(), "the-message-body"));
    definitionTerms.put(
        "[$MESSAGE_ID$]", LanguageUtil.get(themeDisplay.getLocale(), "the-message-id"));
    definitionTerms.put(
        "[$MESSAGE_SUBJECT$]", LanguageUtil.get(themeDisplay.getLocale(), "the-message-subject"));
    definitionTerms.put(
        "[$MESSAGE_URL$]", LanguageUtil.get(themeDisplay.getLocale(), "the-message-url"));
    definitionTerms.put(
        "[$MESSAGE_USER_ADDRESS$]",
        LanguageUtil.get(
            themeDisplay.getLocale(), "the-email-address-of-the-user-who-added-the-message"));
    definitionTerms.put(
        "[$MESSAGE_USER_NAME$]",
        LanguageUtil.get(themeDisplay.getLocale(), "the-user-who-added-the-message"));

    Company company = themeDisplay.getCompany();

    definitionTerms.put("[$PORTAL_URL$]", company.getVirtualHostname());

    definitionTerms.put("[$PORTLET_NAME$]", PortalUtil.getPortletTitle(portletRequest));
    definitionTerms.put(
        "[$SITE_NAME$]",
        LanguageUtil.get(
            themeDisplay.getLocale(), "the-site-name-associated-with-the-message-board"));

    if (!PropsValues.MESSAGE_BOARDS_EMAIL_BULK) {
      definitionTerms.put(
          "[$TO_ADDRESS$]",
          LanguageUtil.get(themeDisplay.getLocale(), "the-address-of-the-email-recipient"));
      definitionTerms.put(
          "[$TO_NAME$]",
          LanguageUtil.get(themeDisplay.getLocale(), "the-name-of-the-email-recipient"));
    }

    return definitionTerms;
  }
  @Override
  public void processAction(
      ActionMapping mapping,
      ActionForm form,
      PortletConfig portletConfig,
      ActionRequest actionRequest,
      ActionResponse actionResponse)
      throws Exception {

    File file = null;

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

      long groupId = ParamUtil.getLong(actionRequest, "groupId");
      boolean privateLayout = ParamUtil.getBoolean(actionRequest, "privateLayout");
      long[] layoutIds = ParamUtil.getLongValues(actionRequest, "layoutIds");
      String fileName = ParamUtil.getString(actionRequest, "exportFileName");
      String range = ParamUtil.getString(actionRequest, "range");

      Date startDate = null;
      Date endDate = null;

      if (range.equals("dateRange")) {
        int startDateMonth = ParamUtil.getInteger(actionRequest, "startDateMonth");
        int startDateDay = ParamUtil.getInteger(actionRequest, "startDateDay");
        int startDateYear = ParamUtil.getInteger(actionRequest, "startDateYear");
        int startDateHour = ParamUtil.getInteger(actionRequest, "startDateHour");
        int startDateMinute = ParamUtil.getInteger(actionRequest, "startDateMinute");
        int startDateAmPm = ParamUtil.getInteger(actionRequest, "startDateAmPm");

        if (startDateAmPm == Calendar.PM) {
          startDateHour += 12;
        }

        startDate =
            PortalUtil.getDate(
                startDateMonth,
                startDateDay,
                startDateYear,
                startDateHour,
                startDateMinute,
                themeDisplay.getTimeZone(),
                new PortalException());

        int endDateMonth = ParamUtil.getInteger(actionRequest, "endDateMonth");
        int endDateDay = ParamUtil.getInteger(actionRequest, "endDateDay");
        int endDateYear = ParamUtil.getInteger(actionRequest, "endDateYear");
        int endDateHour = ParamUtil.getInteger(actionRequest, "endDateHour");
        int endDateMinute = ParamUtil.getInteger(actionRequest, "endDateMinute");
        int endDateAmPm = ParamUtil.getInteger(actionRequest, "endDateAmPm");

        if (endDateAmPm == Calendar.PM) {
          endDateHour += 12;
        }

        endDate =
            PortalUtil.getDate(
                endDateMonth,
                endDateDay,
                endDateYear,
                endDateHour,
                endDateMinute,
                themeDisplay.getTimeZone(),
                new PortalException());
      } else if (range.equals("fromLastPublishDate")) {
        LayoutSet layoutSet = LayoutSetLocalServiceUtil.getLayoutSet(groupId, privateLayout);

        UnicodeProperties settingsProperties = layoutSet.getSettingsProperties();

        long lastPublishDate =
            GetterUtil.getLong(settingsProperties.getProperty("last-publish-date"));

        if (lastPublishDate > 0) {
          Calendar cal = Calendar.getInstance(themeDisplay.getTimeZone(), themeDisplay.getLocale());

          endDate = cal.getTime();

          cal.setTimeInMillis(lastPublishDate);

          startDate = cal.getTime();
        }
      } else if (range.equals("last")) {
        int rangeLast = ParamUtil.getInteger(actionRequest, "last");

        Date now = new Date();

        startDate = new Date(now.getTime() - (rangeLast * Time.HOUR));

        endDate = now;
      }

      file =
          LayoutServiceUtil.exportLayoutsAsFile(
              groupId,
              privateLayout,
              layoutIds,
              actionRequest.getParameterMap(),
              startDate,
              endDate);

      HttpServletRequest request = PortalUtil.getHttpServletRequest(actionRequest);
      HttpServletResponse response = PortalUtil.getHttpServletResponse(actionResponse);

      ServletResponseUtil.sendFile(
          request, response, fileName, new FileInputStream(file), ContentTypes.APPLICATION_ZIP);

      setForward(actionRequest, ActionConstants.COMMON_NULL);
    } catch (Exception e) {
      _log.error(e, e);

      SessionErrors.add(actionRequest, e.getClass().getName());

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

      sendRedirect(actionRequest, actionResponse, pagesRedirect);
    } finally {
      FileUtil.delete(file);
    }
  }
  public void updateActions(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

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

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

    Role role = RoleLocalServiceUtil.getRole(roleId);

    String roleName = role.getName();

    if (roleName.equals(RoleConstants.ADMINISTRATOR)
        || roleName.equals(RoleConstants.ORGANIZATION_ADMINISTRATOR)
        || roleName.equals(RoleConstants.ORGANIZATION_OWNER)
        || roleName.equals(RoleConstants.OWNER)
        || roleName.equals(RoleConstants.SITE_ADMINISTRATOR)
        || roleName.equals(RoleConstants.SITE_OWNER)) {

      throw new RolePermissionsException(roleName);
    }

    String portletResource = ParamUtil.getString(actionRequest, "portletResource");
    String[] relatedPortletResources =
        StringUtil.split(ParamUtil.getString(actionRequest, "relatedPortletResources"));
    String[] modelResources =
        StringUtil.split(ParamUtil.getString(actionRequest, "modelResources"));

    Map<String, List<String>> resourceActionsMap = new HashMap<>();

    if (Validator.isNotNull(portletResource)) {
      resourceActionsMap.put(
          portletResource, ResourceActionsUtil.getResourceActions(portletResource, null));
    }

    for (String relatedPortletResource : relatedPortletResources) {
      resourceActionsMap.put(
          relatedPortletResource,
          ResourceActionsUtil.getResourceActions(relatedPortletResource, null));
    }

    for (String modelResource : modelResources) {
      resourceActionsMap.put(
          modelResource, ResourceActionsUtil.getResourceActions(null, modelResource));
    }

    int rootResourceScope = ResourceConstants.SCOPE_COMPANY;
    String[] rootResourceGroupIds = null;

    String[] selectedTargets =
        StringUtil.split(ParamUtil.getString(actionRequest, "selectedTargets"));
    String[] unselectedTargets =
        StringUtil.split(ParamUtil.getString(actionRequest, "unselectedTargets"));

    for (Map.Entry<String, List<String>> entry : resourceActionsMap.entrySet()) {

      String selResource = entry.getKey();
      List<String> actions = entry.getValue();

      actions = ListUtil.sort(actions, new ActionComparator(themeDisplay.getLocale()));

      for (String actionId : actions) {
        String target = selResource + actionId;

        boolean selected = ArrayUtil.contains(selectedTargets, target);

        if (!selected && !ArrayUtil.contains(unselectedTargets, target)) {

          continue;
        }

        String[] groupIds =
            StringUtil.split(ParamUtil.getString(actionRequest, "groupIds" + target));

        groupIds = ArrayUtil.distinct(groupIds);

        int scope = ResourceConstants.SCOPE_COMPANY;

        if ((role.getType() == RoleConstants.TYPE_ORGANIZATION)
            || (role.getType() == RoleConstants.TYPE_PROVIDER)
            || (role.getType() == RoleConstants.TYPE_SITE)) {

          scope = ResourceConstants.SCOPE_GROUP_TEMPLATE;
        } else {
          if (groupIds.length > 0) {
            scope = ResourceConstants.SCOPE_GROUP;
          }
        }

        if (ResourceBlockLocalServiceUtil.isSupported(selResource)) {
          updateActions_Blocks(
              role,
              themeDisplay.getScopeGroupId(),
              selResource,
              actionId,
              selected,
              scope,
              groupIds);
        } else {
          updateAction(
              role,
              themeDisplay.getScopeGroupId(),
              selResource,
              actionId,
              selected,
              scope,
              groupIds);
        }

        if (selected && actionId.equals(ActionKeys.ACCESS_IN_CONTROL_PANEL)) {

          updateViewControlPanelPermission(
              role, themeDisplay.getScopeGroupId(), selResource, scope, groupIds);

          rootResourceScope = scope;
          rootResourceGroupIds = groupIds;
        }
      }
    }

    // LPS-38031

    if (rootResourceGroupIds != null) {
      updateViewRootResourcePermission(
          role,
          themeDisplay.getScopeGroupId(),
          portletResource,
          rootResourceScope,
          rootResourceGroupIds);
    }

    // Send redirect

    SessionMessages.add(actionRequest, "permissionsUpdated");

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

    if (Validator.isNotNull(redirect)) {
      actionResponse.sendRedirect(redirect);
    }
  }
Exemple #29
0
  @Override
  public Serializable getDisplayFieldValue(
      ThemeDisplay themeDisplay, Serializable fieldValue, String type) throws Exception {

    if (fieldValue instanceof Date) {
      Date valueDate = (Date) fieldValue;

      DateFormat dateFormat = DateFormatFactoryUtil.getDate(themeDisplay.getLocale());

      fieldValue = dateFormat.format(valueDate);
    } else if (type.equals(DDMImpl.TYPE_CHECKBOX)) {
      Boolean valueBoolean = (Boolean) fieldValue;

      if (valueBoolean) {
        fieldValue = LanguageUtil.get(themeDisplay.getLocale(), "yes");
      } else {
        fieldValue = LanguageUtil.get(themeDisplay.getLocale(), "no");
      }
    } else if (type.equals(DDMImpl.TYPE_DDM_DOCUMENTLIBRARY)) {
      if (Validator.isNull(fieldValue)) {
        return StringPool.BLANK;
      }

      String valueString = String.valueOf(fieldValue);

      JSONObject jsonObject = JSONFactoryUtil.createJSONObject(valueString);

      String uuid = jsonObject.getString("uuid");
      long groupId = jsonObject.getLong("groupId");

      FileEntry fileEntry = DLAppLocalServiceUtil.getFileEntryByUuidAndGroupId(uuid, groupId);

      fieldValue =
          DLUtil.getPreviewURL(
              fileEntry, fileEntry.getFileVersion(), null, StringPool.BLANK, false, true);
    } else if (type.equals(DDMImpl.TYPE_DDM_LINK_TO_PAGE)) {
      if (Validator.isNull(fieldValue)) {
        return StringPool.BLANK;
      }

      String valueString = String.valueOf(fieldValue);

      JSONObject jsonObject = JSONFactoryUtil.createJSONObject(valueString);

      long groupId = jsonObject.getLong("groupId");
      boolean privateLayout = jsonObject.getBoolean("privateLayout");
      long layoutId = jsonObject.getLong("layoutId");

      Layout layout = LayoutLocalServiceUtil.getLayout(groupId, privateLayout, layoutId);

      fieldValue = PortalUtil.getLayoutFriendlyURL(layout, themeDisplay);
    } else if (type.equals(DDMImpl.TYPE_RADIO) || type.equals(DDMImpl.TYPE_SELECT)) {

      String valueString = String.valueOf(fieldValue);

      JSONArray jsonArray = JSONFactoryUtil.createJSONArray(valueString);

      String[] stringArray = ArrayUtil.toStringArray(jsonArray);

      fieldValue = stringArray[0];
    }

    return fieldValue;
  }
  private static void _updateAdminUser(
      HttpServletRequest request, UnicodeProperties unicodeProperties) throws Exception {

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

    Company company = CompanyLocalServiceUtil.getCompanyById(themeDisplay.getCompanyId());

    String emailAddress =
        ParamUtil.getString(
            request,
            "adminEmailAddress",
            PropsValues.DEFAULT_ADMIN_EMAIL_ADDRESS_PREFIX + StringPool.AT + company.getMx());

    PropsValues.ADMIN_EMAIL_FROM_ADDRESS = emailAddress;

    unicodeProperties.put(PropsKeys.ADMIN_EMAIL_FROM_ADDRESS, emailAddress);

    ScreenNameGenerator screenNameGenerator = ScreenNameGeneratorFactory.getInstance();

    String screenName =
        GetterUtil.getString(PropsValues.DEFAULT_ADMIN_EMAIL_ADDRESS_PREFIX, "test");

    try {
      screenName = screenNameGenerator.generate(0, 0, emailAddress);
    } catch (Exception e) {
    }

    String firstName =
        ParamUtil.getString(request, "adminFirstName", PropsValues.DEFAULT_ADMIN_FIRST_NAME);
    String lastName =
        ParamUtil.getString(request, "adminLastName", PropsValues.DEFAULT_ADMIN_LAST_NAME);

    FullNameGenerator fullNameGenerator = FullNameGeneratorFactory.getInstance();

    String fullName = fullNameGenerator.getFullName(firstName, null, lastName);

    PropsValues.ADMIN_EMAIL_FROM_NAME = fullName;

    unicodeProperties.put(PropsKeys.ADMIN_EMAIL_FROM_NAME, fullName);

    User user = null;

    try {
      user = UserLocalServiceUtil.getUserByEmailAddress(themeDisplay.getCompanyId(), emailAddress);

      String greeting =
          LanguageUtil.format(
              themeDisplay.getLocale(), "welcome-x", StringPool.SPACE + fullName, false);

      Contact contact = user.getContact();

      Calendar birthdayCal = CalendarFactoryUtil.getCalendar();

      birthdayCal.setTime(contact.getBirthday());

      int birthdayMonth = birthdayCal.get(Calendar.MONTH);
      int birthdayDay = birthdayCal.get(Calendar.DAY_OF_MONTH);
      int birthdayYear = birthdayCal.get(Calendar.YEAR);

      user =
          UserLocalServiceUtil.updateUser(
              user.getUserId(),
              StringPool.BLANK,
              StringPool.BLANK,
              StringPool.BLANK,
              false,
              user.getReminderQueryQuestion(),
              user.getReminderQueryAnswer(),
              screenName,
              emailAddress,
              user.getFacebookId(),
              user.getOpenId(),
              themeDisplay.getLanguageId(),
              user.getTimeZoneId(),
              greeting,
              user.getComments(),
              firstName,
              user.getMiddleName(),
              lastName,
              contact.getPrefixId(),
              contact.getSuffixId(),
              contact.isMale(),
              birthdayMonth,
              birthdayDay,
              birthdayYear,
              contact.getSmsSn(),
              contact.getAimSn(),
              contact.getFacebookSn(),
              contact.getIcqSn(),
              contact.getJabberSn(),
              contact.getMsnSn(),
              contact.getMySpaceSn(),
              contact.getSkypeSn(),
              contact.getTwitterSn(),
              contact.getYmSn(),
              contact.getJobTitle(),
              null,
              null,
              null,
              null,
              null,
              new ServiceContext());
    } catch (NoSuchUserException nsue) {
      UserLocalServiceUtil.addDefaultAdminUser(
          themeDisplay.getCompanyId(),
          screenName,
          emailAddress,
          themeDisplay.getLocale(),
          firstName,
          StringPool.BLANK,
          lastName);

      user = UserLocalServiceUtil.getUserByEmailAddress(themeDisplay.getCompanyId(), emailAddress);

      String defaultAdminEmailAddress =
          PropsValues.DEFAULT_ADMIN_EMAIL_ADDRESS_PREFIX + "@" + PropsValues.COMPANY_DEFAULT_WEB_ID;

      if (!emailAddress.equals(defaultAdminEmailAddress)) {
        User testUser =
            UserLocalServiceUtil.fetchUserByEmailAddress(
                themeDisplay.getCompanyId(), defaultAdminEmailAddress);

        if (testUser != null) {
          UserLocalServiceUtil.updateStatus(
              testUser.getUserId(), WorkflowConstants.STATUS_INACTIVE);
        }
      }
    }

    user = UserLocalServiceUtil.updatePasswordReset(user.getUserId(), true);

    HttpSession session = request.getSession();

    session.setAttribute(WebKeys.EMAIL_ADDRESS, emailAddress);
    session.setAttribute(WebKeys.SETUP_WIZARD_PASSWORD_UPDATED, true);
    session.setAttribute(WebKeys.USER_ID, user.getUserId());
  }