@Override
  protected void doExportStagedModel(
      PortletDataContext portletDataContext, MDRRuleGroupInstance ruleGroupInstance)
      throws Exception {

    MDRRuleGroup ruleGroup =
        _mdrRuleGroupLocalService.getRuleGroup(ruleGroupInstance.getRuleGroupId());

    StagedModelDataHandlerUtil.exportReferenceStagedModel(
        portletDataContext, ruleGroupInstance, ruleGroup, PortletDataContext.REFERENCE_TYPE_PARENT);

    Element ruleGroupInstanceElement = portletDataContext.getExportDataElement(ruleGroupInstance);

    String className = ruleGroupInstance.getClassName();

    if (className.equals(Layout.class.getName())) {
      Layout layout = _layoutLocalService.getLayout(ruleGroupInstance.getClassPK());

      ruleGroupInstanceElement.addAttribute("layout-uuid", layout.getUuid());
    }

    portletDataContext.addClassedModel(
        ruleGroupInstanceElement,
        ExportImportPathUtil.getModelPath(ruleGroupInstance),
        ruleGroupInstance);
  }
  public boolean isShowIconsActions() throws PortalException {
    if (isSpreadsheet()) {
      return false;
    }

    if (_hasShowIconsActionPermission != null) {
      return _hasShowIconsActionPermission;
    }

    _hasShowIconsActionPermission = Boolean.FALSE;

    ThemeDisplay themeDisplay = getThemeDisplay();

    if (!themeDisplay.isSignedIn()) {
      return _hasShowIconsActionPermission;
    }

    Layout layout = themeDisplay.getLayout();

    if (layout.isLayoutPrototypeLinkActive()) {
      return _hasShowIconsActionPermission;
    }

    if (isShowConfigurationIcon()
        || isShowAddDDMDisplayTemplateIcon()
        || isShowAddDDMFormTemplateIcon()
        || isShowEditDisplayDDMTemplateIcon()
        || isShowEditFormDDMTemplateIcon()) {

      _hasShowIconsActionPermission = Boolean.TRUE;
    }

    return _hasShowIconsActionPermission;
  }
  @Override
  public boolean isDefaultUpdated() {
    if (!isCustomizedView() || !hasUserPreferences()) {
      return false;
    }

    String preferencesModifiedDateString =
        _portalPreferences.getValue(
            CustomizedPages.namespacePlid(getPlid()), _MODIFIED_DATE, _NULL_DATE);

    DateFormat dateFormat =
        DateFormatFactoryUtil.getSimpleDateFormat(PropsValues.INDEX_DATE_FORMAT_PATTERN);

    try {
      Date preferencesModifiedDate = dateFormat.parse(preferencesModifiedDateString);

      Layout layout = getLayout();

      String propertiesModifiedDateString =
          layout.getTypeSettingsProperty(_MODIFIED_DATE, _NULL_DATE);

      Date propertiesModifiedDate = dateFormat.parse(propertiesModifiedDateString);

      return propertiesModifiedDate.after(preferencesModifiedDate);
    } catch (Exception e) {
      _log.error(e, e);
    }

    return false;
  }
  public void editConfiguration(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    Portlet portlet = ActionUtil.getPortlet(actionRequest);

    PortletConfig portletConfig =
        (PortletConfig) actionRequest.getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG);

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

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

    PortletPreferences portletPreferences =
        getPortletPreferences(themeDisplay, portlet.getPortletId(), settingsScope);

    actionRequest = ActionUtil.getWrappedActionRequest(actionRequest, portletPreferences);

    ConfigurationAction configurationAction = getConfigurationAction(portlet);

    if (configurationAction == null) {
      return;
    }

    configurationAction.processAction(portletConfig, actionRequest, actionResponse);

    Layout layout = themeDisplay.getLayout();

    PortletLayoutListener portletLayoutListener = portlet.getPortletLayoutListenerInstance();

    if (portletLayoutListener != null) {
      portletLayoutListener.onSetup(portlet.getPortletId(), layout.getPlid());
    }
  }
  /**
   * 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");
    }
  }
  public void deleteLayout(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

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

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

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

    if (selPlid <= 0) {
      long groupId = ParamUtil.getLong(actionRequest, "groupId");
      boolean privateLayout = ParamUtil.getBoolean(actionRequest, "privateLayout");
      long layoutId = ParamUtil.getLong(actionRequest, "layoutId");

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

      selPlid = layout.getPlid();
    }

    Object[] returnValue = SitesUtil.deleteLayout(actionRequest, actionResponse);

    if (selPlid == themeDisplay.getRefererPlid()) {
      long newRefererPlid = (Long) returnValue[2];

      redirect = HttpUtil.setParameter(redirect, "refererPlid", newRefererPlid);
      redirect = HttpUtil.setParameter(redirect, actionResponse.getNamespace() + "selPlid", 0);
    }

    actionRequest.setAttribute(WebKeys.REDIRECT, redirect);
  }
  protected void inheritMobileRuleGroups(Layout layout, ServiceContext serviceContext)
      throws PortalException {

    List<MDRRuleGroupInstance> parentMDRRuleGroupInstances =
        mdrRuleGroupInstanceLocalService.getRuleGroupInstances(
            Layout.class.getName(), layout.getParentPlid());

    for (MDRRuleGroupInstance parentMDRRuleGroupInstance : parentMDRRuleGroupInstances) {

      MDRRuleGroupInstance mdrRuleGroupInstance =
          mdrRuleGroupInstanceService.addRuleGroupInstance(
              layout.getGroupId(),
              Layout.class.getName(),
              layout.getPlid(),
              parentMDRRuleGroupInstance.getRuleGroupId(),
              parentMDRRuleGroupInstance.getPriority(),
              serviceContext);

      List<MDRAction> parentMDRActions =
          mdrActionLocalService.getActions(parentMDRRuleGroupInstance.getRuleGroupInstanceId());

      for (MDRAction mdrAction : parentMDRActions) {
        mdrActionService.addAction(
            mdrRuleGroupInstance.getRuleGroupInstanceId(),
            mdrAction.getNameMap(),
            mdrAction.getDescriptionMap(),
            mdrAction.getType(),
            mdrAction.getTypeSettings(),
            serviceContext);
      }
    }
  }
  @Override
  public void removeNestedColumns(String portletNamespace) {
    UnicodeProperties typeSettingsProperties = getTypeSettingsProperties();

    UnicodeProperties newTypeSettingsProperties = new UnicodeProperties();

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

      String key = entry.getKey();

      if (!key.startsWith(portletNamespace)) {
        newTypeSettingsProperties.setProperty(key, entry.getValue());
      }
    }

    Layout layout = getLayout();

    layout.setTypeSettingsProperties(newTypeSettingsProperties);

    String nestedColumnIds =
        GetterUtil.getString(getTypeSettingsProperty(LayoutTypePortletConstants.NESTED_COLUMN_IDS));

    String[] nestedColumnIdsArray =
        ArrayUtil.removeByPrefix(StringUtil.split(nestedColumnIds), portletNamespace);

    setTypeSettingsProperty(
        LayoutTypePortletConstants.NESTED_COLUMN_IDS, StringUtil.merge(nestedColumnIdsArray));
  }
  protected String getOldScopeName(ActionRequest actionRequest, Portlet portlet) throws Exception {

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

    Layout layout = themeDisplay.getLayout();

    PortletPreferences portletPreferences = actionRequest.getPreferences();

    String scopeType = GetterUtil.getString(portletPreferences.getValue("lfrScopeType", null));

    if (Validator.isNull(scopeType)) {
      return null;
    }

    String scopeName = null;

    if (scopeType.equals("company")) {
      scopeName = themeDisplay.translate("global");
    } else if (scopeType.equals("layout")) {
      String scopeLayoutUuid =
          GetterUtil.getString(portletPreferences.getValue("lfrScopeLayoutUuid", null));

      Layout scopeLayout =
          _layoutLocalService.fetchLayoutByUuidAndGroupId(
              scopeLayoutUuid, layout.getGroupId(), layout.isPrivateLayout());

      if (scopeLayout != null) {
        scopeName = scopeLayout.getName(themeDisplay.getLocale());
      }
    } else {
      throw new IllegalArgumentException("Scope type " + scopeType + " is invalid");
    }

    return scopeName;
  }
  protected void setThemeSettingProperties(
      ActionRequest actionRequest,
      UnicodeProperties typeSettingsProperties,
      Map<String, ThemeSetting> themeSettings,
      String device,
      boolean isLayout)
      throws PortalException {

    Layout layout = null;

    if (isLayout) {
      long groupId = ParamUtil.getLong(actionRequest, "groupId");
      boolean privateLayout = ParamUtil.getBoolean(actionRequest, "privateLayout");
      long layoutId = ParamUtil.getLong(actionRequest, "layoutId");

      layout = layoutLocalService.getLayout(groupId, privateLayout, layoutId);
    }

    for (String key : themeSettings.keySet()) {
      ThemeSetting themeSetting = themeSettings.get(key);

      String property = device + "ThemeSettingsProperties--" + key + StringPool.DOUBLE_DASH;

      String value = ParamUtil.getString(actionRequest, property, themeSetting.getValue());

      if ((isLayout && !Validator.equals(value, layout.getDefaultThemeSetting(key, device, false)))
          || (!isLayout && !value.equals(themeSetting.getValue()))) {

        typeSettingsProperties.setProperty(ThemeSettingImpl.namespaceProperty(device, key), value);
      }
    }
  }
  protected void copyResourcePermissions(String sourcePortletId, String targetPortletId) {

    Layout layout = getLayout();

    Portlet portlet = PortletLocalServiceUtil.getPortletById(getCompanyId(), sourcePortletId);

    String sourcePortletPrimaryKey =
        PortletPermissionUtil.getPrimaryKey(layout.getPlid(), sourcePortletId);

    List<ResourcePermission> resourcePermissions =
        ResourcePermissionLocalServiceUtil.getResourcePermissions(
            portlet.getCompanyId(),
            portlet.getPortletName(),
            PortletKeys.PREFS_OWNER_TYPE_USER,
            sourcePortletPrimaryKey);

    for (ResourcePermission resourcePermission : resourcePermissions) {
      String targetPortletPrimaryKey =
          PortletPermissionUtil.getPrimaryKey(layout.getPlid(), targetPortletId);

      resourcePermission.setResourcePermissionId(CounterLocalServiceUtil.increment());
      resourcePermission.setPrimKey(targetPortletPrimaryKey);

      ResourcePermissionLocalServiceUtil.addResourcePermission(resourcePermission);
    }
  }
  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;
  }
  protected void copyPreferences(long userId, String sourcePortletId, String targetPortletId) {

    Layout layout = getLayout();

    try {
      PortletPreferencesIds portletPreferencesIds =
          PortletPreferencesFactoryUtil.getPortletPreferencesIds(
              layout.getGroupId(), 0, layout, sourcePortletId, false);

      javax.portlet.PortletPreferences sourcePortletPreferences =
          PortletPreferencesLocalServiceUtil.getStrictPreferences(portletPreferencesIds);

      portletPreferencesIds =
          PortletPreferencesFactoryUtil.getPortletPreferencesIds(
              layout.getGroupId(), userId, layout, targetPortletId, false);

      PortletPreferencesLocalServiceUtil.updatePreferences(
          portletPreferencesIds.getOwnerId(),
          portletPreferencesIds.getOwnerType(),
          portletPreferencesIds.getPlid(),
          portletPreferencesIds.getPortletId(),
          sourcePortletPreferences);
    } catch (Exception e) {
    }
  }
  protected PortletPreferences getPortletPreferences(
      ThemeDisplay themeDisplay, String portletId, String settingsScope) {

    Layout layout = themeDisplay.getLayout();

    if (!layout.isSupportsEmbeddedPortlets()) {
      return null;
    }

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

    if (!layoutTypePortlet.isPortletEmbedded(portletId)) {
      return null;
    }

    PortletPreferencesIds portletPreferencesIds =
        new PortletPreferencesIds(
            themeDisplay.getCompanyId(),
            layout.getGroupId(),
            PortletKeys.PREFS_OWNER_TYPE_LAYOUT,
            PortletKeys.PREFS_PLID_SHARED,
            portletId);

    return _portletPreferencesLocalService.getPreferences(portletPreferencesIds);
  }
  protected PortletDataContext getPortletDataContext(
      ExportImportConfiguration exportImportConfiguration, File file) throws PortalException {

    Map<String, Serializable> settingsMap = exportImportConfiguration.getSettingsMap();

    Map<String, String[]> parameterMap = (Map<String, String[]>) settingsMap.get("parameterMap");
    String portletId = MapUtil.getString(settingsMap, "portletId");
    long targetPlid = MapUtil.getLong(settingsMap, "targetPlid");
    long targetGroupId = MapUtil.getLong(settingsMap, "targetGroupId");
    long userId = MapUtil.getLong(settingsMap, "userId");

    Layout layout = _layoutLocalService.getLayout(targetPlid);

    String userIdStrategyString =
        MapUtil.getString(parameterMap, PortletDataHandlerKeys.USER_ID_STRATEGY);

    UserIdStrategy userIdStrategy =
        ExportImportHelperUtil.getUserIdStrategy(userId, userIdStrategyString);

    ZipReader zipReader = ZipReaderFactoryUtil.getZipReader(file);

    PortletDataContext portletDataContext =
        PortletDataContextFactoryUtil.createImportPortletDataContext(
            layout.getCompanyId(), targetGroupId, parameterMap, userIdStrategy, zipReader);

    portletDataContext.setOldPlid(targetPlid);
    portletDataContext.setPlid(targetPlid);
    portletDataContext.setPortletId(portletId);
    portletDataContext.setPrivateLayout(layout.isPrivateLayout());
    portletDataContext.setType("portlet");

    return portletDataContext;
  }
  public void copyApplications(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    long groupId = ParamUtil.getLong(actionRequest, "groupId");
    boolean privateLayout = ParamUtil.getBoolean(actionRequest, "privateLayout");
    long layoutId = ParamUtil.getLong(actionRequest, "layoutId");

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

    if (!layout.getType().equals(LayoutConstants.TYPE_PORTLET)) {
      return;
    }

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

    if ((copyLayoutId == 0) || (copyLayoutId == layout.getLayoutId())) {
      return;
    }

    Layout copyLayout = layoutLocalService.fetchLayout(groupId, privateLayout, copyLayoutId);

    if ((copyLayout == null) || !copyLayout.isTypePortlet()) {
      return;
    }

    ActionUtil.removePortletIds(actionRequest, layout);

    ActionUtil.copyPreferences(actionRequest, layout, copyLayout);

    SitesUtil.copyLookAndFeel(layout, copyLayout);
  }
  @Override
  public void movePortletId(long userId, String portletId, String columnId, int columnPos) {

    if (!hasPortletId(portletId)) {
      return;
    }

    _enablePortletLayoutListener = false;

    try {
      removePortletId(userId, portletId, false);
      addPortletId(userId, portletId, columnId, columnPos, false, true);
    } finally {
      _enablePortletLayoutListener = true;
    }

    Layout layout = getLayout();

    try {
      Portlet portlet = PortletLocalServiceUtil.getPortletById(layout.getCompanyId(), portletId);

      if (portlet != null) {
        PortletLayoutListener portletLayoutListener = portlet.getPortletLayoutListenerInstance();

        if (portletLayoutListener != null) {
          portletLayoutListener.onMoveInLayout(portletId, layout.getPlid());
        }
      }
    } catch (Exception e) {
      _log.error("Unable to fire portlet layout listener event", e);
    }
  }
    protected String toJSON(Layout layout) {
      JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

      jsonObject.put("groupId", layout.getGroupId());
      jsonObject.put("layoutId", layout.getLayoutId());
      jsonObject.put("privateLayout", layout.isPrivateLayout());

      return jsonObject.toString();
    }
  /**
   * Returns the theme's configurable settings, which are declared in <code>
   * liferay-look-and-feel.xml</code> and are configurable in the user interface.
   *
   * @param key the theme's key
   * @return the theme's configurable settings
   */
  public String getThemeSetting(String key) {
    Theme theme = getTheme();

    String device = theme.getDevice();

    Layout layout = getLayout();

    return layout.getThemeSetting(key, device);
  }
  protected Tuple getNewScope(ActionRequest actionRequest) throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    Layout layout = themeDisplay.getLayout();

    String[] scopes = StringUtil.split(ParamUtil.getString(actionRequest, "scope"));

    String scopeType = scopes[0];

    long scopeGroupId = 0;
    String scopeName = null;

    if (Validator.isNull(scopeType)) {
      scopeGroupId = layout.getGroupId();
    } else if (scopeType.equals("company")) {
      scopeGroupId = themeDisplay.getCompanyGroupId();
      scopeName = themeDisplay.translate("global");
    } else if (scopeType.equals("layout")) {
      String scopeLayoutUuid = scopes[1];

      Layout scopeLayout =
          _layoutLocalService.getLayoutByUuidAndGroupId(
              scopeLayoutUuid, layout.getGroupId(), layout.isPrivateLayout());

      if (!scopeLayout.hasScopeGroup()) {
        Map<Locale, String> nameMap = new HashMap<>();

        String name = String.valueOf(scopeLayout.getPlid());

        nameMap.put(LocaleUtil.getDefault(), name);

        _groupLocalService.addGroup(
            themeDisplay.getUserId(),
            GroupConstants.DEFAULT_PARENT_GROUP_ID,
            Layout.class.getName(),
            scopeLayout.getPlid(),
            GroupConstants.DEFAULT_LIVE_GROUP_ID,
            nameMap,
            null,
            0,
            true,
            GroupConstants.DEFAULT_MEMBERSHIP_RESTRICTION,
            null,
            false,
            true,
            null);
      }

      scopeGroupId = scopeLayout.getGroupId();
      scopeName = scopeLayout.getName(themeDisplay.getLocale());
    } else {
      throw new IllegalArgumentException("Scope type " + scopeType + " is invalid");
    }

    return new Tuple(scopeGroupId, scopeName);
  }
  @Override
  public void importDataDeletions(ExportImportConfiguration exportImportConfiguration, File file)
      throws Exception {

    ZipReader zipReader = null;

    try {

      // LAR validation

      ExportImportThreadLocal.setPortletDataDeletionImportInProcess(true);

      Map<String, Serializable> settingsMap = exportImportConfiguration.getSettingsMap();

      Map<String, String[]> parameterMap = (Map<String, String[]>) settingsMap.get("parameterMap");
      String portletId = MapUtil.getString(settingsMap, "portletId");
      long targetPlid = MapUtil.getLong(settingsMap, "targetPlid");
      long targetGroupId = MapUtil.getLong(settingsMap, "targetGroupId");

      Layout layout = _layoutLocalService.getLayout(targetPlid);

      zipReader = ZipReaderFactoryUtil.getZipReader(file);

      validateFile(layout.getCompanyId(), targetGroupId, portletId, zipReader);

      PortletDataContext portletDataContext =
          getPortletDataContext(exportImportConfiguration, file);

      boolean deletePortletData =
          MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.DELETE_PORTLET_DATA);

      // Portlet data deletion

      if (deletePortletData) {
        if (_log.isDebugEnabled()) {
          _log.debug("Deleting portlet data");
        }

        deletePortletData(portletDataContext);
      }

      // Deletion system events

      populateDeletionStagedModelTypes(portletDataContext);

      _deletionSystemEventImporter.importDeletionSystemEvents(portletDataContext);
    } finally {
      ExportImportThreadLocal.setPortletDataDeletionImportInProcess(false);

      if (zipReader != null) {
        zipReader.close();
      }
    }
  }
  protected String getThemeId() {
    try {
      Layout layout = getLayout();

      LayoutSet layoutSet = layout.getLayoutSet();

      return layoutSet.getThemeId();
    } catch (Exception e) {
      _log.error(e, e);
    }

    return null;
  }
  @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;
  }
