@Override
  public String getScopeId(Group group, long scopeGroupId) throws PortalException, SystemException {

    String key = null;

    if (group.isLayout()) {
      Layout layout = LayoutLocalServiceUtil.getLayout(group.getClassPK());

      key = SCOPE_ID_LAYOUT_UUID_PREFIX + layout.getUuid();
    } else if (group.isLayoutPrototype() || (group.getGroupId() == scopeGroupId)) {

      key = SCOPE_ID_GROUP_PREFIX + GroupConstants.DEFAULT;
    } else {
      Group scopeGroup = GroupLocalServiceUtil.getGroup(scopeGroupId);

      if (scopeGroup.hasAncestor(group.getGroupId())) {
        key = SCOPE_ID_PARENT_GROUP_PREFIX + group.getGroupId();
      } else if (group.hasAncestor(scopeGroup.getGroupId())) {
        key = SCOPE_ID_CHILD_GROUP_PREFIX + group.getGroupId();
      } else {
        key = SCOPE_ID_GROUP_PREFIX + group.getGroupId();
      }
    }

    return key;
  }
  @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;
  }
  @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));
  }
Пример #4
0
  private LayoutTypePortlet _getLayoutTypePortletClone(HttpServletRequest request)
      throws IOException {

    LayoutTypePortlet layoutTypePortlet = null;

    LayoutClone layoutClone = LayoutCloneFactory.getInstance();

    if (layoutClone != null) {
      String typeSettings = layoutClone.get(request, getPlid());

      if (typeSettings != null) {
        UnicodeProperties typeSettingsProperties = new UnicodeProperties(true);

        typeSettingsProperties.load(typeSettings);

        String stateMax = typeSettingsProperties.getProperty(LayoutTypePortletConstants.STATE_MAX);
        String stateMin = typeSettingsProperties.getProperty(LayoutTypePortletConstants.STATE_MIN);

        Layout layout = (Layout) this.clone();

        layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType();

        layoutTypePortlet.setStateMax(stateMax);
        layoutTypePortlet.setStateMin(stateMin);
      }
    }

    if (layoutTypePortlet == null) {
      layoutTypePortlet = (LayoutTypePortlet) getLayoutType();
    }

    return layoutTypePortlet;
  }
  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 List<Layout> getCandidateLayouts(long plid, boolean privateLayout, KBArticle kbArticle)
      throws Exception {

    List<Layout> candidateLayouts = new ArrayList<>();

    Group group = GroupLocalServiceUtil.getGroup(kbArticle.getGroupId());

    if (group.isLayout()) {
      Layout layout = LayoutLocalServiceUtil.getLayout(group.getClassPK());

      candidateLayouts.add(layout);

      group = layout.getGroup();
    }

    List<Layout> layouts =
        LayoutLocalServiceUtil.getLayouts(
            group.getGroupId(), privateLayout, LayoutConstants.TYPE_PORTLET);

    candidateLayouts.addAll(layouts);

    Layout layout = LayoutLocalServiceUtil.getLayout(plid);

    if ((layout.getGroupId() == kbArticle.getGroupId()) && layout.isTypePortlet()) {

      candidateLayouts.remove(layout);
      candidateLayouts.add(0, layout);
    }

    return candidateLayouts;
  }
  @Override
  public String getURLViewInContext(
      LiferayPortletRequest liferayPortletRequest,
      LiferayPortletResponse liferayPortletResponse,
      String noSuchEntryRedirect)
      throws Exception {

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

    Layout layout = themeDisplay.getLayout();

    if (Validator.isNotNull(_article.getLayoutUuid())) {
      layout =
          LayoutLocalServiceUtil.getLayoutByUuidAndCompanyId(
              _article.getLayoutUuid(), _article.getCompanyId());
    }

    String portletId = (String) liferayPortletRequest.getAttribute(WebKeys.PORTLET_ID);

    PortletPreferences portletSetup =
        PortletPreferencesFactoryUtil.getLayoutPortletSetup(layout, portletId);

    String linkToLayoutUuid =
        GetterUtil.getString(portletSetup.getValue("portletSetupLinkToLayoutUuid", null));

    if (Validator.isNotNull(_article.getLayoutUuid()) && Validator.isNull(linkToLayoutUuid)) {

      Group group = themeDisplay.getScopeGroup();

      if (group.getGroupId() != _article.getGroupId()) {
        group = GroupLocalServiceUtil.getGroup(_article.getGroupId());
      }

      String groupFriendlyURL =
          PortalUtil.getGroupFriendlyURL(group, layout.isPrivateLayout(), themeDisplay);

      return PortalUtil.addPreservedParameters(
          themeDisplay,
          groupFriendlyURL
              .concat(JournalArticleConstants.CANONICAL_URL_SEPARATOR)
              .concat(_article.getUrlTitle()));
    }

    List<Long> hitLayoutIds =
        JournalContentSearchLocalServiceUtil.getLayoutIds(
            _article.getGroupId(), layout.isPrivateLayout(), _article.getArticleId());

    if (!hitLayoutIds.isEmpty()) {
      Long hitLayoutId = hitLayoutIds.get(0);

      Layout hitLayout =
          LayoutLocalServiceUtil.getLayout(
              _article.getGroupId(), layout.isPrivateLayout(), hitLayoutId.longValue());

      return PortalUtil.getLayoutURL(hitLayout, themeDisplay);
    }

    return noSuchEntryRedirect;
  }
  @Override
  protected StagedModel addStagedModel(
      Group group, Map<String, List<StagedModel>> dependentStagedModelsMap) throws Exception {

    _layoutSetPrototype = LayoutTestUtil.addLayoutSetPrototype(RandomTestUtil.randomString());

    List<Layout> layouts =
        LayoutLocalServiceUtil.getLayouts(
            _layoutSetPrototype.getGroupId(), true, LayoutConstants.DEFAULT_PARENT_LAYOUT_ID);

    Assert.assertEquals(1, layouts.size());

    Layout layout = layouts.get(0);

    addLayout(LayoutSetPrototype.class, layout);
    addLayoutFriendlyURLs(LayoutSetPrototype.class, layout.getPlid());

    LayoutPrototype layoutPrototype = addLayoutPrototype(dependentStagedModelsMap);

    Layout prototypedLayout =
        LayoutTestUtil.addLayout(_layoutSetPrototype.getGroupId(), true, layoutPrototype, true);

    addLayout(LayoutSetPrototype.class, prototypedLayout);
    addLayoutFriendlyURLs(LayoutSetPrototype.class, prototypedLayout.getPlid());

    return _layoutSetPrototype;
  }
  protected String getJournalURL(ThemeDisplay themeDisplay, long groupId, Document result)
      throws Exception {

    Layout layout = themeDisplay.getLayout();

    String articleId = result.get(Field.ENTRY_CLASS_PK);
    String version = result.get("version");

    List<Long> hitLayoutIds =
        JournalContentSearchLocalServiceUtil.getLayoutIds(
            layout.getGroupId(), layout.isPrivateLayout(), articleId);

    if (hitLayoutIds.size() > 0) {
      Long hitLayoutId = hitLayoutIds.get(0);

      Layout hitLayout =
          LayoutLocalServiceUtil.getLayout(
              layout.getGroupId(), layout.isPrivateLayout(), hitLayoutId.longValue());

      return PortalUtil.getLayoutURL(hitLayout, themeDisplay);
    } else {
      StringBundler sb = new StringBundler(7);

      sb.append(themeDisplay.getPathMain());
      sb.append("/journal/view_article_content?groupId=");
      sb.append(groupId);
      sb.append("&articleId=");
      sb.append(articleId);
      sb.append("&version=");
      sb.append(version);

      return sb.toString();
    }
  }
