Example usage for com.liferay.portal.kernel.model Layout isPublicLayout

List of usage examples for com.liferay.portal.kernel.model Layout isPublicLayout

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.model Layout isPublicLayout.

Prototype

public boolean isPublicLayout();

Source Link

Document

Returns true if the current layout is part of the public LayoutSet .

Usage

From source file:com.liferay.contacts.web.internal.portlet.ContactsCenterPortlet.java

License:Open Source License

protected JSONObject getContactsJSONObject(PortletRequest portletRequest, PortletResponse portletResponse)
        throws Exception {

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

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

    String filterBy = ParamUtil.getString(portletRequest, "filterBy");
    String keywords = ParamUtil.getString(portletRequest, "keywords");
    int start = ParamUtil.getInteger(portletRequest, "start");
    int end = ParamUtil.getInteger(portletRequest, "end");

    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

    JSONObject optionsJSONObject = JSONFactoryUtil.createJSONObject();

    optionsJSONObject.put("end", end);
    optionsJSONObject.put("filterBy", filterBy);
    optionsJSONObject.put("keywords", keywords);
    optionsJSONObject.put("start", start);

    jsonObject.put("options", optionsJSONObject);

    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

    String portletId = portletDisplay.getId();

    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();

    if (filterBy.equals(ContactsConstants.FILTER_BY_DEFAULT)
            && !portletId.equals(ContactsPortletKeys.MEMBERS)) {

        List<BaseModel<?>> contacts = entryLocalService.searchUsersAndContacts(themeDisplay.getCompanyId(),
                themeDisplay.getUserId(), keywords, start, end);

        int contactsCount = entryLocalService.searchUsersAndContactsCount(themeDisplay.getCompanyId(),
                themeDisplay.getUserId(), keywords);

        jsonObject.put("count", contactsCount);

        for (BaseModel<?> contact : contacts) {
            JSONObject contactJSONObject = null;

            if (contact instanceof User) {
                contactJSONObject = getUserJSONObject(portletResponse, themeDisplay, (User) contact);
            } else {
                contactJSONObject = getEntryJSONObject(portletResponse, themeDisplay, (Entry) contact,
                        redirect);/* ww  w . j  a  v  a2  s .  c  o m*/
            }

            jsonArray.put(contactJSONObject);
        }
    } else if (filterBy.equals(ContactsConstants.FILTER_BY_FOLLOWERS)
            && !portletId.equals(ContactsPortletKeys.MEMBERS)) {

        List<SocialRelation> socialRelations = socialRelationLocalService.getInverseRelations(
                themeDisplay.getUserId(), SocialRelationConstants.TYPE_UNI_FOLLOWER, start, end);

        for (SocialRelation socialRelation : socialRelations) {
            jsonArray.put(getUserJSONObject(portletResponse, themeDisplay, socialRelation.getUserId1()));
        }
    } else if (filterBy.equals(ContactsConstants.FILTER_BY_TYPE_MY_CONTACTS)
            && !portletId.equals(ContactsPortletKeys.MEMBERS)) {

        List<Entry> entries = entryLocalService.search(themeDisplay.getUserId(), keywords, start, end);

        int entriesCount = entryLocalService.searchCount(themeDisplay.getUserId(), keywords);

        jsonObject.put("count", entriesCount);

        for (Entry entry : entries) {
            JSONObject contactJSONObject = getEntryJSONObject(portletResponse, themeDisplay, entry, redirect);

            jsonArray.put(contactJSONObject);
        }
    } else {
        LinkedHashMap<String, Object> params = new LinkedHashMap<>();

        params.put("inherit", Boolean.TRUE);

        Group group = themeDisplay.getScopeGroup();
        Layout layout = themeDisplay.getLayout();

        if (group.isUser() && layout.isPublicLayout()) {
            params.put("socialRelationType",
                    new Long[] { group.getClassPK(), (long) SocialRelationConstants.TYPE_BI_CONNECTION });
        } else if (filterBy.startsWith(ContactsConstants.FILTER_BY_TYPE)) {
            params.put("socialRelationType",
                    new Long[] { themeDisplay.getUserId(), ContactsUtil.getSocialRelationType(filterBy) });
        }

        if (portletId.equals(ContactsPortletKeys.MEMBERS)) {
            params.put("usersGroups", group.getGroupId());
        } else if (filterBy.startsWith(ContactsConstants.FILTER_BY_GROUP)) {
            params.put("usersGroups", ContactsUtil.getGroupId(filterBy));
        }

        List<User> usersList = null;

        if (filterBy.equals(ContactsConstants.FILTER_BY_ADMINS)) {
            Role siteAdministratorRole = roleLocalService.getRole(group.getCompanyId(),
                    RoleConstants.SITE_ADMINISTRATOR);

            params.put("userGroupRole", new Long[] { group.getGroupId(), siteAdministratorRole.getRoleId() });

            Set<User> users = new HashSet<>();

            users.addAll(userLocalService.search(themeDisplay.getCompanyId(), keywords,
                    WorkflowConstants.STATUS_APPROVED, params, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
                    (OrderByComparator) null));

            Role siteOwnerRole = roleLocalService.getRole(group.getCompanyId(), RoleConstants.SITE_OWNER);

            params.put("userGroupRole", new Long[] { group.getGroupId(), siteOwnerRole.getRoleId() });

            users.addAll(userLocalService.search(themeDisplay.getCompanyId(), keywords,
                    WorkflowConstants.STATUS_APPROVED, params, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
                    (OrderByComparator) null));

            usersList = new ArrayList<>(users);

            ListUtil.sort(usersList, new UserLastNameComparator(true));
        } else {
            int usersCount = userLocalService.searchCount(themeDisplay.getCompanyId(), keywords,
                    WorkflowConstants.STATUS_APPROVED, params);

            jsonObject.put("count", usersCount);

            usersList = userLocalService.search(themeDisplay.getCompanyId(), keywords,
                    WorkflowConstants.STATUS_APPROVED, params, start, end, new UserLastNameComparator(true));
        }

        for (User user : usersList) {
            JSONObject userJSONObject = getUserJSONObject(portletResponse, themeDisplay, user);

            jsonArray.put(userJSONObject);
        }
    }

    jsonObject.put("users", jsonArray);

    return jsonObject;
}

