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 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 void updateTypeSettings(Layout importedLayout, Layout layout) throws PortalException {

    long groupId = layout.getGroupId();

    try {
      LayoutTypePortlet importedLayoutType = (LayoutTypePortlet) importedLayout.getLayoutType();

      List<String> importedPortletIds = importedLayoutType.getPortletIds();

      layout.setGroupId(importedLayout.getGroupId());

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

      importedPortletIds.removeAll(layoutTypePortlet.getPortletIds());

      if (!importedPortletIds.isEmpty()) {
        _portletLocalService.deletePortlets(
            importedLayout.getCompanyId(),
            importedPortletIds.toArray(new String[importedPortletIds.size()]),
            importedLayout.getPlid());
      }

      importedLayout.setTypeSettingsProperties(layoutTypePortlet.getTypeSettingsProperties());
    } finally {
      layout.setGroupId(groupId);
    }
  }
  protected String replaceLinksToLayoutsParameters(String content, Map<String, Layout> layoutsMap)
      throws Exception {

    Layout privateLayout = layoutsMap.get(_PRIVATE_LAYOUT);
    Layout privateUserLayout = layoutsMap.get(_PRIVATE_USER_LAYOUT);
    Layout publicLayout = layoutsMap.get(_PUBLIC_LAYOUT);
    Layout publicUserLayout = layoutsMap.get(_PUBLIC_USER_LAYOUT);

    return StringUtil.replace(
        content,
        new String[] {
          "[$GROUP_ID$]",
          "[$GROUP_ID_USER$]",
          "[$LAYOUT_ID_PRIVATE$]",
          "[$LAYOUT_ID_PRIVATE_USER$]",
          "[$LAYOUT_ID_PUBLIC$]",
          "[$LAYOUT_ID_PUBLIC_USER$]"
        },
        new String[] {
          String.valueOf(privateLayout.getGroupId()),
          String.valueOf(privateUserLayout.getGroupId()),
          String.valueOf(privateLayout.getLayoutId()),
          String.valueOf(privateUserLayout.getLayoutId()),
          String.valueOf(publicLayout.getLayoutId()),
          String.valueOf(publicUserLayout.getLayoutId()),
        });
  }
  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();
    }
  }
  @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())) {
      String portletId = (String) liferayPortletRequest.getAttribute(WebKeys.PORTLET_ID);

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

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

      if (linkToLayoutUuid.equals(_article.getLayoutUuid())) {
        Group group = themeDisplay.getScopeGroup();

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

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

        return groupFriendlyURL
            .concat(JournalArticleConstants.CANONICAL_URL_SEPARATOR)
            .concat(_article.getUrlTitle());
      }
    }

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

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

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

      return PortalUtil.getLayoutURL(hitLayout, themeDisplay);
    }

    return noSuchEntryRedirect;
  }
  protected String addJournalContentPortletToLayout(
      long userId, Layout layout, JournalArticle journalArticle, String columnId) throws Exception {

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

    String journalPortletId =
        layoutTypePortlet.addPortletId(userId, PortletKeys.JOURNAL_CONTENT, columnId, -1);

    LayoutLocalServiceUtil.updateLayout(
        layout.getGroupId(),
        layout.isPrivateLayout(),
        layout.getLayoutId(),
        layout.getTypeSettings());

    javax.portlet.PortletPreferences prefs =
        getPortletPreferences(layout.getCompanyId(), layout.getPlid(), journalPortletId);

    prefs.setValue("articleId", journalArticle.getArticleId());
    prefs.setValue("groupId", String.valueOf(journalArticle.getGroupId()));
    prefs.setValue("showAvailableLocales", Boolean.TRUE.toString());

    updatePortletPreferences(layout.getPlid(), journalPortletId, prefs);

    return journalPortletId;
  }