Пример #10
0
  private LiferayPortletURL createLiferayPortletURL(
      PortletRequest request, String toPage, String portletId) {
    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
    //		String portletId = (String) request.getAttribute(WebKeys.PORTLET_ID);
    LiferayPortletURL renderURL = null;
    String localHost = themeDisplay.getPortalURL();
    List<Layout> layouts = null;
    try {
      layouts = LayoutLocalServiceUtil.getLayouts(themeDisplay.getLayout().getGroupId(), false);

      for (Layout layout : layouts) {

        String nodeNameRemoved =
            PortalUtil.getLayoutFriendlyURL(layout, themeDisplay).replace(localHost, "");

        // Viene ricercato l'URL esatto per la pagina successiva
        if (nodeNameRemoved.indexOf(toPage) > 0) {

          renderURL =
              PortletURLFactoryUtil.create(
                  request, portletId, layout.getPlid(), PortletRequest.RENDER_PHASE);
          renderURL.setWindowState(WindowState.NORMAL);
          renderURL.setPortletMode(PortletMode.VIEW);

          break;
        }
      }

    } catch (Exception e) {
      e.printStackTrace();
    }
    return renderURL;
  }
  @Override
  protected void doExportStagedModel(
      PortletDataContext portletDataContext,
      Element[] elements,
      MDRRuleGroupInstance ruleGroupInstance)
      throws Exception {

    Element ruleGroupsElement = elements[0];

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

    StagedModelDataHandlerUtil.exportStagedModel(portletDataContext, ruleGroupsElement, ruleGroup);

    Element ruleGroupInstancesElement = elements[1];

    Element ruleGroupInstanceElement = ruleGroupInstancesElement.addElement("rule-group-instance");

    String className = ruleGroupInstance.getClassName();

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

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

    portletDataContext.addClassedModel(
        ruleGroupInstanceElement,
        StagedModelPathUtil.getPath(ruleGroupInstance),
        ruleGroupInstance,
        MDRPortletDataHandler.NAMESPACE);
  }
  public int compare(Object obj1, Object obj2) {
    Layout layout1 = (Layout) obj1;
    Layout layout2 = (Layout) obj2;

    int priority1 = layout1.getPriority();
    int priority2 = layout2.getPriority();

    if (priority1 > priority2) {
      return 1;
    } else if (priority1 < priority2) {
      return -1;
    } else {
      if (_layout.equals(layout1)) {
        if (_lessThan) {
          return 1;
        } else {
          return -1;
        }
      } else if (_layout.equals(layout2)) {
        if (_lessThan) {
          return -1;
        } else {
          return 1;
        }
      }

      return 0;
    }
  }
  protected void assertLinksToLayouts(String content, Layout layout, long groupId) {

    StringBundler sb = new StringBundler();

    sb.append(StringPool.OPEN_BRACKET);
    sb.append(layout.getLayoutId());
    sb.append(CharPool.AT);

    Group group = GroupLocalServiceUtil.fetchGroup(groupId);

    if (layout.isPrivateLayout()) {
      if (group == null) {
        sb.append("private");
      } else if (group.isUser()) {
        sb.append("private-user");
      } else {
        sb.append("private-group");
      }
    } else {
      sb.append("public");
    }

    sb.append(CharPool.AT);
    sb.append(layout.getPlid());

    if (group != null) {
      sb.append(CharPool.AT);
      sb.append(String.valueOf(groupId));
    }

    sb.append(StringPool.CLOSE_BRACKET);

    Assert.assertTrue(content.contains(sb.toString()));
  }
  /**
   * Returns the default role for the group with the primary key.
   *
   * <p>If the group is a site, then the default role is {@link
   * com.liferay.portal.model.RoleConstants#SITE_MEMBER}. If the group is an organization, then the
   * default role is {@link com.liferay.portal.model.RoleConstants#ORGANIZATION_USER}. If the group
   * is a user or user group, then the default role is {@link
   * com.liferay.portal.model.RoleConstants#POWER_USER}. For all other group types, the default role
   * is {@link com.liferay.portal.model.RoleConstants#USER}.
   *
   * @param groupId the primary key of the group
   * @return the default role for the group with the primary key
   * @throws PortalException if a group with the primary key could not be found, or if a default
   *     role could not be found for the group
   * @throws SystemException if a system exception occurred
   */
  public Role getDefaultGroupRole(long groupId) throws PortalException, SystemException {

    Group group = groupPersistence.findByPrimaryKey(groupId);

    if (group.isLayout()) {
      Layout layout = layoutLocalService.getLayout(group.getClassPK());

      group = layout.getGroup();
    }

    if (group.isStagingGroup()) {
      group = group.getLiveGroup();
    }

    Role role = null;

    if (group.isCompany()) {
      role = getRole(group.getCompanyId(), RoleConstants.USER);
    } else if (group.isLayoutPrototype()
        || group.isLayoutSetPrototype()
        || group.isRegularSite()
        || group.isSite()) {

      role = getRole(group.getCompanyId(), RoleConstants.SITE_MEMBER);
    } else if (group.isOrganization()) {
      role = getRole(group.getCompanyId(), RoleConstants.ORGANIZATION_USER);
    } else if (group.isUser() || group.isUserGroup()) {
      role = getRole(group.getCompanyId(), RoleConstants.POWER_USER);
    } else {
      role = getRole(group.getCompanyId(), RoleConstants.USER);
    }

    return role;
  }
  protected void fixImportTypeSettings(Layout layout) throws Exception {
    Object[] friendlyURLInfo = extractFriendlyURLInfo(layout);

    if (friendlyURLInfo == null) {
      return;
    }

    String friendlyURL = (String) friendlyURLInfo[0];

    if (!friendlyURL.equals(_SAME_GROUP_FRIENDLY_URL)) {
      return;
    }

    Group group = layout.getGroup();

    UnicodeProperties typeSettings = layout.getTypeSettingsProperties();

    String url = (String) friendlyURLInfo[1];

    int x = (Integer) friendlyURLInfo[2];
    int y = (Integer) friendlyURLInfo[3];

    typeSettings.setProperty(
        "url", url.substring(0, x) + group.getFriendlyURL() + url.substring(y));
  }
  protected void redirectActionURL(
      HttpServletRequest request,
      HttpServletResponse response,
      ActionResponseImpl actionResponseImpl,
      Portlet portlet)
      throws Exception {

    ActionRequestImpl actionRequestImpl =
        (ActionRequestImpl) request.getAttribute(JavaConstants.JAVAX_PORTLET_REQUEST);

    Layout layout = (Layout) request.getAttribute(WebKeys.LAYOUT);

    PortletURL portletURL =
        new PortletURLImpl(
            actionRequestImpl,
            actionRequestImpl.getPortletName(),
            layout.getPlid(),
            PortletRequest.RENDER_PHASE);

    Map<String, String[]> renderParameters = actionResponseImpl.getRenderParameterMap();

    for (Map.Entry<String, String[]> entry : renderParameters.entrySet()) {
      String key = entry.getKey();
      String[] value = entry.getValue();

      portletURL.setParameter(key, value);
    }

    response.sendRedirect(portletURL.toString());
  }
  protected void initNewLayoutPermissions(
      long companyId,
      long groupId,
      long userId,
      Layout layout,
      Layout importedLayout,
      boolean privateLayout)
      throws Exception {

    boolean addGroupPermissions = true;

    Group group = importedLayout.getGroup();

    if (privateLayout && group.isUser()) {
      addGroupPermissions = false;
    }

    boolean addGuestPermissions = false;

    if (!privateLayout || layout.isTypeControlPanel()) {
      addGuestPermissions = true;
    }

    _resourceLocalService.addResources(
        companyId,
        groupId,
        userId,
        Layout.class.getName(),
        importedLayout.getPlid(),
        false,
        addGroupPermissions,
        addGuestPermissions);
  }
