List of usage examples for com.liferay.portal.kernel.util PrefsPropsUtil getStringArray
public static String[] getStringArray(String name, String delimiter)
From source file:com.liferay.faces.demos.bean.DocUploadBackingBean.java
License:Open Source License
public String uploadSingleAttachments(UploadedFileWrapper fileToUpload) { boolean success = true; FacesContext facesContext = FacesContext.getCurrentInstance(); Locale locale = facesContext.getViewRoot().getLocale(); if (locale == null) { locale = Locale.getDefault(); }/*from w ww . j a v a2 s. c o m*/ ArrayList<UploadedFileWrapper> uploadedFiles = new ArrayList<UploadedFileWrapper>(); uploadedFiles.add(fileToUpload); DLFolder dlFolder = docLibModelBean.getSelectedNodeDlFolder(); try { for (UploadedFileWrapper uploadedFile : uploadedFiles) { // DLFolder dlFolder = folderUserObject.getDlFolder(); String name = stripInvalidFileNameCharacters(uploadedFile.getName()); String title = name; String description = null; String changeLog = null; File file = new File(uploadedFile.getAbsolutePath()); ServiceContext serviceContext = new ServiceContext(); // Temporary: Make the default setting be that community members can view the file. Need to develop a // "Viewable By" permissions Facelet composite component UI similar to // portal-web/docroot/html/taglib/ui/input_permissions/page.jsp serviceContext.setAddGroupPermissions(true); try { long fileEntryTypeId = DLFileEntryTypeConstants.FILE_ENTRY_TYPE_ID_BASIC_DOCUMENT; Map<String, Fields> fieldsMap = new HashMap<String, Fields>(); FileInputStream inputStream = new FileInputStream(file); DLFileEntryServiceUtil.addFileEntry(dlFolder.getGroupId(), dlFolder.getRepositoryId(), dlFolder.getFolderId(), name, uploadedFile.getContentType(), title, description, changeLog, fileEntryTypeId, fieldsMap, file, inputStream, file.length(), serviceContext); inputStream.close(); file.delete(); } catch (DuplicateFileException e) { success = false; liferayFacesContext.addGlobalErrorMessage("please-enter-a-unique-document-name"); } catch (FileNameException e) { success = false; String extensions = StringUtil.merge( PrefsPropsUtil.getStringArray(PropsKeys.DL_FILE_EXTENSIONS, StringPool.COMMA), StringPool.COMMA_AND_SPACE); String message = liferayFacesContext .getMessage("document-names-must-end-with-one-of-the-following-extensions"); message = message + extensions; liferayFacesContext.addGlobalErrorMessage(message); } catch (FileSizeException e) { success = false; String message = liferayFacesContext.getMessage("please-enter-a-file-with-a-valid-file-size"); message = message + " (" + getMaxFileSizeKB() + "k max)"; liferayFacesContext.addGlobalErrorMessage(message); } catch (SourceFileNameException e) { success = false; liferayFacesContext.addGlobalErrorMessage( "the-source-file-does-not-have-the-same-extension-as-the-original-file"); } } } catch (Exception e) { success = false; logger.error(e.getMessage(), e); liferayFacesContext.addGlobalUnexpectedErrorMessage(); } docLibModelBean.forceDocumentRequery(); String nextPage = success ? "/views/portletViewMode.xhtml" : "error.xhtml"; return nextPage; }
From source file:com.liferay.privatemessaging.portlet.PrivateMessagingPortlet.java
License:Open Source License
protected String getMessage(PortletRequest portletRequest, Exception key) throws Exception { String message = null;/*from w w w . j a v a2 s.c o m*/ if (key instanceof FileExtensionException) { message = translate(portletRequest, "document-names-must-end-with-one-of-the-following-extensions"); message += CharPool.SPACE + StringUtil.merge( PrefsPropsUtil.getStringArray(PropsKeys.DL_FILE_EXTENSIONS, StringPool.COMMA), StringPool.COMMA_AND_SPACE); } else if (key instanceof FileNameException) { message = translate(portletRequest, "please-enter-a-file-with-a-valid-file-name"); } else if (key instanceof FileSizeException) { long fileMaxSize = PrefsPropsUtil.getLong(PropsKeys.DL_FILE_MAX_SIZE); if (fileMaxSize == 0) { fileMaxSize = PrefsPropsUtil.getLong(PropsKeys.UPLOAD_SERVLET_REQUEST_IMPL_MAX_SIZE); } fileMaxSize /= 1024; message = translate(portletRequest, "please-enter-a-file-with-a-valid-file-size-no-larger-than-x", fileMaxSize); } else if (key instanceof UserScreenNameException) { message = translate(portletRequest, "the-following-users-were-not-found"); message += CharPool.SPACE + key.getMessage(); } else { message = translate(portletRequest, "your-request-failed-to-complete"); } return message; }
From source file:com.liferay.privatemessaging.portlet.PrivateMessagingPortlet.java
License:Open Source License
protected void validateAttachment(String fileName, InputStream inputStream) throws Exception { if (inputStream instanceof ByteArrayFileInputStream) { ByteArrayFileInputStream byteArrayFileInputStream = (ByteArrayFileInputStream) inputStream; File file = byteArrayFileInputStream.getFile(); 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 ww . ja v a 2s. c o m*/ } if (!isValidName(fileName)) { throw new FileNameException(fileName); } String[] fileExtensions = PrefsPropsUtil.getStringArray(PropsKeys.DL_FILE_EXTENSIONS, StringPool.COMMA); boolean validFileExtension = false; for (String fileExtension : fileExtensions) { if (StringPool.STAR.equals(fileExtension) || StringUtil.endsWith(fileName, fileExtension)) { validFileExtension = true; break; } } if (!validFileExtension) { throw new FileExtensionException(fileName); } }
From source file:com.liferay.rtl.servlet.filters.ComboServletFilter.java
License:Open Source License
protected boolean validateModuleExtension(String moduleName) throws Exception { boolean validModuleExtension = false; String[] fileExtensions = PrefsPropsUtil.getStringArray(PropsKeys.COMBO_ALLOWED_FILE_EXTENSIONS, StringPool.COMMA);//from w w w.ja v a 2s . c o m for (String fileExtension : fileExtensions) { if (StringPool.STAR.equals(fileExtension) || StringUtil.endsWith(moduleName, fileExtension)) { validModuleExtension = true; break; } } return validModuleExtension; }
From source file:com.liferay.shopping.service.impl.ShoppingItemLocalServiceImpl.java
License:Open Source License
protected void validate(long companyId, long itemId, String sku, String name, boolean smallImage, String smallImageURL, File smallImageFile, byte[] smallImageBytes, boolean mediumImage, String mediumImageURL, File mediumImageFile, byte[] mediumImageBytes, boolean largeImage, String largeImageURL, File largeImageFile, byte[] largeImageBytes) throws PortalException, SystemException, Exception { if (Validator.isNull(sku)) { throw new ItemSKUException(); }// w ww .j a v a2s .c o m ShoppingItem item = shoppingItemPersistence.fetchByC_S(companyId, sku); if (item != null) { if (itemId > 0) { if (item.getItemId() != itemId) { throw new DuplicateItemSKUException(); } } else { throw new DuplicateItemSKUException(); } } if (Validator.isNull(name)) { throw new ItemNameException(); } String[] imageExtensions = PrefsPropsUtil.getStringArray(PropsKeys.SHOPPING_IMAGE_EXTENSIONS, StringPool.COMMA); // Small image if (smallImage && Validator.isNull(smallImageURL) && smallImageFile != null && smallImageBytes != null) { String smallImageName = smallImageFile.getName(); if (smallImageName != null) { boolean validSmallImageExtension = false; for (int i = 0; i < imageExtensions.length; i++) { if (StringPool.STAR.equals(imageExtensions[i]) || StringUtil.endsWith(smallImageName, imageExtensions[i])) { validSmallImageExtension = true; break; } } if (!validSmallImageExtension) { throw new ItemSmallImageNameException(smallImageName); } } long smallImageMaxSize = GetterUtil .getLong(PrefsPropsUtil.getString(PropsKeys.SHOPPING_IMAGE_MEDIUM_MAX_SIZE)); if ((smallImageMaxSize > 0) && ((smallImageBytes == null) || (smallImageBytes.length > smallImageMaxSize))) { throw new ItemSmallImageSizeException(); } } // Medium image if (mediumImage && Validator.isNull(mediumImageURL) && mediumImageFile != null && mediumImageBytes != null) { String mediumImageName = mediumImageFile.getName(); if (mediumImageName != null) { boolean validMediumImageExtension = false; for (int i = 0; i < imageExtensions.length; i++) { if (StringPool.STAR.equals(imageExtensions[i]) || StringUtil.endsWith(mediumImageName, imageExtensions[i])) { validMediumImageExtension = true; break; } } if (!validMediumImageExtension) { throw new ItemMediumImageNameException(mediumImageName); } } long mediumImageMaxSize = GetterUtil .getLong(PrefsPropsUtil.getString(PropsKeys.SHOPPING_IMAGE_MEDIUM_MAX_SIZE)); if ((mediumImageMaxSize > 0) && ((mediumImageBytes == null) || (mediumImageBytes.length > mediumImageMaxSize))) { throw new ItemMediumImageSizeException(); } } // Large image if (largeImage && Validator.isNull(largeImageURL) && largeImageFile != null && largeImageBytes != null) { String largeImageName = largeImageFile.getName(); if (largeImageName != null) { boolean validLargeImageExtension = false; for (int i = 0; i < imageExtensions.length; i++) { if (StringPool.STAR.equals(imageExtensions[i]) || StringUtil.endsWith(largeImageName, imageExtensions[i])) { validLargeImageExtension = true; break; } } if (!validLargeImageExtension) { throw new ItemLargeImageNameException(largeImageName); } } long largeImageMaxSize = GetterUtil .getLong(PrefsPropsUtil.getString(PropsKeys.SHOPPING_IMAGE_LARGE_MAX_SIZE)); if ((largeImageMaxSize > 0) && ((largeImageBytes == null) || (largeImageBytes.length > largeImageMaxSize))) { throw new ItemLargeImageSizeException(); } } }
From source file:com.liferay.wiki.web.internal.portlet.action.EditPageAttachmentsMVCActionCommand.java
License:Open Source License
/** * TODO: Remove. This should extend from EditFileEntryAction once it is * modularized./*from w ww . j ava 2 s.c o m*/ */ protected String[] getAllowedFileExtensions(PortletConfig portletConfig, PortletRequest portletRequest, PortletResponse portletResponse) throws PortalException { return PrefsPropsUtil.getStringArray(PropsKeys.DL_FILE_EXTENSIONS, StringPool.COMMA); }
From source file:org.lsug.quota.web.internal.portlet.action.documentlibrary.QuotaUploadMultipleFileEntriesMVCActionCommand.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 w w w . ja va 2 s . c o m*/ //TODO DLPortletInstanceSettings is an internal class //We cannot use it here as it does in documentlibrary module Set<String> extensions = new HashSet<>(); return extensions.toArray(new String[extensions.size()]); } }