From source file:com.liferay.exportimport.content.processor.base.BaseTextExportImportContentProcessor.java

License:Open Source License

protected String replaceImportLinksToLayouts(PortletDataContext portletDataContext, String content)
        throws Exception {

    List<String> oldLinksToLayout = new ArrayList<>();
    List<String> newLinksToLayout = new ArrayList<>();

    Matcher matcher = importLinksToLayoutPattern.matcher(content);

    Map<Long, Long> layoutPlids = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(Layout.class);

    String layoutsImportMode = MapUtil.getString(portletDataContext.getParameterMap(),
            PortletDataHandlerKeys.LAYOUTS_IMPORT_MODE,
            PortletDataHandlerKeys.LAYOUTS_IMPORT_MODE_MERGE_BY_LAYOUT_UUID);

    while (matcher.find()) {
        long oldPlid = GetterUtil.getLong(matcher.group(4));

        Long newPlid = MapUtil.getLong(layoutPlids, oldPlid);

        long oldGroupId = GetterUtil.getLong(matcher.group(6));

        long newGroupId = oldGroupId;

        long oldLayoutId = GetterUtil.getLong(matcher.group(1));

        long newLayoutId = oldLayoutId;

        Layout layout = LayoutLocalServiceUtil.fetchLayout(newPlid);

        if (layout != null) {
            newGroupId = layout.getGroupId();
            newLayoutId = layout.getLayoutId();
        } else if (_log.isDebugEnabled()) {
            StringBundler sb = new StringBundler(5);

            sb.append("Unable to get layout with plid ");
            sb.append(oldPlid);/*from   w  w w .  j av a 2s .  c  om*/
            sb.append(", using layout ID  ");
            sb.append(newLayoutId);
            sb.append(" instead");

            _log.debug(sb.toString());
        }

        String oldLinkToLayout = matcher.group(0);

        String newLinkToLayout = StringUtil.replaceFirst(oldLinkToLayout,
                new String[] { StringPool.AT + oldPlid, String.valueOf(oldLayoutId) },
                new String[] { StringPool.BLANK, String.valueOf(newLayoutId) });

        if ((layout != null) && layout.isPublicLayout() && layoutsImportMode
                .equals(PortletDataHandlerKeys.LAYOUTS_IMPORT_MODE_CREATED_FROM_PROTOTYPE)) {

            newLinkToLayout = StringUtil.replace(newLinkToLayout, "private-group", "public");
        }

        if ((oldGroupId != 0) && (oldGroupId != newGroupId)) {
            newLinkToLayout = StringUtil.replaceLast(newLinkToLayout, String.valueOf(oldGroupId),
                    String.valueOf(newGroupId));
        }

        oldLinksToLayout.add(oldLinkToLayout);
        newLinksToLayout.add(newLinkToLayout);
    }

    content = StringUtil.replace(content, ArrayUtil.toStringArray(oldLinksToLayout.toArray()),
            ArrayUtil.toStringArray(newLinksToLayout.toArray()));

    return content;
}