Пример #18
0
  public static String checkViewURL(
      AssetEntry assetEntry,
      boolean viewInContext,
      String viewURL,
      String currentURL,
      ThemeDisplay themeDisplay) {

    if (Validator.isNull(viewURL)) {
      return viewURL;
    }

    viewURL = HttpUtil.setParameter(viewURL, "inheritRedirect", viewInContext);

    Layout layout = themeDisplay.getLayout();

    String assetEntryLayoutUuid = assetEntry.getLayoutUuid();

    if (!viewInContext
        || (Validator.isNotNull(assetEntryLayoutUuid)
            && !assetEntryLayoutUuid.equals(layout.getUuid()))) {

      viewURL = HttpUtil.setParameter(viewURL, "redirect", currentURL);
    }

    return viewURL;
  }
Пример #19
0
  protected Layout getPortalPageLayout(long userId, long groupId, String portalPageName)
      throws Exception {
    Layout portalPageLayout = null;
    boolean privateLayout = true;
    List<Layout> layouts = LayoutLocalServiceUtil.getLayouts(groupId, privateLayout);

    for (Layout layout : layouts) {

      if (layout.getName(Locale.US).equals(portalPageName)) {
        portalPageLayout = layout;
      }
    }

    if (portalPageLayout == null) {
      long parentLayoutId = LayoutConstants.DEFAULT_PARENT_LAYOUT_ID;
      String type = LayoutConstants.TYPE_PORTLET;
      boolean hidden = false;
      String friendlyURL = "/" + portalPageName.toLowerCase();
      portalPageLayout =
          ServiceUtil.addLayout(
              userId,
              groupId,
              privateLayout,
              parentLayoutId,
              portalPageName,
              portalPageName,
              portalPageName,
              type,
              hidden,
              friendlyURL);
    }

    return portalPageLayout;
  }
  protected PortletDataContext getPortletDataContext(
      ExportImportConfiguration exportImportConfiguration) throws PortalException {

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

    long sourcePlid = MapUtil.getLong(settingsMap, "sourcePlid");
    long sourceGroupId = MapUtil.getLong(settingsMap, "sourceGroupId");
    String portletId = MapUtil.getString(settingsMap, "portletId");
    Map<String, String[]> parameterMap = (Map<String, String[]>) settingsMap.get("parameterMap");
    DateRange dateRange = ExportImportDateUtil.getDateRange(exportImportConfiguration);

    Layout layout = _layoutLocalService.getLayout(sourcePlid);
    ZipWriter zipWriter = ExportImportHelperUtil.getPortletZipWriter(portletId);

    PortletDataContext portletDataContext =
        PortletDataContextFactoryUtil.createExportPortletDataContext(
            layout.getCompanyId(),
            sourceGroupId,
            parameterMap,
            dateRange.getStartDate(),
            dateRange.getEndDate(),
            zipWriter);

    portletDataContext.setOldPlid(sourcePlid);
    portletDataContext.setPlid(sourcePlid);
    portletDataContext.setPortletId(portletId);

    return portletDataContext;
  }
