List of usage examples for com.liferay.portal.kernel.service ServiceContext getThemeDisplay
public ThemeDisplay getThemeDisplay()
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 ww w. ja va 2 s .c om*/ return false; }
From source file:com.liferay.asset.publisher.web.servlet.taglib.ui.OrderingAndGroupingFormNavigatorEntry.java
License:Open Source License
@Override public boolean isVisible(User user, Object object) { if (!isDynamicAssetSelection()) { return false; }//from w w w. j a va 2 s . c om ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext(); ThemeDisplay themeDisplay = serviceContext.getThemeDisplay(); PortletDisplay portletDisplay = themeDisplay.getPortletDisplay(); Portlet portlet = _portletLocalService.getPortletById(themeDisplay.getCompanyId(), portletDisplay.getPortletResource()); AssetPublisherCustomizer assetPublisherCustomizer = assetPublisherCustomizerRegistry .getAssetPublisherCustomizer(portlet.getRootPortletId()); if (assetPublisherCustomizer == null) { return true; } return assetPublisherCustomizer.isOrderingAndGroupingEnabled(serviceContext.getRequest()); }
From source file:com.liferay.asset.publisher.web.servlet.taglib.ui.ScopeFormNavigatorEntry.java
License:Open Source License
@Override public boolean isVisible(User user, Object object) { if (!isDynamicAssetSelection()) { return true; }/* ww w. j a v a 2s. c om*/ ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext(); ThemeDisplay themeDisplay = serviceContext.getThemeDisplay(); PortletDisplay portletDisplay = themeDisplay.getPortletDisplay(); String rootPortletId = PortletIdCodec.decodePortletName(portletDisplay.getPortletName()); if (rootPortletId.equals(AssetPublisherPortletKeys.RELATED_ASSETS)) { return false; } return true; }
From source file:com.liferay.blogs.service.impl.BlogsEntryLocalServiceImpl.java
License:Open Source License
protected BlogsEntry startWorkflowInstance(long userId, BlogsEntry entry, ServiceContext serviceContext) throws PortalException { Map<String, Serializable> workflowContext = new HashMap<>(); workflowContext.put(WorkflowConstants.CONTEXT_URL, getEntryURL(entry, serviceContext)); String userPortraitURL = StringPool.BLANK; String userURL = StringPool.BLANK; if (serviceContext.getThemeDisplay() != null) { User user = userPersistence.findByPrimaryKey(userId); userPortraitURL = user.getPortraitURL(serviceContext.getThemeDisplay()); userURL = user.getDisplayURL(serviceContext.getThemeDisplay()); }/* ww w. j a v a 2 s. c o m*/ workflowContext.put(WorkflowConstants.CONTEXT_USER_PORTRAIT_URL, userPortraitURL); workflowContext.put(WorkflowConstants.CONTEXT_USER_URL, userURL); return WorkflowHandlerRegistryUtil.startWorkflowInstance(entry.getCompanyId(), entry.getGroupId(), userId, BlogsEntry.class.getName(), entry.getEntryId(), entry, serviceContext, workflowContext); }
From source file:com.liferay.contacts.web.internal.notifications.ContactsCenterUserNotificationHandler.java
License:Open Source License
protected String getUserNameLink(long userId, ServiceContext serviceContext) { try {//from ww w. j a v a 2 s. c o m if (userId <= 0) { return StringPool.BLANK; } User user = _userLocalService.getUserById(userId); String userName = user.getFullName(); String userDisplayURL = user.getDisplayURL(serviceContext.getThemeDisplay()); return StringBundler.concat("<a href=\"", userDisplayURL, "\">", HtmlUtil.escape(userName), "</a>"); } catch (Exception e) { return StringPool.BLANK; } }
From source file:com.liferay.document.library.web.internal.social.DLFileEntryActivityInterpreter.java
License:Open Source License
@Override protected String getBody(SocialActivity activity, ServiceContext serviceContext) throws Exception { FileEntry fileEntry = _dlAppLocalService.getFileEntry(activity.getClassPK()); if (fileEntry.getModel() instanceof DLFileEntry) { DLFileEntry dlFileEntry = (DLFileEntry) fileEntry.getModel(); if (dlFileEntry.isInTrash()) { return StringPool.BLANK; }/*from ww w . ja v a 2s .co m*/ } StringBundler sb = new StringBundler(3); AssetRendererFactory<?> assetRendererFactory = AssetRendererFactoryRegistryUtil .getAssetRendererFactoryByClassName(DLFileEntry.class.getName()); AssetRenderer<?> assetRenderer = assetRendererFactory.getAssetRenderer(fileEntry.getFileEntryId()); String fileEntryLink = assetRenderer.getURLDownload(serviceContext.getThemeDisplay()); sb.append(wrapLink(fileEntryLink, "download-file", serviceContext)); sb.append(StringPool.SPACE); String folderLink = getFolderLink(fileEntry, serviceContext); folderLink = addNoSuchEntryRedirect(folderLink, DLFolder.class.getName(), fileEntry.getFolderId(), serviceContext); sb.append(wrapLink(folderLink, "go-to-folder", serviceContext)); return sb.toString(); }
From source file:com.liferay.document.library.web.social.DLFileEntryActivityInterpreter.java
License:Open Source License
@Override protected String getBody(SocialActivity activity, ServiceContext serviceContext) throws Exception { FileEntry fileEntry = _dlAppLocalService.getFileEntry(activity.getClassPK()); if (TrashUtil.isInTrash(DLFileEntry.class.getName(), fileEntry.getFileEntryId())) { return StringPool.BLANK; }/* www.jav a 2 s.c o m*/ StringBundler sb = new StringBundler(3); AssetRendererFactory<?> assetRendererFactory = AssetRendererFactoryRegistryUtil .getAssetRendererFactoryByClassName(DLFileEntry.class.getName()); AssetRenderer<?> assetRenderer = assetRendererFactory.getAssetRenderer(fileEntry.getFileEntryId()); String fileEntryLink = assetRenderer.getURLDownload(serviceContext.getThemeDisplay()); sb.append(wrapLink(fileEntryLink, "download-file", serviceContext)); sb.append(StringPool.SPACE); String folderLink = getFolderLink(fileEntry, serviceContext); folderLink = addNoSuchEntryRedirect(folderLink, DLFolder.class.getName(), fileEntry.getFolderId(), serviceContext); sb.append(wrapLink(folderLink, "go-to-folder", serviceContext)); return sb.toString(); }
From source file:com.liferay.exportimport.content.processor.base.BaseTextExportImportContentProcessor.java
License:Open Source License
protected void validateDLReferences(long groupId, String content) throws PortalException { String portalURL = PortalUtil.getPathContext(); ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext(); if ((serviceContext != null) && (serviceContext.getThemeDisplay() != null)) { ThemeDisplay themeDisplay = serviceContext.getThemeDisplay(); portalURL = PortalUtil.getPortalURL(themeDisplay) + PortalUtil.getPathContext(); }/* ww w .j ava 2s. co m*/ String[] patterns = { portalURL.concat("/c/document_library/get_file?"), portalURL.concat("/documents/"), portalURL.concat("/image/image_gallery?") }; String[] completePatterns = new String[patterns.length]; long[] companyIds = PortalUtil.getCompanyIds(); for (long companyId : companyIds) { Company company = CompanyLocalServiceUtil.getCompany(companyId); String webId = company.getWebId(); int i = 0; for (String pattern : patterns) { completePatterns[i] = webId.concat(pattern); i++; } int beginPos = -1; int endPos = content.length(); while (true) { beginPos = StringUtil.lastIndexOfAny(content, completePatterns, endPos); if (beginPos == -1) { break; } Map<String, String[]> dlReferenceParameters = getDLReferenceParameters(groupId, content, beginPos + portalURL.length() + webId.length(), endPos); FileEntry fileEntry = getFileEntry(dlReferenceParameters); if (fileEntry == null) { throw new NoSuchFileEntryException(); } endPos = beginPos - 1; } } }
From source file:com.liferay.exportimport.internal.content.processor.DLReferencesExportImportContentProcessor.java
License:Open Source License
protected void validateDLReferences(long groupId, String content) throws PortalException { String portalURL = _portal.getPathContext(); ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext(); if ((serviceContext != null) && (serviceContext.getThemeDisplay() != null)) { ThemeDisplay themeDisplay = serviceContext.getThemeDisplay(); portalURL = _portal.getPortalURL(themeDisplay) + _portal.getPathContext(); }/* w w w. j a va 2s . co m*/ String[] patterns = { portalURL.concat("/c/document_library/get_file?"), portalURL.concat("/documents/"), portalURL.concat("/image/image_gallery?") }; String[] completePatterns = new String[patterns.length]; long[] companyIds = _portal.getCompanyIds(); for (long companyId : companyIds) { Company company = _companyLocalService.getCompany(companyId); String webId = company.getWebId(); int i = 0; for (String pattern : patterns) { completePatterns[i] = webId.concat(pattern); i++; } int beginPos = -1; int endPos = content.length(); while (true) { beginPos = StringUtil.lastIndexOfAny(content, completePatterns, endPos); if (beginPos == -1) { break; } Map<String, String[]> dlReferenceParameters = getDLReferenceParameters(groupId, content, beginPos + portalURL.length() + webId.length(), endPos); FileEntry fileEntry = getFileEntry(dlReferenceParameters); if (fileEntry == null) { StringBundler sb = new StringBundler(4); sb.append("Validation failed for a referenced file entry "); sb.append("because a file entry could not be found with "); sb.append("the following parameters: "); sb.append(dlReferenceParameters); throw new NoSuchFileEntryException(sb.toString()); } endPos = beginPos - 1; } } }
From source file:com.liferay.flags.internal.messaging.FlagsRequestMessageListener.java
License:Open Source License
@Override protected void doReceive(Message message) throws Exception { FlagsRequest flagsRequest = (FlagsRequest) message.getPayload(); // Service context ServiceContext serviceContext = flagsRequest.getServiceContext(); // Company//from www .ja v a2 s . co m long companyId = serviceContext.getCompanyId(); Company company = _companyLocalService.getCompany(serviceContext.getCompanyId()); // Group Layout layout = _layoutLocalService.getLayout(serviceContext.getPlid()); Group group = layout.getGroup(); // Reporter user String reporterUserName = null; String reporterEmailAddress = null; User reporterUser = _userLocalService.getUserById(serviceContext.getUserId()); Locale locale = LocaleUtil.getDefault(); if (reporterUser.isDefaultUser()) { reporterUserName = LanguageUtil.get(locale, "anonymous"); } else { reporterUserName = reporterUser.getFullName(); reporterEmailAddress = reporterUser.getEmailAddress(); } // Reported user String reportedUserName = StringPool.BLANK; String reportedEmailAddress = StringPool.BLANK; String reportedURL = StringPool.BLANK; User reportedUser = _userLocalService.getUserById(flagsRequest.getReportedUserId()); if (reportedUser.isDefaultUser()) { reportedUserName = group.getDescriptiveName(); } else { reportedUserName = reportedUser.getFullName(); reportedEmailAddress = reportedUser.getEmailAddress(); reportedURL = reportedUser.getDisplayURL(serviceContext.getThemeDisplay()); } // Content String contentType = ResourceActionsUtil.getModelResource(locale, flagsRequest.getClassName()); // Reason String reason = LanguageUtil.get(locale, flagsRequest.getReason()); // Email FlagsGroupServiceConfiguration flagsGroupServiceConfiguration = ConfigurationProviderUtil .getCompanyConfiguration(FlagsGroupServiceConfiguration.class, companyId); String fromName = flagsGroupServiceConfiguration.emailFromName(); String fromAddress = flagsGroupServiceConfiguration.emailFromAddress(); String subject = ContentUtil.get(FlagsRequestMessageListener.class.getClassLoader(), flagsGroupServiceConfiguration.emailSubject()); String body = ContentUtil.get(FlagsRequestMessageListener.class.getClassLoader(), flagsGroupServiceConfiguration.emailBody()); // Recipients Set<User> recipients = getRecipients(companyId, serviceContext.getScopeGroupId()); for (User recipient : recipients) { try { notify(reporterUser.getUserId(), company, group, reporterEmailAddress, reporterUserName, reportedEmailAddress, reportedUserName, reportedURL, flagsRequest.getClassPK(), flagsRequest.getContentTitle(), contentType, flagsRequest.getContentURL(), reason, fromName, fromAddress, recipient.getFullName(), recipient.getEmailAddress(), subject, body, serviceContext); } catch (IOException ioe) { if (_log.isWarnEnabled()) { _log.warn(ioe); } } } }