From source file:com.liferay.exportimport.internal.content.processor.LinksToLayoutsExportImportContentProcessor.java

License:Open Source License

protected String replaceImportLinksToLayouts(PortletDataContext portletDataContext, String content)
        throws Exception {

    List<String> oldLinksToLayout = new ArrayList<>();
    List<String> newLinksToLayout = new ArrayList<>();

    Matcher matcher = _importLinksToLayoutPattern.matcher(content);

    Map<Long, Long> layoutPlids = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(Layout.class);

    String layoutsImportMode = MapUtil.getString(portletDataContext.getParameterMap(),
            PortletDataHandlerKeys.LAYOUTS_IMPORT_MODE,
            PortletDataHandlerKeys.LAYOUTS_IMPORT_MODE_MERGE_BY_LAYOUT_UUID);

    while (matcher.find()) {
        long oldPlid = GetterUtil.getLong(matcher.group(4));

        Long newPlid = MapUtil.getLong(layoutPlids, oldPlid);

        long oldGroupId = GetterUtil.getLong(matcher.group(6));

        long newGroupId = oldGroupId;

        long oldLayoutId = GetterUtil.getLong(matcher.group(1));

        long newLayoutId = oldLayoutId;

        Layout layout = _layoutLocalService.fetchLayout(newPlid);

        if (layout != null) {
            newGroupId = layout.getGroupId();
            newLayoutId = layout.getLayoutId();
        } else if (_log.isWarnEnabled()) {
            _log.warn("Unable to get layout with plid " + oldPlid);
        }//from   w  ww.  j  a  v  a 2  s . co m

        String oldLinkToLayout = matcher.group(0);

        String newLinkToLayout = StringUtil.replaceFirst(oldLinkToLayout,
                new String[] { StringPool.AT + oldPlid, String.valueOf(oldLayoutId) },
                new String[] { StringPool.BLANK, String.valueOf(newLayoutId) });

        if ((layout != null) && layout.isPublicLayout() && layoutsImportMode
                .equals(PortletDataHandlerKeys.LAYOUTS_IMPORT_MODE_CREATED_FROM_PROTOTYPE)) {

            newLinkToLayout = StringUtil.replace(newLinkToLayout, "private-group", "public");
        }

        if ((oldGroupId != 0) && (oldGroupId != newGroupId)) {
            newLinkToLayout = StringUtil.replaceLast(newLinkToLayout, String.valueOf(oldGroupId),
                    String.valueOf(newGroupId));
        }

        oldLinksToLayout.add(oldLinkToLayout);
        newLinksToLayout.add(newLinkToLayout);
    }

    content = StringUtil.replace(content, ArrayUtil.toStringArray(oldLinksToLayout.toArray()),
            ArrayUtil.toStringArray(newLinksToLayout.toArray()));

    return content;
}

From source file:com.liferay.grow.service.wrapper.LayoutCustomServiceWrapper.java

License:Open Source License

@Override
public Layout addLayout(long userId, long groupId, boolean privateLayout, long parentLayoutId, String name,
        String title, String description, String type, boolean hidden, String friendlyURL,
        ServiceContext serviceContext) throws PortalException {

    Layout layout = super.addLayout(userId, groupId, privateLayout, parentLayoutId, name, title, description,
            type, hidden, friendlyURL, serviceContext);

    try {/*w ww .j av  a 2  s. c  om*/
        Group group = layout.getGroup();

        String layoutFriendlyURL = layout.getFriendlyURL();

        String defaultUserPublicLayoutFriendlyURL = getFriendlyURL(
                PropsValues.DEFAULT_USER_PUBLIC_LAYOUT_FRIENDLY_URL);

        // Remove the Guest role's View permission for default user Profile
        // Page

        if (group.isUser() && layout.isPublicLayout()
                && layoutFriendlyURL.equals(defaultUserPublicLayoutFriendlyURL)) {

            Role guestRole = _roleLocalService.getRole(layout.getCompanyId(), RoleConstants.GUEST);

            _resourcePermissionLocalService.setResourcePermissions(layout.getCompanyId(),
                    Layout.class.getName(), ResourceConstants.SCOPE_INDIVIDUAL,
                    String.valueOf(layout.getPlid()), guestRole.getRoleId(), new String[0]);
        }
    } catch (Exception e) {
        _log.error("Cannot withdraw View permission for Layout with plid " + layout.getPlid(), e);
    }

    return layout;
}