Пример #21
0
  public static void updatePermissions(Layout layout, boolean addDefaultActionIds)
      throws Exception {

    long companyId = layout.getCompanyId();

    Role role = RoleLocalServiceUtil.getRole(companyId, RoleConstants.GUEST);

    String[] actionIds = new String[0];

    String name = Layout.class.getName();
    int scope = ResourceConstants.SCOPE_INDIVIDUAL;
    String primKey = String.valueOf(layout.getPrimaryKey());

    ResourcePermissionLocalServiceUtil.setResourcePermissions(
        companyId, name, scope, primKey, role.getRoleId(), actionIds);

    role = RoleLocalServiceUtil.getRole(companyId, RoleConstants.POWER_USER);

    ResourcePermissionLocalServiceUtil.setResourcePermissions(
        companyId, name, scope, primKey, role.getRoleId(), actionIds);

    if (addDefaultActionIds) {
      actionIds = new String[] {ActionKeys.VIEW};
    }

    role = RoleLocalServiceUtil.getRole(companyId, RoleConstants.USER);

    ResourcePermissionLocalServiceUtil.setResourcePermissions(
        companyId, name, scope, primKey, role.getRoleId(), actionIds);
  }
    @Override
    public Void call() throws PortalException {
      Group group = _groupLocalService.getGroup(_groupId);

      Layout layout = _layoutLocalService.fetchLayout(_plid);

      if (group.hasStagingGroup()) {
        group = group.getStagingGroup();

        if (layout != null) {
          layout =
              _layoutLocalService.fetchLayoutByUuidAndGroupId(
                  layout.getUuid(), group.getGroupId(), layout.isPrivateLayout());
        }
      }

      javax.portlet.PortletPreferences jxPortletPreferences = null;

      if (layout == null) {
        jxPortletPreferences =
            PortletPreferencesFactoryUtil.getStrictPortletSetup(
                group.getCompanyId(), group.getGroupId(), _portletId);
      } else {
        jxPortletPreferences =
            PortletPreferencesFactoryUtil.getStrictPortletSetup(layout, _portletId);
      }

      ExportImportDateUtil.updateLastPublishDate(
          _portletId, jxPortletPreferences, _dateRange, _endDate);

      return null;
    }
