List of usage examples for com.liferay.portal.kernel.util PropsUtil get
public static String get(String key)
From source file:com.liferay.petra.log4j.Log4JUtil.java
License:Open Source License
private static String _getLiferayHome() { if (_liferayHome == null) { _liferayHome = PropsUtil.get(PropsKeys.LIFERAY_HOME); }// w ww .j a va 2 s . c o m return _liferayHome; }
From source file:com.liferay.petra.mail.MailEngine.java
License:Open Source License
public static void send(InternetAddress from, InternetAddress[] to, InternetAddress[] cc, InternetAddress[] bcc, InternetAddress[] bulkAddresses, String subject, String body, boolean htmlFormat, InternetAddress[] replyTo, String messageId, String inReplyTo, List<FileAttachment> fileAttachments, SMTPAccount smtpAccount, InternetHeaders internetHeaders) throws MailEngineException { long startTime = System.currentTimeMillis(); if (_log.isDebugEnabled()) { _log.debug("From: " + from); _log.debug("To: " + Arrays.toString(to)); _log.debug("CC: " + Arrays.toString(cc)); _log.debug("BCC: " + Arrays.toString(bcc)); _log.debug("List Addresses: " + Arrays.toString(bulkAddresses)); _log.debug("Subject: " + subject); _log.debug("Body: " + body); _log.debug("HTML Format: " + htmlFormat); _log.debug("Reply to: " + Arrays.toString(replyTo)); _log.debug("Message ID: " + messageId); _log.debug("In Reply To: " + inReplyTo); if ((fileAttachments != null) && _log.isDebugEnabled()) { for (int i = 0; i < fileAttachments.size(); i++) { FileAttachment fileAttachment = fileAttachments.get(i); File file = fileAttachment.getFile(); if (file == null) { continue; }/*from w w w .j a va 2s. co m*/ _log.debug(StringBundler.concat("Attachment ", String.valueOf(i), " file ", file.getAbsolutePath(), " and file name ", fileAttachment.getFileName())); } } } try { InternetAddressUtil.validateAddress(from); if (ArrayUtil.isNotEmpty(to)) { InternetAddressUtil.validateAddresses(to); } if (ArrayUtil.isNotEmpty(cc)) { InternetAddressUtil.validateAddresses(cc); } if (ArrayUtil.isNotEmpty(bcc)) { InternetAddressUtil.validateAddresses(bcc); } if (ArrayUtil.isNotEmpty(replyTo)) { InternetAddressUtil.validateAddresses(replyTo); } if (ArrayUtil.isNotEmpty(bulkAddresses)) { InternetAddressUtil.validateAddresses(bulkAddresses); } Session session = null; if (smtpAccount == null) { session = getSession(); } else { session = getSession(smtpAccount); } Message message = new LiferayMimeMessage(session); message.addHeader("X-Auto-Response-Suppress", "AutoReply, DR, NDR, NRN, OOF, RN"); message.setFrom(from); if (ArrayUtil.isNotEmpty(to)) { message.setRecipients(Message.RecipientType.TO, to); } if (ArrayUtil.isNotEmpty(cc)) { message.setRecipients(Message.RecipientType.CC, cc); } if (ArrayUtil.isNotEmpty(bcc)) { message.setRecipients(Message.RecipientType.BCC, bcc); } subject = GetterUtil.getString(subject); message.setSubject(_sanitizeCRLF(subject)); if (ListUtil.isNotEmpty(fileAttachments)) { MimeMultipart rootMultipart = new MimeMultipart(_MULTIPART_TYPE_MIXED); MimeMultipart messageMultipart = new MimeMultipart(_MULTIPART_TYPE_ALTERNATIVE); MimeBodyPart messageBodyPart = new MimeBodyPart(); messageBodyPart.setContent(messageMultipart); rootMultipart.addBodyPart(messageBodyPart); if (htmlFormat) { MimeBodyPart bodyPart = new MimeBodyPart(); bodyPart.setContent(body, _TEXT_HTML); messageMultipart.addBodyPart(bodyPart); } else { MimeBodyPart bodyPart = new MimeBodyPart(); bodyPart.setText(body); messageMultipart.addBodyPart(bodyPart); } for (FileAttachment fileAttachment : fileAttachments) { File file = fileAttachment.getFile(); if (file == null) { continue; } MimeBodyPart mimeBodyPart = new MimeBodyPart(); DataSource dataSource = new FileDataSource(file); mimeBodyPart.setDataHandler(new DataHandler(dataSource)); mimeBodyPart.setDisposition(Part.ATTACHMENT); if (fileAttachment.getFileName() != null) { mimeBodyPart.setFileName(fileAttachment.getFileName()); } else { mimeBodyPart.setFileName(file.getName()); } rootMultipart.addBodyPart(mimeBodyPart); } message.setContent(rootMultipart); message.saveChanges(); } else { if (htmlFormat) { message.setContent(body, _TEXT_HTML); } else { message.setContent(body, _TEXT_PLAIN); } } message.setSentDate(new Date()); if (ArrayUtil.isNotEmpty(replyTo)) { message.setReplyTo(replyTo); } if (messageId != null) { message.setHeader("Message-ID", _sanitizeCRLF(messageId)); } if (inReplyTo != null) { message.setHeader("In-Reply-To", _sanitizeCRLF(inReplyTo)); message.setHeader("References", _sanitizeCRLF(inReplyTo)); } if (internetHeaders != null) { Enumeration enumeration = internetHeaders.getAllHeaders(); while (enumeration.hasMoreElements()) { Header header = (Header) enumeration.nextElement(); message.setHeader(header.getName(), header.getValue()); } } int batchSize = GetterUtil.getInteger(PropsUtil.get(PropsKeys.MAIL_BATCH_SIZE), _BATCH_SIZE); _send(session, message, bulkAddresses, batchSize); } catch (SendFailedException sfe) { _log.error(sfe); if (_isThrowsExceptionOnFailure()) { throw new MailEngineException(sfe); } } catch (Exception e) { throw new MailEngineException(e); } if (_log.isDebugEnabled()) { _log.debug("Sending mail takes " + (System.currentTimeMillis() - startTime) + " ms"); } }
From source file:com.liferay.petra.mail.MailEngine.java
License:Open Source License
private static boolean _isThrowsExceptionOnFailure() { return GetterUtil.getBoolean(PropsUtil.get(PropsKeys.MAIL_THROWS_EXCEPTION_ON_FAILURE)); }
From source file:com.liferay.polls.service.ClpSerializer.java
License:Open Source License
public static String getServletContextName() { if (Validator.isNotNull(_servletContextName)) { return _servletContextName; }//from w w w.j ava 2 s . co m synchronized (ClpSerializer.class) { if (Validator.isNotNull(_servletContextName)) { return _servletContextName; } try { ClassLoader classLoader = ClpSerializer.class.getClassLoader(); Class<?> portletPropsClass = classLoader.loadClass("com.liferay.util.portlet.PortletProps"); Method getMethod = portletPropsClass.getMethod("get", new Class<?>[] { String.class }); String portletPropsServletContextName = (String) getMethod.invoke(null, "polls-portlet-deployment-context"); if (Validator.isNotNull(portletPropsServletContextName)) { _servletContextName = portletPropsServletContextName; } } catch (Throwable t) { if (_log.isInfoEnabled()) { _log.info("Unable to locate deployment context from portlet properties"); } } if (Validator.isNull(_servletContextName)) { try { String propsUtilServletContextName = PropsUtil.get("polls-portlet-deployment-context"); if (Validator.isNotNull(propsUtilServletContextName)) { _servletContextName = propsUtilServletContextName; } } catch (Throwable t) { if (_log.isInfoEnabled()) { _log.info("Unable to locate deployment context from portal properties"); } } } if (Validator.isNull(_servletContextName)) { _servletContextName = "polls-portlet"; } return _servletContextName; } }
From source file:com.liferay.portlet.asset.service.impl.AssetEntryLocalServiceImpl.java
License:Open Source License
@Override public AssetEntry updateEntry(long userId, long groupId, Date createDate, Date modifiedDate, String className, long classPK, String classUuid, long classTypeId, long[] categoryIds, String[] tagNames, boolean visible, Date startDate, Date endDate, Date expirationDate, String mimeType, String title, String description, String summary, String url, String layoutUuid, int height, int width, Integer priority, boolean sync) throws PortalException, SystemException { // Entry//from ww w . j ava 2 s . c o m User user = userPersistence.findByPrimaryKey(userId); long classNameId = PortalUtil.getClassNameId(className); List<String> newTagsList = new ArrayList<String>(); if (!Validator.isNull(tagNames) && className.equalsIgnoreCase(JournalArticle.class.getName())) { for (String tag : tagNames) { if (PropsUtil.get("stoxx-contentmanagement-all-region").equalsIgnoreCase(tag)) { ClassLoader classLoader = (ClassLoader) PortletBeanLocatorUtil .locate(ClpSerializer.getServletContextName(), "portletClassLoader"); DynamicQuery query = DynamicQueryFactoryUtil.forClass(IndexDB.class, classLoader); query.setProjection( ProjectionFactoryUtil.distinct(ProjectionFactoryUtil.property("superRegion"))); query.addOrder(OrderFactoryUtil.asc("superRegion")); query.add(RestrictionsFactoryUtil.eq("data1", "1")); newTagsList.addAll(new ArrayList<String>(IndexDBLocalServiceUtil.dynamicQuery(query))); } else if (PropsUtil.get("stoxx-contentmanagement-all-type").equalsIgnoreCase(tag)) { ClassLoader classLoader = (ClassLoader) PortletBeanLocatorUtil .locate(ClpSerializer.getServletContextName(), "portletClassLoader"); DynamicQuery query = DynamicQueryFactoryUtil.forClass(IndexDB.class, classLoader); query.setProjection( ProjectionFactoryUtil.distinct(ProjectionFactoryUtil.property("superType"))); query.addOrder(OrderFactoryUtil.asc("superType")); query.add(RestrictionsFactoryUtil.eq("data1", "1")); newTagsList.addAll(new ArrayList<String>(IndexDBLocalServiceUtil.dynamicQuery(query))); } else { List<String> regionSuperTypeList = getRegionandTypeList(tag); if (regionSuperTypeList.size() > 0) { newTagsList.addAll(regionSuperTypeList); } } } } if (newTagsList.size() > 0) { int arraySize = newTagsList.size() + tagNames.length; String[] newTagNames = new String[arraySize]; int count = 0; for (String tag : newTagsList) { tag = tag.replace(StringPool.SLASH, StringPool.BLANK); tag = tag.replace(StringPool.AMPERSAND, StringPool.BLANK); tag = tag.replace(StringPool.PERCENT, StringPool.BLANK); newTagNames[count] = tag; count++; } for (String tag : tagNames) { if (!PropsUtil.get("stoxx-contentmanagement-all-type").equalsIgnoreCase(tag) && !PropsUtil.get("stoxx-contentmanagement-all-region").equalsIgnoreCase(tag)) { newTagNames[count] = tag; count++; } } List<String> tagList = new ArrayList<String>(Arrays.asList(newTagNames)); tagList.removeAll(Collections.singleton(null)); tagNames = tagList.toArray(new String[tagList.size()]); } validate(groupId, className, categoryIds, tagNames); AssetEntry entry = assetEntryPersistence.fetchByC_C(classNameId, classPK); boolean oldVisible = false; if (entry != null) { oldVisible = entry.isVisible(); } if (modifiedDate == null) { modifiedDate = new Date(); } if (entry == null) { long entryId = counterLocalService.increment(); entry = assetEntryPersistence.create(entryId); entry.setCompanyId(user.getCompanyId()); entry.setUserId(user.getUserId()); entry.setUserName(user.getFullName()); if (createDate == null) { createDate = new Date(); } entry.setCreateDate(createDate); entry.setModifiedDate(modifiedDate); entry.setClassNameId(classNameId); entry.setClassPK(classPK); entry.setClassUuid(classUuid); entry.setVisible(visible); entry.setExpirationDate(expirationDate); if (priority == null) { entry.setPriority(0); } entry.setViewCount(0); } entry.setGroupId(groupId); entry.setModifiedDate(modifiedDate); entry.setClassTypeId(classTypeId); entry.setVisible(visible); entry.setStartDate(startDate); entry.setEndDate(endDate); entry.setExpirationDate(expirationDate); entry.setMimeType(mimeType); entry.setTitle(title); entry.setDescription(description); entry.setSummary(summary); entry.setUrl(url); entry.setLayoutUuid(layoutUuid); entry.setHeight(height); entry.setWidth(width); if (priority != null) { entry.setPriority(priority.intValue()); } // Categories if (categoryIds != null) { assetEntryPersistence.setAssetCategories(entry.getEntryId(), categoryIds); } // Tags if (tagNames != null) { long siteGroupId = PortalUtil.getSiteGroupId(groupId); Group siteGroup = groupLocalService.getGroup(siteGroupId); List<AssetTag> tags = assetTagLocalService.checkTags(userId, siteGroup, tagNames); List<AssetTag> oldTags = assetEntryPersistence.getAssetTags(entry.getEntryId()); assetEntryPersistence.setAssetTags(entry.getEntryId(), tags); if (entry.isVisible()) { boolean isNew = entry.isNew(); assetEntryPersistence.updateImpl(entry); if (isNew) { for (AssetTag tag : tags) { assetTagLocalService.incrementAssetCount(tag.getTagId(), classNameId); } } else { for (AssetTag oldTag : oldTags) { if (!tags.contains(oldTag)) { assetTagLocalService.decrementAssetCount(oldTag.getTagId(), classNameId); } } for (AssetTag tag : tags) { if (!oldTags.contains(tag)) { assetTagLocalService.incrementAssetCount(tag.getTagId(), classNameId); } } } } else if (oldVisible) { for (AssetTag oldTag : oldTags) { assetTagLocalService.decrementAssetCount(oldTag.getTagId(), classNameId); } } } // Update entry after tags so that entry listeners have access to the // saved categories and tags log.info("AssetEntryLocalServiceImpl.updateEntry() inside updateEntry"); if (entry.getClassName().equals(JournalArticle.class.getName())) { List<AssetCategory> assetCategory = entry.getCategories(); for (AssetCategory ae : assetCategory) { log.info("AssetEntryLocalServiceImpl.updateEntry() the asset category is " + ae.getName()); if (STOXXConstants.CATEGORY_STOXX_NEWS_PRESS_RELEASE.equalsIgnoreCase(ae.getName()) || STOXXConstants.CATEGORY_STOXX_NEWS_MARKET_NEWS.equalsIgnoreCase(ae.getName()) || STOXXConstants.CATEGORY_STOXX_RESEARCH_MARKET_TRENDS.equalsIgnoreCase(ae.getName()) || STOXXConstants.CATEGORY_STOXX_RESEARCH_WEBINARS.equalsIgnoreCase(ae.getName()) || STOXXConstants.CATEGORY_STOXX_RESEARCH_EXPERT_SPEAK.equalsIgnoreCase(ae.getName()) || STOXXConstants.CATEGORY_STOXX_RESEARCH_EVENTS.equalsIgnoreCase(ae.getName()) || STOXXConstants.CATEGORY_STOXX_RESEARCH_PULSE.equalsIgnoreCase(ae.getName())) { JournalArticle journalArticle = null; try { journalArticle = JournalArticleLocalServiceUtil.getLatestArticle(entry.getClassPK()); } catch (Exception e) { log.info("The exception in getting journalArticle " + e.getMessage()); break; } String strDate = getXmlDocument(journalArticle, "Date"); log.info("AssetEntryLocalServiceImpl.updateEntry() Date is strDate" + strDate); if (!Validator.isBlank(strDate)) { log.info("AssetEntryLocalServiceImpl.updateEntry() date is not null"); Date date = new Date(Long.parseLong(strDate)); entry.setModifiedDate(date); break; } } } } log.info("AssetEntryLocalServiceImpl.updateEntry() processing finished"); assetEntryPersistence.update(entry); // Synchronize if (!sync) { return entry; } if (className.equals(BlogsEntry.class.getName())) { BlogsEntry blogsEntry = blogsEntryPersistence.findByPrimaryKey(classPK); blogsEntry.setTitle(title); blogsEntryPersistence.update(blogsEntry); } else if (className.equals(BookmarksEntry.class.getName())) { BookmarksEntry bookmarksEntry = bookmarksEntryPersistence.findByPrimaryKey(classPK); bookmarksEntry.setName(title); bookmarksEntry.setDescription(description); bookmarksEntry.setUrl(url); bookmarksEntryPersistence.update(bookmarksEntry); } else if (className.equals(DLFileEntry.class.getName())) { DLFileEntry dlFileEntry = dlFileEntryPersistence.findByPrimaryKey(classPK); dlFileEntry.setTitle(title); dlFileEntry.setDescription(description); dlFileEntryPersistence.update(dlFileEntry); } else if (className.equals(JournalArticle.class.getName())) { JournalArticle journalArticle = journalArticlePersistence.findByPrimaryKey(classPK); journalArticle.setTitle(title); journalArticle.setDescription(description); journalArticlePersistence.update(journalArticle); } else if (className.equals(MBMessage.class.getName())) { MBMessage mbMessage = mbMessagePersistence.findByPrimaryKey(classPK); mbMessage.setSubject(title); mbMessagePersistence.update(mbMessage); } else if (className.equals(WikiPage.class.getName())) { WikiPage wikiPage = wikiPagePersistence.findByPrimaryKey(classPK); wikiPage.setTitle(title); wikiPagePersistence.update(wikiPage); } return entry; }
From source file:com.liferay.portlet.asset.service.impl.AssetEntryLocalServiceImpl.java
License:Open Source License
private List<String> getRegionandTypeList(String name) { Connection conn = null;// w ww . ja v a2 s. co m DataSource source = InfrastructureUtil.getDataSource(); List<String> regionTypeList = new ArrayList<String>(); try { Class.forName(PropsUtil.get("jdbc.default.driverClassName")); conn = source.getConnection(); String query = "select superType,superRegion from stoxx_indexdb where symbol=?"; PreparedStatement pstmt = conn.prepareStatement(query); pstmt.setString(1, name.toUpperCase()); ResultSet rs = pstmt.executeQuery(); if (rs.next()) { String superType = rs.getString("superType"); String superRegion = rs.getString("superRegion"); log.info("superType is : " + superType + " superRegion is" + superRegion); regionTypeList.add(superType); regionTypeList.add(superRegion); } } catch (SQLException e) { log.info("SQLException", e); } catch (ClassNotFoundException e) { log.info(e.getMessage(), e); } finally { try { if (null != conn) { conn.close(); } } catch (SQLException e) { log.error(e.getMessage(), e); } } regionTypeList.removeAll(Collections.singleton(null)); return regionTypeList; }
From source file:com.liferay.portlet.documentlibrary.recordlog.service.ClpSerializer.java
License:Open Source License
public static String getServletContextName() { if (Validator.isNotNull(_servletContextName)) { return _servletContextName; }//from w w w. java 2s. co m synchronized (ClpSerializer.class) { if (Validator.isNotNull(_servletContextName)) { return _servletContextName; } try { ClassLoader classLoader = ClpSerializer.class.getClassLoader(); Class<?> portletPropsClass = classLoader.loadClass("com.liferay.util.portlet.PortletProps"); Method getMethod = portletPropsClass.getMethod("get", new Class<?>[] { String.class }); String portletPropsServletContextName = (String) getMethod.invoke(null, "document-download-tracking-hook-deployment-context"); if (Validator.isNotNull(portletPropsServletContextName)) { _servletContextName = portletPropsServletContextName; } } catch (Throwable t) { if (_log.isInfoEnabled()) { _log.info("Unable to locate deployment context from portlet properties"); } } if (Validator.isNull(_servletContextName)) { try { String propsUtilServletContextName = PropsUtil .get("document-download-tracking-hook-deployment-context"); if (Validator.isNotNull(propsUtilServletContextName)) { _servletContextName = propsUtilServletContextName; } } catch (Throwable t) { if (_log.isInfoEnabled()) { _log.info("Unable to locate deployment context from portal properties"); } } } if (Validator.isNull(_servletContextName)) { _servletContextName = "document-download-tracking-hook"; } return _servletContextName; } }
From source file:com.liferay.portlet.documentlibrary.util.DLPreviewableProcessor.java
License:Open Source License
protected boolean isThumbnailEnabled(int index) throws SystemException { if ((index == THUMBNAIL_INDEX_DEFAULT) && GetterUtil.getBoolean(PropsUtil.get(PropsKeys.DL_FILE_ENTRY_THUMBNAIL_ENABLED))) { return true; } else if ((index == THUMBNAIL_INDEX_CUSTOM_1) && ((PrefsPropsUtil.getInteger(PropsKeys.DL_FILE_ENTRY_THUMBNAIL_CUSTOM_1_MAX_HEIGHT) > 0) || (PrefsPropsUtil.getInteger(PropsKeys.DL_FILE_ENTRY_THUMBNAIL_CUSTOM_1_MAX_WIDTH) > 0))) { return true; } else if ((index == THUMBNAIL_INDEX_CUSTOM_2) && ((PrefsPropsUtil.getInteger(PropsKeys.DL_FILE_ENTRY_THUMBNAIL_CUSTOM_2_MAX_HEIGHT) > 0) || (PrefsPropsUtil.getInteger(PropsKeys.DL_FILE_ENTRY_THUMBNAIL_CUSTOM_2_MAX_WIDTH) > 0))) { return true; }//from w w w.ja v a 2s . c o m return false; }
From source file:com.liferay.portlet.messageboards.util.MBUtil.java
License:Open Source License
public static String getMessageFormat(PortletPreferences preferences) { String messageFormat = preferences.getValue("messageFormat", MBMessageConstants.DEFAULT_FORMAT); String editorImpl = PropsUtil.get(BB_CODE_EDITOR_WYSIWYG_IMPL_KEY); if (messageFormat.equals("bbcode") && !(editorImpl.equals("bbcode") || editorImpl.equals("ckeditor_bbcode"))) { messageFormat = "html"; }//www . j ava 2 s . c om return messageFormat; }
From source file:com.liferay.portlet.PortletBagFactory.java
License:Open Source License
protected List<AssetRendererFactory> newAssetRendererFactoryInstances(Portlet portlet) throws Exception { List<AssetRendererFactory> assetRendererFactoryInstances = new ArrayList<AssetRendererFactory>(); for (String assetRendererFactoryClass : portlet.getAssetRendererFactoryClasses()) { String assetRendererEnabledPropertyKey = PropsKeys.ASSET_RENDERER_ENABLED + assetRendererFactoryClass; String assetRendererEnabledPropertyValue = null; if (_warFile) { assetRendererEnabledPropertyValue = getPluginPropertyValue(assetRendererEnabledPropertyKey); } else {/*from w w w .ja v a 2 s.c o m*/ assetRendererEnabledPropertyValue = PropsUtil.get(assetRendererEnabledPropertyKey); } boolean assetRendererEnabledValue = GetterUtil.getBoolean(assetRendererEnabledPropertyValue, true); if (assetRendererEnabledValue) { AssetRendererFactory assetRendererFactoryInstance = newAssetRendererFactoryInstance(portlet, assetRendererFactoryClass); assetRendererFactoryInstances.add(assetRendererFactoryInstance); } } return assetRendererFactoryInstances; }