From source file:com.liferay.journal.util.impl.JournalUtil.java

License:Open Source License

private static void _populateTokens(Map<String, String> tokens, long articleGroupId, ThemeDisplay themeDisplay)
        throws PortalException {

    Layout layout = themeDisplay.getLayout();

    Group group = layout.getGroup();

    LayoutSet layoutSet = layout.getLayoutSet();

    String friendlyUrlCurrent = null;

    if (layout.isPublicLayout()) {
        friendlyUrlCurrent = themeDisplay.getPathFriendlyURLPublic();
    } else if (group.isUserGroup()) {
        friendlyUrlCurrent = themeDisplay.getPathFriendlyURLPrivateUser();
    } else {/*from  w w  w .  j a v a  2s  .  co  m*/
        friendlyUrlCurrent = themeDisplay.getPathFriendlyURLPrivateGroup();
    }

    String layoutSetFriendlyUrl = themeDisplay.getI18nPath();

    String virtualHostname = layoutSet.getVirtualHostname();

    if (Validator.isNull(virtualHostname) || !virtualHostname.equals(themeDisplay.getServerName())) {

        layoutSetFriendlyUrl = friendlyUrlCurrent + group.getFriendlyURL();
    }

    tokens.put("article_group_id", String.valueOf(articleGroupId));
    tokens.put("cdn_host", themeDisplay.getCDNHost());
    tokens.put("company_id", String.valueOf(themeDisplay.getCompanyId()));
    tokens.put("friendly_url_current", friendlyUrlCurrent);
    tokens.put("friendly_url_private_group", themeDisplay.getPathFriendlyURLPrivateGroup());
    tokens.put("friendly_url_private_user", themeDisplay.getPathFriendlyURLPrivateUser());
    tokens.put("friendly_url_public", themeDisplay.getPathFriendlyURLPublic());
    tokens.put("group_friendly_url", group.getFriendlyURL());
    tokens.put("image_path", themeDisplay.getPathImage());
    tokens.put("layout_set_friendly_url", layoutSetFriendlyUrl);
    tokens.put("main_path", themeDisplay.getPathMain());
    tokens.put("portal_ctx", themeDisplay.getPathContext());
    tokens.put("portal_url", HttpUtil.removeProtocol(themeDisplay.getURLPortal()));
    tokens.put("protocol", HttpUtil.getProtocol(themeDisplay.getURLPortal()));
    tokens.put("root_path", themeDisplay.getPathContext());
    tokens.put("scope_group_id", String.valueOf(themeDisplay.getScopeGroupId()));
    tokens.put("site_group_id", String.valueOf(themeDisplay.getSiteGroupId()));
    tokens.put("theme_image_path", themeDisplay.getPathThemeImages());

    _populateCustomTokens(tokens, themeDisplay.getCompanyId());

    // Deprecated tokens

    tokens.put("friendly_url", themeDisplay.getPathFriendlyURLPublic());
    tokens.put("friendly_url_private", themeDisplay.getPathFriendlyURLPrivateGroup());
    tokens.put("group_id", String.valueOf(articleGroupId));
    tokens.put("page_url", themeDisplay.getPathFriendlyURLPublic());
}

From source file:com.liferay.journal.util.impl.JournalUtil.java

License:Open Source License

