/**
   * Resets the number of failed merge attempts for the page template, which is accessed from the
   * action request's <code>layoutPrototypeId</code> param. Once the counter is reset, the modified
   * page template is merged back into its linked page, which is accessed from the action request's
   * <code>selPlid</code> param.
   *
   * <p>If the number of failed merge attempts is not equal to zero after the merge, an error key is
   * submitted into the {@link SessionErrors}.
   *
   * @param actionRequest the action request
   * @throws Exception if an exception occurred
   */
  public void resetMergeFailCountAndMerge(
      ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

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

    LayoutPrototype layoutPrototype =
        layoutPrototypeLocalService.getLayoutPrototype(layoutPrototypeId);

    SitesUtil.setMergeFailCount(layoutPrototype, 0);

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

    Layout selLayout = layoutLocalService.getLayout(selPlid);

    SitesUtil.resetPrototype(selLayout);

    SitesUtil.mergeLayoutPrototypeLayout(selLayout.getGroup(), selLayout);

    layoutPrototype = layoutPrototypeService.getLayoutPrototype(layoutPrototypeId);

    int mergeFailCountAfterMerge = SitesUtil.getMergeFailCount(layoutPrototype);

    if (mergeFailCountAfterMerge > 0) {
      SessionErrors.add(actionRequest, "resetMergeFailCountAndMerge");
    }
  }
  protected String[] getStaticPortletIds(String position) {
    Layout layout = getLayout();

    String selector1 = StringPool.BLANK;

    Group group = null;

    try {
      group = layout.getGroup();
    } catch (PortalException pe) {
      _log.error("Unable to get group " + layout.getGroupId());

      return new String[0];
    }

    if (group.isUser()) {
      selector1 = LayoutTypePortletConstants.STATIC_PORTLET_USER_SELECTOR;
    } else if (group.isOrganization()) {
      selector1 = LayoutTypePortletConstants.STATIC_PORTLET_ORGANIZATION_SELECTOR;
    } else if (group.isRegularSite()) {
      selector1 = LayoutTypePortletConstants.STATIC_PORTLET_REGULAR_SITE_SELECTOR;
    }

    String selector2 = layout.getFriendlyURL();

    String[] portletIds = PropsUtil.getArray(position, new Filter(selector1, selector2));

    for (int i = 0; i < portletIds.length; i++) {
      portletIds[i] = JS.getSafeName(portletIds[i]);
    }

    return portletIds;
  }
  @Override
  public boolean isVisible(User user, Layout layout) {
    try {
      Group group = layout.getGroup();

      if (!group.isUser() && layout.isTypePortlet()) {
        return true;
      }
    } catch (PortalException pe) {
      _log.error("Unable to display form for customization settings", pe);
    }

    return false;
  }