示例#8
0
  public static Layout addLayout(
      Group group,
      boolean privateLayout,
      long parentLayoutId,
      String name,
      String friendlyURL,
      String layoutTemplateId)
      throws Exception {

    ServiceContext serviceContext = new ServiceContext();

    Layout layout =
        LayoutLocalServiceUtil.addLayout(
            group.getCreatorUserId(),
            group.getGroupId(),
            privateLayout,
            parentLayoutId,
            name,
            StringPool.BLANK,
            StringPool.BLANK,
            LayoutConstants.TYPE_PORTLET,
            false,
            friendlyURL,
            serviceContext);

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

    layoutTypePortlet.setLayoutTemplateId(0, layoutTemplateId, false);

    return LayoutLocalServiceUtil.updateLayout(
        layout.getGroupId(),
        layout.isPrivateLayout(),
        layout.getLayoutId(),
        layout.getTypeSettings());
  }
  /** @see com.liferay.portal.lar.ExportImportHelperImpl#getMissingParentLayouts( Layout, long) */
  protected List<Layout> getMissingRemoteParentLayouts(
      HttpPrincipal httpPrincipal, Layout layout, long remoteGroupId) throws PortalException {

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

    long parentLayoutId = layout.getParentLayoutId();

    while (parentLayoutId > 0) {
      Layout parentLayout =
          LayoutLocalServiceUtil.getLayout(
              layout.getGroupId(), layout.isPrivateLayout(), parentLayoutId);

      try {
        LayoutServiceHttp.getLayoutByUuidAndGroupId(
            httpPrincipal, parentLayout.getUuid(), remoteGroupId, parentLayout.getPrivateLayout());

        // If one parent is found, all others are assumed to exist

        break;
      } catch (NoSuchLayoutException nsle) {
        missingRemoteParentLayouts.add(parentLayout);

        parentLayoutId = parentLayout.getParentLayoutId();
      }
    }

    return missingRemoteParentLayouts;
  }
  protected String replaceLinksToLayoutsParameters(
      String content, Layout privateLayout, Layout publicLayout) {

    return StringUtil.replace(
        content,
        new String[] {
          "[$GROUP_ID_PRIVATE$]", "[$GROUP_ID_PUBLIC$]",
          "[$LAYOUT_ID_PRIVATE$]", "[$LAYOUT_ID_PUBLIC$]"
        },
        new String[] {
          String.valueOf(privateLayout.getGroupId()),
          String.valueOf(publicLayout.getGroupId()),
          String.valueOf(privateLayout.getLayoutId()),
          String.valueOf(publicLayout.getLayoutId())
        });
  }
  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;
  }
  protected void exportJournalArticle(
      PortletDataContext portletDataContext, Layout layout, Element layoutElement)
      throws Exception {

    UnicodeProperties typeSettingsProperties = layout.getTypeSettingsProperties();

    String articleId = typeSettingsProperties.getProperty("article-id", StringPool.BLANK);

    long articleGroupId = layout.getGroupId();

    if (Validator.isNull(articleId)) {
      if (_log.isWarnEnabled()) {
        _log.warn("No article id found in typeSettings of layout " + layout.getPlid());
      }
    }

    JournalArticle article = null;

    try {
      article =
          JournalArticleLocalServiceUtil.getLatestArticle(
              articleGroupId, articleId, WorkflowConstants.STATUS_APPROVED);
    } catch (NoSuchArticleException nsae) {
      if (_log.isWarnEnabled()) {
        _log.warn(
            "No approved article found with group id "
                + articleGroupId
                + " and article id "
                + articleId);
      }
    }

    if (article == null) {
      return;
    }

    String path = JournalPortletDataHandlerImpl.getArticlePath(portletDataContext, article);

    Element articleElement = layoutElement.addElement("article");

    articleElement.addAttribute("path", path);

    Element dlFileEntryTypesElement = layoutElement.addElement("dl-file-entry-types");
    Element dlFoldersElement = layoutElement.addElement("dl-folders");
    Element dlFilesElement = layoutElement.addElement("dl-file-entries");
    Element dlFileRanksElement = layoutElement.addElement("dl-file-ranks");

    JournalPortletDataHandlerImpl.exportArticle(
        portletDataContext,
        layoutElement,
        layoutElement,
        layoutElement,
        dlFileEntryTypesElement,
        dlFoldersElement,
        dlFilesElement,
        dlFileRanksElement,
        article,
        false);
  }
  @Override
  protected void doExportStagedModel(PortletDataContext portletDataContext, Layout layout)
      throws Exception {

    if (layout.isTypeSharedPortlet()) {
      return;
    }

    Element layoutElement = portletDataContext.getExportDataElement(layout);

    populateElementLayoutMetadata(layoutElement, layout);

    layoutElement.addAttribute(Constants.ACTION, Constants.ADD);

    portletDataContext.setPlid(layout.getPlid());

    long parentLayoutId = layout.getParentLayoutId();

    if (parentLayoutId != LayoutConstants.DEFAULT_PARENT_LAYOUT_ID) {
      Layout parentLayout =
          _layoutLocalService.fetchLayout(
              layout.getGroupId(), layout.isPrivateLayout(), parentLayoutId);

      if (parentLayout != null) {
        StagedModelDataHandlerUtil.exportReferenceStagedModel(
            portletDataContext, layout, parentLayout, PortletDataContext.REFERENCE_TYPE_PARENT);

        layoutElement.addAttribute("parent-layout-uuid", parentLayout.getUuid());
      }
    }

    List<LayoutFriendlyURL> layoutFriendlyURLs =
        _layoutFriendlyURLLocalService.getLayoutFriendlyURLs(layout.getPlid());

    for (LayoutFriendlyURL layoutFriendlyURL : layoutFriendlyURLs) {
      StagedModelDataHandlerUtil.exportReferenceStagedModel(
          portletDataContext,
          layout,
          layoutFriendlyURL,
          PortletDataContext.REFERENCE_TYPE_DEPENDENCY);
    }

    if (layout.isIconImage()) {
      exportLayoutIconImage(portletDataContext, layout, layoutElement);
    }

    if (layout.isTypeLinkToLayout()) {
      exportLinkedLayout(portletDataContext, layout, layoutElement);
    }

    fixExportTypeSettings(layout);

    exportTheme(portletDataContext, layout);

    portletDataContext.addClassedModel(
        layoutElement, ExportImportPathUtil.getModelPath(layout), layout);
  }
  @Override
  public Settings getPortletInstanceSettings(Layout layout, String portletId)
      throws PortalException {

    return applyFallbackKeys(
        PortletConstants.getRootPortletId(portletId),
        new PortletPreferencesSettings(
            getPortletInstancePortletPreferences(layout, portletId),
            getGroupSettings(layout.getGroupId(), portletId)));
  }
  private void _doPreparePortlet(HttpServletRequest request, Portlet portlet) throws Exception {

    User user = PortalUtil.getUser(request);
    Layout layout = (Layout) request.getAttribute(WebKeys.LAYOUT);

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

    long scopeGroupId = PortalUtil.getScopeGroupId(request, portlet.getPortletId());

    themeDisplay.setScopeGroupId(scopeGroupId);

    long siteGroupId = 0;

    if (layout.isTypeControlPanel()) {
      siteGroupId = PortalUtil.getSiteGroupId(scopeGroupId);
    } else {
      siteGroupId = PortalUtil.getSiteGroupId(layout.getGroupId());
    }

    themeDisplay.setSiteGroupId(siteGroupId);

    if (user != null) {
      HttpSession session = request.getSession();

      InvokerPortletImpl.clearResponse(
          session,
          layout.getPrimaryKey(),
          portlet.getPortletId(),
          LanguageUtil.getLanguageId(request));
    }

    processPublicRenderParameters(request, layout, portlet);

    if (themeDisplay.isLifecycleRender() || themeDisplay.isLifecycleResource()) {

      WindowState windowState =
          WindowStateFactory.getWindowState(ParamUtil.getString(request, "p_p_state"));

      if (layout.isTypeControlPanel()
          && ((windowState == null)
              || windowState.equals(WindowState.NORMAL)
              || Validator.isNull(windowState.toString()))) {

        windowState = WindowState.MAXIMIZED;
      }

      PortletMode portletMode =
          PortletModeFactory.getPortletMode(ParamUtil.getString(request, "p_p_mode"));

      PortalUtil.updateWindowState(portlet.getPortletId(), user, layout, windowState, request);

      PortalUtil.updatePortletMode(portlet.getPortletId(), user, layout, portletMode, request);
    }
  }
  protected void addLayoutIds(
      List<Long> layoutIds, long groupId, boolean privateLayout, long layoutId) throws Exception {

    List<Layout> layouts = LayoutLocalServiceUtil.getLayouts(groupId, privateLayout, layoutId);

    for (Layout layout : layouts) {
      layoutIds.add(layout.getLayoutId());

      addLayoutIds(layoutIds, layout.getGroupId(), layout.isPrivateLayout(), layout.getLayoutId());
    }
  }
  protected Layout updateLayoutTemplateId(Layout layout, String layoutTemplateId) throws Exception {

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

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

    return LayoutServiceUtil.updateLayout(
        layout.getGroupId(),
        layout.isPrivateLayout(),
        layout.getLayoutId(),
        layout.getTypeSettings());
  }
  protected String getPortletId(long plid) throws Exception {
    Layout layout = LayoutLocalServiceUtil.getLayout(plid);

    long selPlid =
        PortalUtil.getPlidFromPortletId(layout.getGroupId(), PortletKeys.KNOWLEDGE_BASE_DISPLAY);

    if (selPlid != LayoutConstants.DEFAULT_PARENT_LAYOUT_ID) {
      return PortletKeys.KNOWLEDGE_BASE_DISPLAY;
    }

    return PortletKeys.KNOWLEDGE_BASE_ARTICLE_DEFAULT_INSTANCE;
  }