private static void _populateTokens(Map<String, String> tokens, long articleGroupId,
        ThemeDisplayModel themeDisplayModel) throws Exception {

    Layout layout = LayoutLocalServiceUtil.getLayout(themeDisplayModel.getPlid());

    Group group = layout.getGroup();

    LayoutSet layoutSet = layout.getLayoutSet();

    String friendlyUrlCurrent = null;

    if (layout.isPublicLayout()) {
        friendlyUrlCurrent = themeDisplayModel.getPathFriendlyURLPublic();
    } else if (group.isUserGroup()) {
        friendlyUrlCurrent = themeDisplayModel.getPathFriendlyURLPrivateUser();
    } else {/*w w  w .  java2 s  .  co m*/
        friendlyUrlCurrent = themeDisplayModel.getPathFriendlyURLPrivateGroup();
    }

    String layoutSetFriendlyUrl = themeDisplayModel.getI18nPath();

    String virtualHostname = layoutSet.getVirtualHostname();

    if (Validator.isNull(virtualHostname) || !virtualHostname.equals(themeDisplayModel.getServerName())) {

        layoutSetFriendlyUrl = friendlyUrlCurrent + group.getFriendlyURL();
    }

    tokens.put("article_group_id", String.valueOf(articleGroupId));
    tokens.put("cdn_host", themeDisplayModel.getCdnHost());
    tokens.put("company_id", String.valueOf(themeDisplayModel.getCompanyId()));
    tokens.put("friendly_url_current", friendlyUrlCurrent);
    tokens.put("friendly_url_private_group", themeDisplayModel.getPathFriendlyURLPrivateGroup());
    tokens.put("friendly_url_private_user", themeDisplayModel.getPathFriendlyURLPrivateUser());
    tokens.put("friendly_url_public", themeDisplayModel.getPathFriendlyURLPublic());
    tokens.put("group_friendly_url", group.getFriendlyURL());
    tokens.put("image_path", themeDisplayModel.getPathImage());
    tokens.put("layout_set_friendly_url", layoutSetFriendlyUrl);
    tokens.put("main_path", themeDisplayModel.getPathMain());
    tokens.put("portal_ctx", themeDisplayModel.getPathContext());
    tokens.put("portal_url", HttpUtil.removeProtocol(themeDisplayModel.getURLPortal()));
    tokens.put("protocol", HttpUtil.getProtocol(themeDisplayModel.getURLPortal()));
    tokens.put("root_path", themeDisplayModel.getPathContext());
    tokens.put("scope_group_id", String.valueOf(themeDisplayModel.getScopeGroupId()));
    tokens.put("theme_image_path", themeDisplayModel.getPathThemeImages());

    _populateCustomTokens(tokens, themeDisplayModel.getCompanyId());

    // Deprecated tokens

    tokens.put("friendly_url", themeDisplayModel.getPathFriendlyURLPublic());
    tokens.put("friendly_url_private", themeDisplayModel.getPathFriendlyURLPrivateGroup());
    tokens.put("group_id", String.valueOf(articleGroupId));
    tokens.put("page_url", themeDisplayModel.getPathFriendlyURLPublic());
}

From source file:com.liferay.site.navigation.menu.web.internal.display.context.SiteNavigationMenuDisplayContext.java

License:Open Source License

public String getItemSelectorURL() {
    ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY);

    ItemSelector itemSelector = (ItemSelector) _request.getAttribute(SiteNavigationMenuWebKeys.ITEM_SELECTOR);

    LayoutItemSelectorCriterion layoutItemSelectorCriterion = new LayoutItemSelectorCriterion();

    Layout layout = themeDisplay.getLayout();

    layoutItemSelectorCriterion.setCheckDisplayPage(false);
    layoutItemSelectorCriterion.setEnableCurrentPage(true);
    layoutItemSelectorCriterion.setShowPrivatePages(layout.isPrivateLayout());
    layoutItemSelectorCriterion.setShowPublicPages(layout.isPublicLayout());

    List<ItemSelectorReturnType> desiredItemSelectorReturnTypes = new ArrayList<>();

    desiredItemSelectorReturnTypes.add(new UUIDItemSelectorReturnType());

    layoutItemSelectorCriterion.setDesiredItemSelectorReturnTypes(desiredItemSelectorReturnTypes);

    PortletURL itemSelectorURL = itemSelector.getItemSelectorURL(
            RequestBackedPortletURLFactoryUtil.create(_request), getEventName(), layoutItemSelectorCriterion);

    itemSelectorURL.setParameter("layoutUuid", getRootLayoutUuid());

    return itemSelectorURL.toString();
}

From source file:com.liferay.social.activities.web.internal.util.SocialActivitiesQueryHelper.java

License:Open Source License

