List of usage examples for com.liferay.portal.kernel.theme ThemeDisplay getPortletDisplay
@JSON(include = false)
public PortletDisplay getPortletDisplay()
From source file:com.liferay.bookmarks.web.internal.portlet.toolbar.contributor.BookmarksPortletToolbarContributor.java
License:Open Source License
protected void addPortletTitleAddFolderMenuItem(List<MenuItem> menuItems, BookmarksFolder folder, ThemeDisplay themeDisplay, PortletRequest portletRequest) throws PortalException { long folderId = _getFolderId(folder); if (!containsPermission(themeDisplay.getPermissionChecker(), themeDisplay.getScopeGroupId(), folderId, ActionKeys.ADD_FOLDER)) {/*from w w w . j a v a 2 s .c o m*/ return; } URLMenuItem urlMenuItem = new URLMenuItem(); urlMenuItem.setLabel(LanguageUtil.get(PortalUtil.getHttpServletRequest(portletRequest), (folder != null) ? "subfolder" : "folder")); PortletDisplay portletDisplay = themeDisplay.getPortletDisplay(); PortletURL portletURL = PortletURLFactoryUtil.create(portletRequest, portletDisplay.getId(), themeDisplay.getPlid(), PortletRequest.RENDER_PHASE); portletURL.setParameter("mvcRenderCommandName", "/bookmarks/edit_folder"); portletURL.setParameter("redirect", PortalUtil.getCurrentURL(portletRequest)); portletURL.setParameter("parentFolderId", String.valueOf(folderId)); urlMenuItem.setURL(portletURL.toString()); menuItems.add(urlMenuItem); }
From source file:com.liferay.bookmarks.web.internal.portlet.util.BookmarksUtil.java
License:Open Source License
public static Map<String, String> getEmailDefinitionTerms(PortletRequest portletRequest, String emailFromAddress, String emailFromName) { ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY); Map<String, String> definitionTerms = new LinkedHashMap<>(); definitionTerms.put("[$BOOKMARKS_ENTRY_USER_NAME$]", LanguageUtil.get(themeDisplay.getLocale(), "the-user-who-added-the-bookmark-entry")); definitionTerms.put("[$BOOKMARKS_ENTRY_STATUS_BY_USER_NAME$]", LanguageUtil.get(themeDisplay.getLocale(), "the-user-who-updated-the-bookmark-entry")); definitionTerms.put("[$BOOKMARKS_ENTRY_URL$]", LanguageUtil.get(themeDisplay.getLocale(), "the-bookmark-entry-url")); definitionTerms.put("[$FROM_ADDRESS$]", HtmlUtil.escape(emailFromAddress)); definitionTerms.put("[$FROM_NAME$]", HtmlUtil.escape(emailFromName)); Company company = themeDisplay.getCompany(); definitionTerms.put("[$PORTAL_URL$]", company.getVirtualHostname()); PortletDisplay portletDisplay = themeDisplay.getPortletDisplay(); definitionTerms.put("[$PORTLET_NAME$]", HtmlUtil.escape(portletDisplay.getTitle())); definitionTerms.put("[$TO_ADDRESS$]", LanguageUtil.get(themeDisplay.getLocale(), "the-address-of-the-email-recipient")); definitionTerms.put("[$TO_NAME$]", LanguageUtil.get(themeDisplay.getLocale(), "the-name-of-the-email-recipient")); return definitionTerms; }
From source file:com.liferay.comment.taglib.servlet.taglib.DiscussionTag.java
License:Open Source License
protected String getPaginationURL(HttpServletRequest request) { ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); PortletDisplay portletDisplay = themeDisplay.getPortletDisplay(); String portletId = portletDisplay.getId(); return StringBundler.concat(themeDisplay.getPathMain(), "/portal/comment/discussion/get_comments?p_p_isolated=1&", "portletId=", portletId); }
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 w w w . j a v a2 s . c om } 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.ActionUtil.java
License:Open Source License
public static Folder getFolder(HttpServletRequest request) throws PortalException { ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); long folderId = ParamUtil.getLong(request, "folderId"); boolean ignoreRootFolder = ParamUtil.getBoolean(request, "ignoreRootFolder"); if ((folderId <= 0) && !ignoreRootFolder) { PortletDisplay portletDisplay = themeDisplay.getPortletDisplay(); String portletId = portletDisplay.getId(); PortletPreferences portletPreferences = PortletPreferencesFactoryUtil.getPortletPreferences(request, portletId);/*w w w . ja va 2 s .c om*/ folderId = GetterUtil.getLong(portletPreferences.getValue("rootFolderId", null)); } Folder folder = null; if (folderId > 0) { folder = DLAppServiceUtil.getFolder(folderId); if (folder.getModel() instanceof DLFolder) { DLFolder dlFolder = (DLFolder) folder.getModel(); if (dlFolder.isInTrash()) { throw new NoSuchFolderException("{folderId=" + folderId + "}"); } } } else { DLPermission.check(themeDisplay.getPermissionChecker(), themeDisplay.getScopeGroupId(), ActionKeys.VIEW); } return folder; }
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 {// w w w. j a v a2s . 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 a2 s . c o m*/ } 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); } }
From source file:com.liferay.document.library.web.internal.portlet.action.EditRepositoryMVCActionCommand.java
License:Open Source License
protected void updateRepository(ActionRequest actionRequest) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); PortletDisplay portletDisplay = themeDisplay.getPortletDisplay(); long repositoryId = ParamUtil.getLong(actionRequest, "repositoryId"); String className = ParamUtil.getString(actionRequest, "className"); long classNameId = _portal.getClassNameId(className); long folderId = ParamUtil.getLong(actionRequest, "folderId"); String name = ParamUtil.getString(actionRequest, "name"); String description = ParamUtil.getString(actionRequest, "description"); UnicodeProperties typeSettingsProperties = PropertiesParamUtil.getProperties(actionRequest, "settings--"); ServiceContext serviceContext = ServiceContextFactory.getInstance(DLFolder.class.getName(), actionRequest); if (repositoryId <= 0) { // Add repository _repositoryService.addRepository(themeDisplay.getScopeGroupId(), classNameId, folderId, name, description, portletDisplay.getId(), typeSettingsProperties, serviceContext); } else {// www.ja v a 2s . c o m // Update repository _repositoryService.updateRepository(repositoryId, name, description); } }
From source file:com.liferay.document.library.web.internal.portlet.configuration.icon.AccessFromDesktopPortletConfigurationIcon.java
License:Open Source License
@Override public boolean isShow(PortletRequest portletRequest) { try {/* w w w . j ava 2 s. c o m*/ ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY); PortletDisplay portletDisplay = themeDisplay.getPortletDisplay(); long folderId = DLFolderConstants.DEFAULT_PARENT_FOLDER_ID; Folder folder = ActionUtil.getFolder(portletRequest); if (folder != null) { folderId = folder.getFolderId(); } if (DLFolderPermission.contains(themeDisplay.getPermissionChecker(), themeDisplay.getScopeGroupId(), folderId, ActionKeys.VIEW) && portletDisplay.isWebDAVEnabled() && ((folder == null) || (folder.getRepositoryId() == themeDisplay.getScopeGroupId()))) { return true; } } catch (Exception e) { } return false; }
From source file:com.liferay.document.library.web.internal.portlet.configuration.icon.MetadataSetsPortletConfigurationIcon.java
License:Open Source License
@Override public String getURL(PortletRequest portletRequest, PortletResponse portletResponse) { ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY); PortletDisplay portletDisplay = themeDisplay.getPortletDisplay(); Portlet portlet = _portletLocalService.getPortletById(portletDisplay.getId()); PortletURL portletURL = PortletURLFactoryUtil.create(portletRequest, PortletProviderUtil.getPortletId(DDMStructure.class.getName(), PortletProvider.Action.VIEW), PortletRequest.RENDER_PHASE); portletURL.setParameter("mvcPath", "/view.jsp"); portletURL.setParameter("backURL", themeDisplay.getURLCurrent()); portletURL.setParameter("groupId", String.valueOf(themeDisplay.getScopeGroupId())); portletURL.setParameter("refererPortletName", DLPortletKeys.DOCUMENT_LIBRARY); portletURL.setParameter("refererWebDAVToken", WebDAVUtil.getStorageToken(portlet)); portletURL.setParameter("showAncestorScopes", Boolean.TRUE.toString()); portletURL.setParameter("showManageTemplates", Boolean.FALSE.toString()); return portletURL.toString(); }