示例#19
0
  protected String getEntryURL(
      ResourceRequest resourceRequest,
      JournalFeed feed,
      JournalArticle article,
      Layout layout,
      ThemeDisplay themeDisplay)
      throws Exception {

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

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

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

      return PortalUtil.getLayoutFriendlyURL(hitLayout, themeDisplay);
    } else {
      long plid =
          PortalUtil.getPlidFromFriendlyURL(feed.getCompanyId(), feed.getTargetLayoutFriendlyUrl());

      String portletId = PortletKeys.JOURNAL_CONTENT;

      if (Validator.isNotNull(feed.getTargetPortletId())) {
        portletId = feed.getTargetPortletId();
      }

      PortletURL entryURL =
          new PortletURLImpl(resourceRequest, portletId, plid, PortletRequest.RENDER_PHASE);

      entryURL.setParameter("struts_action", "/journal_content/view");
      entryURL.setParameter("groupId", String.valueOf(article.getGroupId()));
      entryURL.setParameter("articleId", article.getArticleId());

      return entryURL.toString();
    }
  }
  @Ignore
  @Test
  public void testExportLinksToUserLayouts() throws Exception {
    User user = TestPropsValues.getUser();

    Group group = user.getGroup();

    Layout privateLayout = LayoutTestUtil.addLayout(group, true);
    Layout publicLayout = LayoutTestUtil.addLayout(group, false);

    PortletDataContext portletDataContextExport =
        PortletDataContextFactoryUtil.createExportPortletDataContext(
            group.getCompanyId(),
            group.getGroupId(),
            new HashMap<String, String[]>(),
            new Date(System.currentTimeMillis() - Time.HOUR),
            new Date(),
            new TestReaderWriter());

    JournalArticle journalArticle =
        JournalTestUtil.addArticle(
            group.getGroupId(), RandomTestUtil.randomString(), RandomTestUtil.randomString());

    Element rootElement = SAXReaderUtil.createElement("root");

    rootElement.addElement("entry");

    String content =
        replaceLinksToLayoutsParameters(
            getContent("layout_links_user_group.txt"), privateLayout, publicLayout);

    content =
        ExportImportHelperUtil.replaceExportContentReferences(
            portletDataContextExport, journalArticle, content, true);

    assertLinksToLayouts(content, privateLayout, 0);
    assertLinksToLayouts(content, privateLayout, privateLayout.getGroupId());
    assertLinksToLayouts(content, publicLayout, 0);
    assertLinksToLayouts(content, publicLayout, publicLayout.getGroupId());
  }
  protected long getRefererGroupId(ThemeDisplay themeDisplay) throws Exception {

    long refererGroupId = 0;

    try {
      Layout refererLayout = LayoutLocalServiceUtil.getLayout(themeDisplay.getRefererPlid());

      refererGroupId = refererLayout.getGroupId();
    } catch (NoSuchLayoutException nsle) {
    }

    return refererGroupId;
  }
  protected String getLinkToLayoutFieldValue(Layout layout, boolean includeGroupId) {

    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

    if (includeGroupId) {
      jsonObject.put("groupId", String.valueOf(layout.getGroupId()));
    }

    jsonObject.put("layoutId", String.valueOf(layout.getLayoutId()));
    jsonObject.put("privateLayout", layout.isPrivateLayout());

    return jsonObject.toString();
  }
  @Override
  public boolean isScopeIdSelectable(
      PermissionChecker permissionChecker, String scopeId, long companyGroupId, Layout layout)
      throws PortalException, SystemException {

    long groupId = getGroupIdFromScopeId(scopeId, layout.getGroupId(), layout.isPrivateLayout());

    if (scopeId.startsWith(SCOPE_ID_CHILD_GROUP_PREFIX)) {
      Group group = GroupLocalServiceUtil.getGroup(groupId);

      if (!group.hasAncestor(layout.getGroupId())) {
        return false;
      }
    } else if (scopeId.startsWith(SCOPE_ID_PARENT_GROUP_PREFIX)) {
      Group siteGroup = layout.getGroup();

      if (!siteGroup.hasAncestor(groupId)) {
        return false;
      }

      if (SitesUtil.isContentSharingWithChildrenEnabled(siteGroup)) {
        return true;
      }

      if (!PrefsPropsUtil.getBoolean(
          layout.getCompanyId(), PropsKeys.SITES_CONTENT_SHARING_THROUGH_ADMINISTRATORS_ENABLED)) {

        return false;
      }

      return GroupPermissionUtil.contains(permissionChecker, groupId, ActionKeys.UPDATE);
    } else if (groupId != companyGroupId) {
      return GroupPermissionUtil.contains(permissionChecker, groupId, ActionKeys.UPDATE);
    }

    return true;
  }
  protected void updateContentSearch(
      ActionRequest actionRequest, String portletResource, String articleId) throws Exception {

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

    Layout layout = themeDisplay.getLayout();

    _journalContentSearchLocalService.updateContentSearch(
        layout.getGroupId(),
        layout.isPrivateLayout(),
        layout.getLayoutId(),
        portletResource,
        articleId,
        true);
  }
  @Override
  public List<Layout> getAncestors() throws PortalException, SystemException {
    List<Layout> layouts = new ArrayList<Layout>();

    Layout layout = this;

    while (!layout.isRootLayout()) {
      layout =
          LayoutLocalServiceUtil.getLayout(
              layout.getGroupId(), layout.isPrivateLayout(), layout.getParentLayoutId());

      layouts.add(layout);
    }

    return layouts;
  }
  public static void addResources(Layout layout, String portletId) throws Exception {

    String rootPortletId = PortletConstants.getRootPortletId(portletId);

    String portletPrimaryKey = PortletPermissionUtil.getPrimaryKey(layout.getPlid(), portletId);

    ResourceLocalServiceUtil.addResources(
        layout.getCompanyId(),
        layout.getGroupId(),
        0,
        rootPortletId,
        portletPrimaryKey,
        true,
        true,
        true);
  }