public List<SocialActivitySet> getSocialActivitySets(Group group, Layout layout, Scope scope, int start,
        int end) {

    if (scope == Scope.ALL) {
        if (!group.isUser()) {
            return _socialActivitySetLocalService.getGroupActivitySets(group.getGroupId(), start, end);
        }//from  w ww .  ja  va  2s  . c o m

        return _socialActivitySetLocalService.getUserViewableActivitySets(group.getClassPK(), start, end);
    } else if (group.isOrganization()) {
        return _socialActivitySetLocalService.getOrganizationActivitySets(group.getOrganizationId(), start,
                end);
    } else if (!group.isUser()) {
        return _socialActivitySetLocalService.getGroupActivitySets(group.getGroupId(), start, end);
    } else if (layout.isPublicLayout() || (scope == Scope.ME)) {
        return _socialActivitySetLocalService.getUserActivitySets(group.getClassPK(), start, end);
    } else if (scope == Scope.CONNECTIONS) {
        return _socialActivitySetLocalService.getRelationActivitySets(group.getClassPK(),
                SocialRelationConstants.TYPE_BI_CONNECTION, start, end);
    } else if (scope == Scope.FOLLOWING) {
        return _socialActivitySetLocalService.getRelationActivitySets(group.getClassPK(),
                SocialRelationConstants.TYPE_UNI_FOLLOWER, start, end);
    } else if (scope == Scope.MY_SITES) {
        return _socialActivitySetLocalService.getUserGroupsActivitySets(group.getClassPK(), start, end);
    } else {
        return Collections.emptyList();
    }
}

From source file:com.liferay.social.activities.web.internal.util.SocialActivitiesQueryHelper.java

License:Open Source License

public int getSocialActivitySetsCount(Group group, Layout layout, Scope scope) {

    if (scope == Scope.ALL) {
        if (!group.isUser()) {
            return _socialActivitySetLocalService.getGroupActivitySetsCount(group.getGroupId());
        }//  w  w w  .j  a  va  2 s.  c  o m

        return _socialActivitySetLocalService.getUserViewableActivitySetsCount(group.getClassPK());
    } else if (group.isOrganization()) {
        return _socialActivitySetLocalService.getOrganizationActivitySetsCount(group.getOrganizationId());
    } else if (!group.isUser()) {
        return _socialActivitySetLocalService.getGroupActivitySetsCount(group.getGroupId());
    } else if (layout.isPublicLayout() || (scope == Scope.ME)) {
        return _socialActivitySetLocalService.getUserActivitySetsCount(group.getClassPK());
    } else if (scope == Scope.CONNECTIONS) {
        return _socialActivitySetLocalService.getRelationActivitySetsCount(group.getClassPK(),
                SocialRelationConstants.TYPE_BI_CONNECTION);
    } else if (scope == Scope.FOLLOWING) {
        return _socialActivitySetLocalService.getRelationActivitySetsCount(group.getClassPK(),
                SocialRelationConstants.TYPE_UNI_FOLLOWER);
    } else if (scope == Scope.MY_SITES) {
        return _socialActivitySetLocalService.getUserGroupsActivitySetsCount(group.getClassPK());
    } else {
        return 0;
    }
}

From source file:com.liferay.wiki.web.internal.portlet.action.ActionUtil.java

License:Open Source License

public static WikiNode getFirstVisibleNode(PortletRequest portletRequest) throws PortalException {

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

    WikiNode node = null;/*from  w  ww .jav a2 s  . co m*/

    int nodesCount = WikiNodeLocalServiceUtil.getNodesCount(themeDisplay.getScopeGroupId());

    if (nodesCount == 0) {
        Layout layout = themeDisplay.getLayout();

        ServiceContext serviceContext = ServiceContextFactory.getInstance(WikiNode.class.getName(),
                portletRequest);

        serviceContext.setAddGroupPermissions(true);

        if (layout.isPublicLayout() || layout.isTypeControlPanel()) {
            serviceContext.setAddGuestPermissions(true);
        } else {
            serviceContext.setAddGuestPermissions(false);
        }

        node = WikiNodeLocalServiceUtil.addDefaultNode(themeDisplay.getDefaultUserId(), serviceContext);
    } else {
        node = getFirstNode(portletRequest);

        if (node == null) {
            throw new PrincipalException();
        }

        return node;
    }

    return node;
}