Пример #23
0
  protected Group addScopeGroup() throws Exception {
    Group group = GroupTestUtil.addGroup();

    Layout layout = LayoutTestUtil.addLayout(group.getGroupId(), ServiceTestUtil.randomString());

    String name = ServiceTestUtil.randomString();

    ServiceContext serviceContext = ServiceTestUtil.getServiceContext(group.getGroupId());

    Group scopeGroup =
        GroupLocalServiceUtil.addGroup(
            TestPropsValues.getUserId(),
            group.getParentGroupId(),
            Layout.class.getName(),
            layout.getPlid(),
            GroupConstants.DEFAULT_LIVE_GROUP_ID,
            name,
            ServiceTestUtil.randomString(),
            GroupConstants.TYPE_SITE_OPEN,
            true,
            GroupConstants.DEFAULT_MEMBERSHIP_RESTRICTION,
            StringPool.SLASH + FriendlyURLNormalizerUtil.normalize(name),
            false,
            true,
            serviceContext);

    return scopeGroup;
  }
  @Override
  public boolean isShow() {
    try {
      Layout layout = getLayout();

      if (layout == null) {
        return false;
      }

      Group group = layout.getGroup();

      if (group.isLayoutPrototype()) {
        return false;
      }

      if (LayoutPermissionUtil.contains(
          themeDisplay.getPermissionChecker(), getLayout(), ActionKeys.PERMISSIONS)) {

        return true;
      }
    } catch (Exception e) {
    }

    return false;
  }
  protected String[] getStaticPortletIds(String position) throws PortalException {

    Layout layout = getLayout();

    String selector1 = StringPool.BLANK;

    Group group = layout.getGroup();

    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;
  }