示例#27
0
  protected void visitLayout(Element element, Layout layout, ThemeDisplay themeDisplay)
      throws PortalException, SystemException {

    UnicodeProperties typeSettingsProperties = layout.getTypeSettingsProperties();

    if (!PortalUtil.isLayoutSitemapable(layout)
        || !GetterUtil.getBoolean(typeSettingsProperties.getProperty("sitemap-include"), true)) {

      return;
    }

    String layoutFullURL = PortalUtil.getLayoutFullURL(layout, themeDisplay);

    layoutFullURL = PortalUtil.getCanonicalURL(layoutFullURL, themeDisplay, layout);

    addURLElement(
        element,
        layoutFullURL,
        typeSettingsProperties,
        layout.getModifiedDate(),
        layoutFullURL,
        getAlternateURLs(layoutFullURL, themeDisplay, layout));

    Locale[] availableLocales = LanguageUtil.getAvailableLocales(layout.getGroupId());

    if (availableLocales.length > 1) {
      Locale defaultLocale = LocaleUtil.getSiteDefault();

      for (Locale availableLocale : availableLocales) {
        if (availableLocale.equals(defaultLocale)) {
          continue;
        }

        String alternateURL =
            PortalUtil.getAlternateURL(layoutFullURL, themeDisplay, availableLocale, layout);

        addURLElement(
            element,
            alternateURL,
            typeSettingsProperties,
            layout.getModifiedDate(),
            layoutFullURL,
            getAlternateURLs(layoutFullURL, themeDisplay, layout));
      }
    }
  }