Exemple #24
0
  public static void doTag(
      String portletProviderClassName,
      PortletProvider.Action portletProviderAction,
      String instanceId,
      String queryString,
      String defaultPreferences,
      boolean persistSettings,
      PageContext pageContext,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    String portletId =
        PortletProviderUtil.getPortletId(portletProviderClassName, portletProviderAction);

    if (Validator.isNotNull(portletId)) {
      doTag(
          portletId,
          instanceId,
          queryString,
          _SETTINGS_SCOPE_DEFAULT,
          defaultPreferences,
          persistSettings,
          pageContext,
          request,
          response);
    } else {
      ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

      Layout layout = themeDisplay.getLayout();

      if (!layout.isTypeControlPanel()
          && !LayoutPermissionUtil.contains(
              themeDisplay.getPermissionChecker(), layout, ActionKeys.UPDATE)) {

        return;
      }

      String errorMessage =
          LanguageUtil.format(
              request,
              "an-app-that-can-x-x-belongs-here",
              new Object[] {portletProviderAction.name(), portletProviderClassName},
              false);

      request.setAttribute("liferay-portlet:runtime:errorMessage", errorMessage);

      PortalIncludeUtil.include(pageContext, _ERROR_PAGE);
    }
  }
  public static BreadcrumbEntry getScopeGroupBreadcrumbEntry(ThemeDisplay themeDisplay)
      throws Exception {

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

    Layout layout = themeDisplay.getLayout();

    _addGroupsBreadcrumbEntries(breadcrumbEntries, themeDisplay, layout.getLayoutSet(), false);

    if (breadcrumbEntries.isEmpty()) {
      return null;
    }

    return breadcrumbEntries.get(0);
  }
  public static List<BreadcrumbEntry> getParentGroupBreadcrumbEntries(ThemeDisplay themeDisplay)
      throws Exception {

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

    Layout layout = themeDisplay.getLayout();

    LayoutSet parentLayoutSet = _getParentLayoutSet(layout.getLayoutSet());

    if (parentLayoutSet != null) {
      _addGroupsBreadcrumbEntries(breadcrumbEntries, themeDisplay, parentLayoutSet, true);
    }

    return breadcrumbEntries;
  }
  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;
  }
  @Override
  protected StagedModel addStagedModel(
      Group group, Map<String, List<StagedModel>> dependentStagedModelsMap) throws Exception {

    List<StagedModel> dependentStagedModels =
        dependentStagedModelsMap.get(Layout.class.getSimpleName());

    Layout parentLayout = (Layout) dependentStagedModels.get(0);

    Layout layout = LayoutTestUtil.addLayout(group, parentLayout.getPlid());

    addDependentLayoutFriendlyURLs(dependentStagedModelsMap, layout);

    return layout;
  }
  protected boolean isLayoutSetPrototype() {
    try {
      Layout layout = getLayout();

      LayoutSet layoutSet = layout.getLayoutSet();

      Group group = layoutSet.getGroup();

      return group.isLayoutSetPrototype();
    } catch (Exception e) {
      _log.error(e, e);
    }

    return false;
  }
  protected boolean isGroupFriendlyURL(
      Group group, Layout layout, String layoutURL, Locale locale) {

    if (Validator.isNull(layoutURL)) {
      return true;
    }

    int pos = layoutURL.lastIndexOf(CharPool.SLASH);

    String layoutURLLanguageId = layoutURL.substring(pos + 1);

    Locale layoutURLLocale = LocaleUtil.fromLanguageId(layoutURLLanguageId, true, false);

    if (layoutURLLocale != null) {
      return true;
    }

    if (PortalUtil.isGroupFriendlyURL(
        layoutURL, group.getFriendlyURL(), layout.getFriendlyURL(locale))) {

      return true;
    }

    return false;
  }