List of usage examples for com.liferay.portal.util PrefsPropsUtil getLong
public static long getLong(String name)
From source file:com.liferay.document.library.web.internal.portlet.action.EditFileEntryMVCActionCommand.java
License:Open Source License
protected String getAddMultipleFileEntriesErrorMessage(PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse, Exception e) throws Exception { String errorMessage = null;//from w ww .ja va 2s . c om ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); if (e instanceof AntivirusScannerException) { AntivirusScannerException ase = (AntivirusScannerException) e; errorMessage = themeDisplay.translate(ase.getMessageKey()); } else if (e instanceof AssetCategoryException) { AssetCategoryException ace = (AssetCategoryException) e; AssetVocabulary assetVocabulary = ace.getVocabulary(); String vocabularyTitle = StringPool.BLANK; if (assetVocabulary != null) { vocabularyTitle = assetVocabulary.getTitle(themeDisplay.getLocale()); } if (ace.getType() == AssetCategoryException.AT_LEAST_ONE_CATEGORY) { errorMessage = themeDisplay.translate("please-select-at-least-one-category-for-x", vocabularyTitle); } else if (ace.getType() == AssetCategoryException.TOO_MANY_CATEGORIES) { errorMessage = themeDisplay.translate("you-cannot-select-more-than-one-category-for-x", vocabularyTitle); } } else if (e instanceof DuplicateFileEntryException) { errorMessage = themeDisplay.translate("the-folder-you-selected-already-has-an-entry-with-this-" + "name.-please-select-a-different-folder"); } else if (e instanceof FileExtensionException) { errorMessage = themeDisplay.translate("please-enter-a-file-with-a-valid-extension-x", StringUtil.merge(getAllowedFileExtensions(portletConfig, actionRequest, actionResponse))); } else if (e instanceof FileNameException) { errorMessage = themeDisplay.translate("please-enter-a-file-with-a-valid-file-name"); } else if (e instanceof FileSizeException) { long fileMaxSize = PrefsPropsUtil.getLong(PropsKeys.DL_FILE_MAX_SIZE); if (fileMaxSize == 0) { fileMaxSize = PrefsPropsUtil.getLong(PropsKeys.UPLOAD_SERVLET_REQUEST_IMPL_MAX_SIZE); } errorMessage = themeDisplay.translate("please-enter-a-file-with-a-valid-file-size-no-larger-than-x", TextFormatter.formatStorageSize(fileMaxSize, themeDisplay.getLocale())); } else if (e instanceof InvalidFileEntryTypeException) { errorMessage = themeDisplay.translate("the-document-type-you-selected-is-not-valid-for-this-folder"); } else { errorMessage = themeDisplay.translate("an-unexpected-error-occurred-while-saving-your-document"); } return errorMessage; }
From source file:com.liferay.document.library.web.internal.portlet.action.EditFileEntryMVCActionCommand.java
License:Open Source License
protected void handleUploadException(PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse, String cmd, Exception e) throws Exception { if (e instanceof AssetCategoryException || e instanceof AssetTagException) { SessionErrors.add(actionRequest, e.getClass(), e); } else if (e instanceof AntivirusScannerException || e instanceof DuplicateFileEntryException || e instanceof DuplicateFolderNameException || e instanceof FileExtensionException || e instanceof FileMimeTypeException || e instanceof FileNameException || e instanceof FileSizeException || e instanceof LiferayFileItemException || e instanceof NoSuchFolderException || e instanceof SourceFileNameException || e instanceof StorageFieldRequiredException || e instanceof UploadRequestSizeException) { if (!cmd.equals(Constants.ADD_DYNAMIC) && !cmd.equals(Constants.ADD_MULTIPLE) && !cmd.equals(Constants.ADD_TEMP)) { if (e instanceof AntivirusScannerException) { SessionErrors.add(actionRequest, e.getClass(), e); } else { SessionErrors.add(actionRequest, e.getClass()); }//from w ww. j a v a 2 s . co m return; } else if (cmd.equals(Constants.ADD_TEMP)) { hideDefaultErrorMessage(actionRequest); } if (e instanceof AntivirusScannerException || e instanceof DuplicateFileEntryException || e instanceof FileExtensionException || e instanceof FileNameException || e instanceof FileSizeException || e instanceof UploadRequestSizeException) { HttpServletResponse response = _portal.getHttpServletResponse(actionResponse); response.setContentType(ContentTypes.TEXT_HTML); response.setStatus(HttpServletResponse.SC_OK); String errorMessage = StringPool.BLANK; int errorType = 0; ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); if (e instanceof AntivirusScannerException) { AntivirusScannerException ase = (AntivirusScannerException) e; errorMessage = themeDisplay.translate(ase.getMessageKey()); errorType = ServletResponseConstants.SC_FILE_ANTIVIRUS_EXCEPTION; } if (e instanceof DuplicateFileEntryException) { errorMessage = themeDisplay.translate("please-enter-a-unique-document-name"); errorType = ServletResponseConstants.SC_DUPLICATE_FILE_EXCEPTION; } else if (e instanceof FileExtensionException) { errorMessage = themeDisplay.translate("please-enter-a-file-with-a-valid-extension-x", StringUtil .merge(getAllowedFileExtensions(portletConfig, actionRequest, actionResponse))); errorType = ServletResponseConstants.SC_FILE_EXTENSION_EXCEPTION; } else if (e instanceof FileNameException) { errorMessage = themeDisplay.translate("please-enter-a-file-with-a-valid-file-name"); errorType = ServletResponseConstants.SC_FILE_NAME_EXCEPTION; } else if (e instanceof FileSizeException) { long fileMaxSize = PrefsPropsUtil.getLong(PropsKeys.DL_FILE_MAX_SIZE); if (fileMaxSize == 0) { fileMaxSize = PrefsPropsUtil.getLong(PropsKeys.UPLOAD_SERVLET_REQUEST_IMPL_MAX_SIZE); } errorMessage = themeDisplay.translate( "please-enter-a-file-with-a-valid-file-size-no-" + "larger-than-x", TextFormatter.formatStorageSize(fileMaxSize, themeDisplay.getLocale())); errorType = ServletResponseConstants.SC_FILE_SIZE_EXCEPTION; } JSONObject jsonObject = JSONFactoryUtil.createJSONObject(); jsonObject.put("message", errorMessage); jsonObject.put("status", errorType); JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject); } if (e instanceof AntivirusScannerException) { SessionErrors.add(actionRequest, e.getClass(), e); } else { SessionErrors.add(actionRequest, e.getClass()); } } else if (e instanceof DuplicateLockException || e instanceof FileEntryLockException.MustOwnLock || e instanceof InvalidFileVersionException || e instanceof NoSuchFileEntryException || e instanceof PrincipalException) { if (e instanceof DuplicateLockException) { DuplicateLockException dle = (DuplicateLockException) e; SessionErrors.add(actionRequest, dle.getClass(), dle.getLock()); } else { SessionErrors.add(actionRequest, e.getClass()); } actionResponse.setRenderParameter("mvcPath", "/document_library/error.jsp"); } else { Throwable cause = e.getCause(); if (cause instanceof DuplicateFileEntryException) { SessionErrors.add(actionRequest, DuplicateFileEntryException.class); } else { throw e; } } }
From source file:com.liferay.document.library.web.internal.upload.FileEntryDLUploadHandler.java
License:Open Source License
@Override protected void validateFile(String fileName, String contentType, long size) throws PortalException { long maxSize = PrefsPropsUtil.getLong(PropsKeys.DL_FILE_MAX_SIZE); if ((maxSize > 0) && (size > maxSize)) { throw new FileSizeException(size + " exceeds its maximum permitted size of " + maxSize); }//from w w w . j a va 2 s. c om }
From source file:com.liferay.portlet.blogs.service.impl.BlogsEntryLocalServiceImpl.java
License:Open Source License
protected void validate(String title, String content, boolean smallImage, String smallImageURL, String smallImageFileName, byte[] smallImageBytes) throws PortalException, SystemException { if (Validator.isNull(title)) { throw new EntryTitleException(); } else if (Validator.isNull(content)) { throw new EntryContentException(); }/*from w w w .j a va2 s . c o m*/ String[] imageExtensions = PrefsPropsUtil.getStringArray(PropsKeys.BLOGS_IMAGE_EXTENSIONS, StringPool.COMMA); if (smallImage && Validator.isNull(smallImageURL) && (smallImageBytes != null)) { if (smallImageFileName != null) { boolean validSmallImageExtension = false; for (String _imageExtension : imageExtensions) { if (StringPool.STAR.equals(_imageExtension) || StringUtil.endsWith(smallImageFileName, _imageExtension)) { validSmallImageExtension = true; break; } } if (!validSmallImageExtension) { throw new EntrySmallImageNameException(smallImageFileName); } } long smallImageMaxSize = PrefsPropsUtil.getLong(PropsKeys.BLOGS_IMAGE_SMALL_MAX_SIZE); if ((smallImageMaxSize > 0) && ((smallImageBytes == null) || (smallImageBytes.length > smallImageMaxSize))) { throw new EntrySmallImageSizeException(); } } }
From source file:com.liferay.portlet.documentlibrary.store.DLStoreImpl.java
License:Open Source License
public void validate(String fileName, boolean validateFileExtension, byte[] bytes) throws PortalException, SystemException { validate(fileName, validateFileExtension); if ((PrefsPropsUtil.getLong(PropsKeys.DL_FILE_MAX_SIZE) > 0) && ((bytes == null) || (bytes.length > PrefsPropsUtil.getLong(PropsKeys.DL_FILE_MAX_SIZE)))) { throw new FileSizeException(fileName); }//from w ww .ja va2 s . c o m }
From source file:com.liferay.portlet.documentlibrary.store.DLStoreImpl.java
License:Open Source License
public void validate(String fileName, boolean validateFileExtension, File file) throws PortalException, SystemException { validate(fileName, validateFileExtension); if ((PrefsPropsUtil.getLong(PropsKeys.DL_FILE_MAX_SIZE) > 0) && ((file == null) || (file.length() > PrefsPropsUtil.getLong(PropsKeys.DL_FILE_MAX_SIZE)))) { throw new FileSizeException(fileName); }/*from w w w. j a va 2 s. c o m*/ }
From source file:com.liferay.portlet.documentlibrary.store.DLStoreImpl.java
License:Open Source License
public void validate(String fileName, boolean validateFileExtension, InputStream is) throws PortalException, SystemException { validate(fileName, validateFileExtension); // LEP-4851//from w w w . j a v a 2 s. c o m try { if ((is == null) || ((PrefsPropsUtil.getLong(PropsKeys.DL_FILE_MAX_SIZE) > 0) && (is.available() > PrefsPropsUtil.getLong(PropsKeys.DL_FILE_MAX_SIZE)))) { throw new FileSizeException(fileName); } } catch (IOException ioe) { throw new FileSizeException(ioe.getMessage()); } }
From source file:com.liferay.portlet.documentlibrary.store.DLStoreImpl.java
License:Open Source License
public void validate(String fileName, String fileExtension, String sourceFileName, boolean validateFileExtension, File file) throws PortalException, SystemException { validate(fileName, fileExtension, sourceFileName, validateFileExtension); if ((file != null) && (PrefsPropsUtil.getLong(PropsKeys.DL_FILE_MAX_SIZE) > 0) && (file.length() > PrefsPropsUtil.getLong(PropsKeys.DL_FILE_MAX_SIZE))) { throw new FileSizeException(fileName); }/*w w w .j av a 2 s .c o m*/ }
From source file:com.liferay.portlet.documentlibrary.store.DLStoreImpl.java
License:Open Source License
public void validate(String fileName, String fileExtension, String sourceFileName, boolean validateFileExtension, InputStream is) throws PortalException, SystemException { validate(fileName, fileExtension, sourceFileName, validateFileExtension); try {/*www. j a v a2 s . c o m*/ if ((is != null) && (PrefsPropsUtil.getLong(PropsKeys.DL_FILE_MAX_SIZE) > 0) && (is.available() > PrefsPropsUtil.getLong(PropsKeys.DL_FILE_MAX_SIZE))) { throw new FileSizeException(fileName); } } catch (IOException ioe) { throw new FileSizeException(ioe.getMessage()); } }
From source file:com.liferay.portlet.journal.service.impl.JournalArticleLocalServiceImpl.java
License:Open Source License
protected void validate(long companyId, long groupId, long classNameId, Map<Locale, String> titleMap, String content, String type, String structureId, String templateId, boolean smallImage, String smallImageURL, File smallImageFile, byte[] smallImageBytes) throws PortalException, SystemException { Locale defaultLocale = LocaleUtil.fromLanguageId(LocalizationUtil.getDefaultLocale(content)); if ((classNameId == 0) && (titleMap.isEmpty() || Validator.isNull(titleMap.get(defaultLocale)))) { throw new ArticleTitleException(); } else if (Validator.isNull(type)) { throw new ArticleTypeException(); }//www . ja va 2 s. c o m validateContent(content); if (Validator.isNotNull(structureId)) { Group companyGroup = groupLocalService.getCompanyGroup(companyId); try { journalStructurePersistence.findByG_S(groupId, structureId); } catch (NoSuchStructureException nsse) { journalStructurePersistence.findByG_S(companyGroup.getGroupId(), structureId); } JournalTemplate template = null; if (Validator.isNotNull(templateId)) { try { template = journalTemplatePersistence.findByG_T(groupId, templateId); } catch (NoSuchTemplateException nste) { template = journalTemplatePersistence.findByG_T(companyGroup.getGroupId(), templateId); } if (!template.getStructureId().equals(structureId)) { throw new NoSuchTemplateException(); } } else if (classNameId == 0) { throw new NoSuchTemplateException(); } } String[] imageExtensions = PrefsPropsUtil.getStringArray(PropsKeys.JOURNAL_IMAGE_EXTENSIONS, StringPool.COMMA); if (smallImage && Validator.isNull(smallImageURL) && (smallImageFile != null) && (smallImageBytes != null)) { String smallImageName = smallImageFile.getName(); if (smallImageName != null) { boolean validSmallImageExtension = false; for (String _imageExtension : imageExtensions) { if (StringPool.STAR.equals(_imageExtension) || StringUtil.endsWith(smallImageName, _imageExtension)) { validSmallImageExtension = true; break; } } if (!validSmallImageExtension) { throw new ArticleSmallImageNameException(smallImageName); } } long smallImageMaxSize = PrefsPropsUtil.getLong(PropsKeys.JOURNAL_IMAGE_SMALL_MAX_SIZE); if ((smallImageMaxSize > 0) && ((smallImageBytes == null) || (smallImageBytes.length > smallImageMaxSize))) { throw new ArticleSmallImageSizeException(); } } }