示例#28
0
  protected Map<Locale, String> getAlternateURLs(
      String canonicalURL, ThemeDisplay themeDisplay, Layout layout)
      throws PortalException, SystemException {

    Map<Locale, String> alternateURLs = new HashMap<Locale, String>();

    Locale[] availableLocales = LanguageUtil.getAvailableLocales(layout.getGroupId());

    for (Locale availableLocale : availableLocales) {
      String alternateURL =
          PortalUtil.getAlternateURL(canonicalURL, themeDisplay, availableLocale, layout);

      alternateURLs.put(availableLocale, alternateURL);
    }

    return alternateURLs;
  }
  public static void removePortletIds(HttpServletRequest request, Layout layout) throws Exception {

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

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

    List<String> portletIds = layoutTypePortlet.getPortletIds();

    for (String portletId : portletIds) {
      layoutTypePortlet.removePortletId(themeDisplay.getUserId(), portletId);
    }

    LayoutServiceUtil.updateLayout(
        layout.getGroupId(),
        layout.isPrivateLayout(),
        layout.getLayoutId(),
        layout.getTypeSettings());
  }
  @Override
  public void setAddToPagePreferences(
      PortletPreferences preferences, String portletId, ThemeDisplay themeDisplay)
      throws Exception {

    preferences.setValue("articleId", _article.getArticleId());
    preferences.setValue("groupId", String.valueOf(_article.getGroupId()));

    Layout layout = themeDisplay.getLayout();

    JournalContentSearchLocalServiceUtil.updateContentSearch(
        layout.getGroupId(),
        layout.isPrivateLayout(),
        layout.getLayoutId(),
        portletId,
        _article.getArticleId(),
        true);
  }