Exemplo n.º 4
0
  public static List<BreadcrumbEntry> getLayoutBreadcrumbEntries(ThemeDisplay themeDisplay)
      throws Exception {

    List<BreadcrumbEntry> breadcrumbEntries = new ArrayList<>();

    Layout layout = themeDisplay.getLayout();

    Group group = layout.getGroup();

    if (!group.isLayoutPrototype()) {
      _addLayoutBreadcrumbEntries(breadcrumbEntries, themeDisplay, layout);
    }

    return breadcrumbEntries;
  }
  protected void updateLayoutSetPrototype(Layout layout, Date modifiedDate) {
    if (layout == null) {
      return;
    }

    Group group = null;

    try {
      group = layout.getGroup();

      if (!group.isLayoutSetPrototype()) {
        return;
      }
    } catch (PortalException pe) {
      return;
    }

    try {
      LayoutSetPrototype layoutSetPrototype =
          LayoutSetPrototypeLocalServiceUtil.getLayoutSetPrototype(group.getClassPK());

      layoutSetPrototype.setModifiedDate(modifiedDate);

      LayoutSetPrototypeLocalServiceUtil.updateLayoutSetPrototype(layoutSetPrototype);

      LayoutSet layoutSet = layoutSetPrototype.getLayoutSet();

      layoutSet.setModifiedDate(layout.getModifiedDate());

      UnicodeProperties settingsProperties = layoutSet.getSettingsProperties();

      settingsProperties.remove(Sites.MERGE_FAIL_COUNT);

      LayoutSetLocalServiceUtil.updateLayoutSet(layoutSet);
    } catch (Exception e) {
      _log.error(e, e);
    }
  }
  public void addLayout(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest);

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

    long groupId = ParamUtil.getLong(actionRequest, "groupId");
    long liveGroupId = ParamUtil.getLong(actionRequest, "liveGroupId");
    long stagingGroupId = ParamUtil.getLong(actionRequest, "stagingGroupId");
    boolean privateLayout = ParamUtil.getBoolean(actionRequest, "privateLayout");
    long parentLayoutId = ParamUtil.getLong(uploadPortletRequest, "parentLayoutId");
    Map<Locale, String> nameMap = LocalizationUtil.getLocalizationMap(actionRequest, "name");
    Map<Locale, String> titleMap = LocalizationUtil.getLocalizationMap(actionRequest, "title");
    Map<Locale, String> descriptionMap =
        LocalizationUtil.getLocalizationMap(actionRequest, "description");
    Map<Locale, String> keywordsMap =
        LocalizationUtil.getLocalizationMap(actionRequest, "keywords");
    Map<Locale, String> robotsMap = LocalizationUtil.getLocalizationMap(actionRequest, "robots");
    String type = ParamUtil.getString(uploadPortletRequest, "type");
    boolean hidden = ParamUtil.getBoolean(uploadPortletRequest, "hidden");
    Map<Locale, String> friendlyURLMap =
        LocalizationUtil.getLocalizationMap(actionRequest, "friendlyURL");

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

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

    Layout layout = null;

    boolean inheritFromParentLayoutId =
        ParamUtil.getBoolean(uploadPortletRequest, "inheritFromParentLayoutId");

    UnicodeProperties typeSettingsProperties =
        PropertiesParamUtil.getProperties(actionRequest, "TypeSettingsProperties--");

    if (inheritFromParentLayoutId && (parentLayoutId > 0)) {
      Layout parentLayout = layoutLocalService.getLayout(groupId, privateLayout, parentLayoutId);

      layout =
          layoutService.addLayout(
              groupId,
              privateLayout,
              parentLayoutId,
              nameMap,
              titleMap,
              parentLayout.getDescriptionMap(),
              parentLayout.getKeywordsMap(),
              parentLayout.getRobotsMap(),
              parentLayout.getType(),
              parentLayout.getTypeSettings(),
              hidden,
              friendlyURLMap,
              serviceContext);

      inheritMobileRuleGroups(layout, serviceContext);

      if (parentLayout.isTypePortlet()) {
        ActionUtil.copyPreferences(actionRequest, layout, parentLayout);

        SitesUtil.copyLookAndFeel(layout, parentLayout);
      }
    } else if (layoutPrototypeId > 0) {
      LayoutPrototype layoutPrototype =
          layoutPrototypeService.getLayoutPrototype(layoutPrototypeId);

      boolean layoutPrototypeLinkEnabled =
          ParamUtil.getBoolean(
              uploadPortletRequest, "layoutPrototypeLinkEnabled" + layoutPrototype.getUuid());

      serviceContext.setAttribute("layoutPrototypeLinkEnabled", layoutPrototypeLinkEnabled);

      serviceContext.setAttribute("layoutPrototypeUuid", layoutPrototype.getUuid());

      layout =
          layoutService.addLayout(
              groupId,
              privateLayout,
              parentLayoutId,
              nameMap,
              titleMap,
              descriptionMap,
              keywordsMap,
              robotsMap,
              LayoutConstants.TYPE_PORTLET,
              typeSettingsProperties.toString(),
              hidden,
              friendlyURLMap,
              serviceContext);

      // Force propagation from page template to page.
      // See LPS-48430.

      SitesUtil.mergeLayoutPrototypeLayout(layout.getGroup(), layout);
    } else {
      long copyLayoutId = ParamUtil.getLong(uploadPortletRequest, "copyLayoutId");

      Layout copyLayout = null;

      String layoutTemplateId =
          ParamUtil.getString(
              uploadPortletRequest, "layoutTemplateId", PropsValues.DEFAULT_LAYOUT_TEMPLATE_ID);

      if (copyLayoutId > 0) {
        copyLayout = layoutLocalService.fetchLayout(groupId, privateLayout, copyLayoutId);

        if ((copyLayout != null) && copyLayout.isTypePortlet()) {
          LayoutTypePortlet copyLayoutTypePortlet = (LayoutTypePortlet) copyLayout.getLayoutType();

          layoutTemplateId = copyLayoutTypePortlet.getLayoutTemplateId();

          typeSettingsProperties = copyLayout.getTypeSettingsProperties();
        }
      }

      layout =
          layoutService.addLayout(
              groupId,
              privateLayout,
              parentLayoutId,
              nameMap,
              titleMap,
              descriptionMap,
              keywordsMap,
              robotsMap,
              type,
              typeSettingsProperties.toString(),
              hidden,
              friendlyURLMap,
              serviceContext);

      LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType();

      layoutTypePortlet.setLayoutTemplateId(themeDisplay.getUserId(), layoutTemplateId);

      layoutService.updateLayout(
          groupId, privateLayout, layout.getLayoutId(), layout.getTypeSettings());

      if ((copyLayout != null) && copyLayout.isTypePortlet()) {
        ActionUtil.copyPreferences(actionRequest, layout, copyLayout);

        SitesUtil.copyLookAndFeel(layout, copyLayout);
      }
    }

    updateLookAndFeel(
        actionRequest,
        themeDisplay.getCompanyId(),
        liveGroupId,
        stagingGroupId,
        privateLayout,
        layout.getLayoutId(),
        layout.getTypeSettingsProperties());
  }
  @Override
  public ActionForward execute(
      ActionMapping actionMapping,
      ActionForm actionForm,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    HttpSession session = request.getSession();

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

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

    Locale locale = LocaleUtil.fromLanguageId(languageId);

    if (LanguageUtil.isAvailableLocale(themeDisplay.getSiteGroupId(), locale)) {

      boolean persistState = ParamUtil.getBoolean(request, "persistState", true);

      if (themeDisplay.isSignedIn() && persistState) {
        User user = themeDisplay.getUser();

        Contact contact = user.getContact();

        AdminUtil.updateUser(
            request,
            user.getUserId(),
            user.getScreenName(),
            user.getEmailAddress(),
            user.getFacebookId(),
            user.getOpenId(),
            languageId,
            user.getTimeZoneId(),
            user.getGreeting(),
            user.getComments(),
            contact.getSmsSn(),
            contact.getFacebookSn(),
            contact.getJabberSn(),
            contact.getSkypeSn(),
            contact.getTwitterSn());
      }

      session.setAttribute(Globals.LOCALE_KEY, locale);

      LanguageUtil.updateCookie(request, response, locale);
    }

    // Send redirect

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

    String layoutURL = StringPool.BLANK;
    String queryString = StringPool.BLANK;

    int pos = redirect.indexOf(Portal.FRIENDLY_URL_SEPARATOR);

    if (pos == -1) {
      pos = redirect.indexOf(StringPool.QUESTION);
    }

    if (pos != -1) {
      layoutURL = redirect.substring(0, pos);
      queryString = redirect.substring(pos);
    } else {
      layoutURL = redirect;
    }

    Layout layout = themeDisplay.getLayout();

    if (isGroupFriendlyURL(layout.getGroup(), layout, layoutURL, locale)) {
      if (PropsValues.LOCALE_PREPEND_FRIENDLY_URL_STYLE == 0) {
        redirect = layoutURL;
      } else {
        redirect = PortalUtil.getGroupFriendlyURL(layout.getLayoutSet(), themeDisplay, locale);
      }
    } else {
      if (PropsValues.LOCALE_PREPEND_FRIENDLY_URL_STYLE == 0) {
        if (themeDisplay.isI18n()) {
          redirect = layout.getFriendlyURL(locale);
        } else {
          redirect = PortalUtil.getLayoutURL(layout, themeDisplay, locale);
        }
      } else {
        redirect = PortalUtil.getLayoutFriendlyURL(layout, themeDisplay, locale);
      }
    }

    if (layout.isTypeControlPanel()) {
      redirect = redirect + queryString;
    }

    response.sendRedirect(redirect);

    return null;
  }