Пример #26
0
  protected void deleteMissingLayouts(
      long groupId,
      boolean privateLayout,
      Set<Long> newLayoutIds,
      List<Layout> previousLayouts,
      ServiceContext serviceContext)
      throws Exception {

    // Layouts

    if (_log.isDebugEnabled()) {
      if (newLayoutIds.size() > 0) {
        _log.debug("Delete missing layouts");
      }
    }

    for (Layout layout : previousLayouts) {
      if (!newLayoutIds.contains(layout.getLayoutId())) {
        try {
          LayoutLocalServiceUtil.deleteLayout(layout, false, serviceContext);
        } catch (NoSuchLayoutException nsle) {
        }
      }
    }

    // Layout set

    LayoutSetLocalServiceUtil.updatePageCount(groupId, privateLayout);
  }
  @Override
  public void movePortletId(long userId, String portletId, String columnId, int columnPos)
      throws PortalException {

    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 void copyPreferences(String sourcePortletId, String targetPortletId) {

    Layout layout = getLayout();

    PermissionChecker permissionChecker = PermissionThreadLocal.getPermissionChecker();

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

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

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

      PortletPreferencesLocalServiceUtil.updatePreferences(
          portletPreferencesIds.getOwnerId(),
          portletPreferencesIds.getOwnerType(),
          portletPreferencesIds.getPlid(),
          portletPreferencesIds.getPortletId(),
          sourcePortletPreferences);
    } catch (Exception e) {
    }
  }
  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());

    return portletDataContext;
  }
  public boolean isShowParentGroups() {
    if (_showParentGroups != null) {
      return _showParentGroups;
    }

    String showParentGroupsString =
        PrefsParamUtil.getString(_portletPreferences, _request, "showParentGroups", null);

    if (Validator.isNotNull(showParentGroupsString)) {
      _showParentGroups = GetterUtil.getBoolean(showParentGroupsString);

      return _showParentGroups;
    }

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

    try {
      Layout layout = themeDisplay.getLayout();

      Group group = layout.getGroup();

      _showParentGroups =
          GetterUtil.getBoolean(
              group.getTypeSettingsProperty("breadcrumbShowParentGroups"),
              BreadcrumbConfigurationValues.SHOW_PARENT_GROUPS);
    } catch (Exception e) {
      _log.error(e, e);
    }

    return _showParentGroups;
  }