Example usage for com.liferay.portal.kernel.theme ThemeDisplay getLayout

List of usage examples for com.liferay.portal.kernel.theme ThemeDisplay getLayout

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.theme ThemeDisplay getLayout.

Prototype

public Layout getLayout() 

Source Link

Document

Returns the site's page.

Usage

From source file:com.liferay.asset.publisher.web.internal.portlet.toolbar.contributor.AssetPublisherPortletToolbarContributor.java

License:Open Source License

private boolean _isVisible(AssetPublisherDisplayContext assetPublisherDisplayContext,
        PortletRequest portletRequest) {

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

    if (!assetPublisherDisplayContext.isShowAddContentButton()) {
        return false;
    }//from w ww  . j  a va 2  s .co  m

    Group scopeGroup = themeDisplay.getScopeGroup();

    if (scopeGroup.hasStagingGroup() && !scopeGroup.isStagingGroup()
            && PropsValues.STAGING_LIVE_GROUP_LOCKING_ENABLED) {

        return false;
    }

    Layout layout = themeDisplay.getLayout();

    if (layout.isLayoutPrototypeLinkActive() && assetPublisherDisplayContext.isSelectionStyleManual()) {

        return false;
    }

    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

    String portletName = portletDisplay.getPortletName();

    if (portletName.equals(AssetPublisherPortletKeys.HIGHEST_RATED_ASSETS)) {

        return false;
    }

    if (portletName.equals(AssetPublisherPortletKeys.MOST_VIEWED_ASSETS)) {
        return false;
    }

    if (portletName.equals(AssetPublisherPortletKeys.RELATED_ASSETS)) {
        return false;
    }

    return true;
}

From source file:com.liferay.asset.publisher.web.portlet.action.AssetPublisherConfigurationAction.java

License:Open Source License

protected void checkPermission(ActionRequest actionRequest, String scopeId) throws Exception {

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

    Layout layout = themeDisplay.getLayout();

    if (!assetPublisherWebUtil.isScopeIdSelectable(themeDisplay.getPermissionChecker(), scopeId,
            themeDisplay.getCompanyGroupId(), layout, true)) {

        throw new PrincipalException();
    }//from ww w  . j  a v a2s.co m
}

From source file:com.liferay.asset.publisher.web.servlet.taglib.ui.BaseConfigurationFormNavigatorEntry.java

License:Open Source License

protected boolean isDynamicAssetSelection() {
    ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();

    ThemeDisplay themeDisplay = serviceContext.getThemeDisplay();

    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

    PortletPreferences portletSetup = themeDisplay.getStrictLayoutPortletSetup(themeDisplay.getLayout(),
            portletDisplay.getPortletResource());

    String selectionStyle = GetterUtil.getString(portletSetup.getValue("selectionStyle", null), "dynamic");

    if (Objects.equals(selectionStyle, "dynamic")) {
        return true;
    }//from w w  w  . ja v  a 2 s. co  m

    return false;
}

From source file:com.liferay.asset.publisher.web.util.AssetPublisherUtil.java

License:Open Source License

public static void addAndStoreSelection(PortletRequest portletRequest, String className, long classPK,
        int assetEntryOrder) throws Exception {

    String portletId = PortalUtil.getPortletId(portletRequest);

    String rootPortletId = PortletIdCodec.decodePortletName(portletId);

    if (!rootPortletId.equals(AssetPublisherPortletKeys.ASSET_PUBLISHER)) {
        return;//from ww  w  .  j  a  va  2s  . co  m
    }

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

    Layout layout = themeDisplay.getLayout();

    PortletPreferences portletPreferences = PortletPreferencesFactoryUtil.getStrictPortletSetup(layout,
            portletId);

    if (portletPreferences instanceof StrictPortletPreferencesImpl) {
        return;
    }

    String selectionStyle = portletPreferences.getValue("selectionStyle", "dynamic");

    if (selectionStyle.equals("dynamic")) {
        return;
    }

    AssetEntry assetEntry = _assetEntryLocalService.getEntry(className, classPK);

    addSelection(themeDisplay, portletPreferences, portletId, assetEntry.getEntryId(), assetEntryOrder,
            className);

    portletPreferences.store();
}

From source file:com.liferay.asset.publisher.web.util.AssetRSSUtil.java

License:Open Source License

protected static String getAssetPublisherURL(PortletRequest portletRequest) throws Exception {

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

    Layout layout = themeDisplay.getLayout();

    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

    StringBundler sb = new StringBundler(6);

    String layoutFriendlyURL = GetterUtil.getString(PortalUtil.getLayoutFriendlyURL(layout, themeDisplay));

    if (!layoutFriendlyURL.startsWith(Http.HTTP_WITH_SLASH)
            && !layoutFriendlyURL.startsWith(Http.HTTPS_WITH_SLASH)) {

        sb.append(themeDisplay.getPortalURL());
    }/*from  w w  w. ja  v a 2 s .  co  m*/

    sb.append(layoutFriendlyURL);
    sb.append(Portal.FRIENDLY_URL_SEPARATOR);
    sb.append("asset_publisher/");
    sb.append(portletDisplay.getInstanceId());
    sb.append(StringPool.SLASH);

    return sb.toString();
}

From source file:com.liferay.asset.publisher.web.util.DefaultAssetPublisherCustomizer.java

License:Open Source License

@Override
public void setAssetEntryQueryOptions(AssetEntryQuery assetEntryQuery, HttpServletRequest request) {

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

    PortletPreferences portletPreferences = getPortletPreferences(request);

    long[] groupIds = AssetPublisherUtil.getGroupIds(portletPreferences, themeDisplay.getScopeGroupId(),
            themeDisplay.getLayout());

    assetEntryQuery.setGroupIds(groupIds);
}

From source file:com.liferay.blogs.web.internal.portlet.action.RSSAction.java

License:Open Source License

@Override
protected byte[] getRSS(HttpServletRequest request) throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    Layout layout = themeDisplay.getLayout();

    long plid = ParamUtil.getLong(request, "p_l_id");

    if (plid == LayoutConstants.DEFAULT_PLID) {
        plid = themeDisplay.getPlid();//from   w  ww.j  a v a2s .c om
    }

    long companyId = ParamUtil.getLong(request, "companyId");
    long groupId = ParamUtil.getLong(request, "groupId");
    long organizationId = ParamUtil.getLong(request, "organizationId");
    int status = WorkflowConstants.STATUS_APPROVED;
    int max = ParamUtil.getInteger(request, "max", SearchContainer.DEFAULT_DELTA);
    String type = ParamUtil.getString(request, "type", RSSUtil.FORMAT_DEFAULT);
    double version = ParamUtil.getDouble(request, "version", RSSUtil.VERSION_DEFAULT);
    String displayStyle = ParamUtil.getString(request, "displayStyle", RSSUtil.DISPLAY_STYLE_DEFAULT);

    String feedURL = themeDisplay.getPortalURL() + themeDisplay.getPathMain() + "/blogs/find_entry?";

    String entryURL = feedURL;

    String rss = StringPool.BLANK;

    if (companyId > 0) {
        feedURL = StringPool.BLANK;

        rss = _blogsEntryService.getCompanyEntriesRSS(companyId, new Date(), status, max, type, version,
                displayStyle, feedURL, entryURL, themeDisplay);
    } else if (groupId > 0) {
        feedURL += "p_l_id=" + plid;

        entryURL = feedURL;

        rss = _blogsEntryService.getGroupEntriesRSS(groupId, new Date(), status, max, type, version,
                displayStyle, feedURL, entryURL, themeDisplay);
    } else if (organizationId > 0) {
        feedURL = StringPool.BLANK;

        rss = _blogsEntryService.getOrganizationEntriesRSS(organizationId, new Date(), status, max, type,
                version, displayStyle, feedURL, entryURL, themeDisplay);
    } else if (layout != null) {
        groupId = themeDisplay.getScopeGroupId();

        feedURL = themeDisplay.getPathMain() + "/blogs/rss";

        entryURL = feedURL;

        rss = _blogsEntryService.getGroupEntriesRSS(groupId, new Date(), status, max, type, version,
                displayStyle, feedURL, entryURL, themeDisplay);
    }

    return rss.getBytes(StringPool.UTF8);
}

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);/*from   ww  w.  java2  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.document.library.web.internal.portlet.action.EditFileEntryMVCActionCommand.java

License:Open Source License

protected String[] getAllowedFileExtensions(PortletConfig portletConfig, PortletRequest portletRequest,
        PortletResponse portletResponse) throws PortalException {

    String portletName = portletConfig.getPortletName();

    if (!portletName.equals(DLPortletKeys.MEDIA_GALLERY_DISPLAY)) {
        return PrefsPropsUtil.getStringArray(PropsKeys.DL_FILE_EXTENSIONS, StringPool.COMMA);
    } else {//from  ww  w. j a v a 2 s . co  m
        ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

        PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

        DLPortletInstanceSettings dlPortletInstanceSettings = DLPortletInstanceSettings
                .getInstance(themeDisplay.getLayout(), portletDisplay.getId());

        Set<String> extensions = new HashSet<>();

        String[] mimeTypes = dlPortletInstanceSettings.getMimeTypes();

        for (String mimeType : mimeTypes) {
            extensions.addAll(MimeTypesUtil.getExtensions(mimeType));
        }

        return extensions.toArray(new String[extensions.size()]);
    }
}

From source file:com.liferay.document.library.web.internal.portlet.action.EditFileEntryMVCActionCommand.java

License:Open Source License

protected FileEntry updateFileEntry(PortletConfig portletConfig, ActionRequest actionRequest,
        ActionResponse actionResponse) throws Exception {

    UploadPortletRequest uploadPortletRequest = _portal.getUploadPortletRequest(actionRequest);

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

    String cmd = ParamUtil.getString(uploadPortletRequest, Constants.CMD);

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

    long repositoryId = ParamUtil.getLong(uploadPortletRequest, "repositoryId");
    long folderId = ParamUtil.getLong(uploadPortletRequest, "folderId");
    String sourceFileName = uploadPortletRequest.getFileName("file");
    String title = ParamUtil.getString(uploadPortletRequest, "title");
    String description = ParamUtil.getString(uploadPortletRequest, "description");
    String changeLog = ParamUtil.getString(uploadPortletRequest, "changeLog");
    boolean majorVersion = ParamUtil.getBoolean(uploadPortletRequest, "majorVersion");

    if (folderId > 0) {
        Folder folder = _dlAppService.getFolder(folderId);

        if (folder.getGroupId() != themeDisplay.getScopeGroupId()) {
            throw new NoSuchFolderException("{folderId=" + folderId + "}");
        }/*from   w  w  w.  j av  a 2 s.com*/
    }

    InputStream inputStream = null;

    if (cmd.equals(Constants.ADD_DYNAMIC)) {
        title = uploadPortletRequest.getFileName("file");
    }

    try {
        String contentType = uploadPortletRequest.getContentType("file");
        long size = uploadPortletRequest.getSize("file");

        if ((cmd.equals(Constants.ADD) || cmd.equals(Constants.ADD_DYNAMIC)) && (size == 0)) {

            contentType = MimeTypesUtil.getContentType(title);
        }

        if (cmd.equals(Constants.ADD) || cmd.equals(Constants.ADD_DYNAMIC) || (size > 0)) {

            String portletName = portletConfig.getPortletName();

            if (portletName.equals(DLPortletKeys.MEDIA_GALLERY_DISPLAY)) {
                PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

                DLPortletInstanceSettings dlPortletInstanceSettings = DLPortletInstanceSettings
                        .getInstance(themeDisplay.getLayout(), portletDisplay.getId());

                String[] mimeTypes = dlPortletInstanceSettings.getMimeTypes();

                if (Arrays.binarySearch(mimeTypes, contentType) < 0) {
                    throw new FileMimeTypeException(contentType);
                }
            }
        }

        inputStream = uploadPortletRequest.getFileAsStream("file");

        ServiceContext serviceContext = ServiceContextFactory.getInstance(DLFileEntry.class.getName(),
                uploadPortletRequest);

        FileEntry fileEntry = null;

        if (cmd.equals(Constants.ADD) || cmd.equals(Constants.ADD_DYNAMIC)) {

            // Add file entry

            fileEntry = _dlAppService.addFileEntry(repositoryId, folderId, sourceFileName, contentType, title,
                    description, changeLog, inputStream, size, serviceContext);

            if (cmd.equals(Constants.ADD_DYNAMIC)) {
                JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

                jsonObject.put("fileEntryId", fileEntry.getFileEntryId());

                JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject);
            }
        } else if (cmd.equals(Constants.UPDATE_AND_CHECKIN)) {

            // Update file entry and checkin

            fileEntry = _dlAppService.updateFileEntryAndCheckIn(fileEntryId, sourceFileName, contentType, title,
                    description, changeLog, majorVersion, inputStream, size, serviceContext);
        } else {

            // Update file entry

            fileEntry = _dlAppService.updateFileEntry(fileEntryId, sourceFileName, contentType, title,
                    description, changeLog, majorVersion, inputStream, size, serviceContext);
        }

        return fileEntry;
    } finally {
        StreamUtil.cleanUp(inputStream);
    }
}