List of usage examples for com.liferay.portal.kernel.util PropsKeys BLOGS_IMAGE_EXTENSIONS
String BLOGS_IMAGE_EXTENSIONS
To view the source code for com.liferay.portal.kernel.util PropsKeys BLOGS_IMAGE_EXTENSIONS.
Click Source Link
From source file:com.liferay.blogs.service.impl.BlogsEntryLocalServiceImpl.java
License:Open Source License
protected void validate(long smallImageFileEntryId) throws PortalException { String[] imageExtensions = PrefsPropsUtil.getStringArray(PropsKeys.BLOGS_IMAGE_EXTENSIONS, StringPool.COMMA);//w ww .j av a 2 s. c o m if (smallImageFileEntryId != 0) { FileEntry fileEntry = PortletFileRepositoryUtil.getPortletFileEntry(smallImageFileEntryId); boolean validSmallImageExtension = false; for (String imageExtension : imageExtensions) { if (StringPool.STAR.equals(imageExtension) || imageExtension.equals(StringPool.PERIOD + fileEntry.getExtension())) { validSmallImageExtension = true; break; } } if (!validSmallImageExtension) { throw new EntrySmallImageNameException( "Invalid small image for file entry " + smallImageFileEntryId); } } }
From source file:com.liferay.blogs.web.internal.upload.BaseBlogsUploadHandler.java
License:Open Source License
@Override public void validateFile(String fileName, String contentType, long size) throws PortalException { long maxSize = getMaxFileSize(); if ((maxSize > 0) && (size > maxSize)) { throw new EntryImageSizeException(); }/*from w w w .j a v a 2s . c om*/ String extension = FileUtil.getExtension(fileName); String[] imageExtensions = PrefsPropsUtil.getStringArray(PropsKeys.BLOGS_IMAGE_EXTENSIONS, StringPool.COMMA); for (String imageExtension : imageExtensions) { if (StringPool.STAR.equals(imageExtension) || imageExtension.equals(StringPool.PERIOD + extension)) { return; } } throw new EntryImageNameException("Invalid image for file name " + fileName); }
From source file:com.liferay.blogs.web.internal.upload.BaseBlogsUploadHandler.java
License:Open Source License
@Override protected void doHandleUploadException(PortletRequest portletRequest, PortletResponse portletResponse, PortalException pe, JSONObject jsonObject) throws PortalException { if (pe instanceof EntryImageNameException || pe instanceof EntryImageSizeException) { String errorMessage = StringPool.BLANK; int errorType = 0; if (pe instanceof EntryImageNameException) { errorType = ServletResponseConstants.SC_FILE_EXTENSION_EXCEPTION; String[] imageExtensions = PrefsPropsUtil.getStringArray(PropsKeys.BLOGS_IMAGE_EXTENSIONS, StringPool.COMMA);/*from w w w .ja v a 2s. c o m*/ errorMessage = StringUtil.merge(imageExtensions); } else if (pe instanceof EntryImageSizeException) { errorType = ServletResponseConstants.SC_FILE_SIZE_EXCEPTION; } JSONObject errorJSONObject = JSONFactoryUtil.createJSONObject(); errorJSONObject.put("errorType", errorType); errorJSONObject.put("message", errorMessage); jsonObject.put("error", errorJSONObject); } else { throw pe; } }
From source file:com.liferay.blogs.web.internal.upload.ImageBlogsUploadFileEntryHandler.java
License:Open Source License
private void _validateFile(String fileName, long size) throws PortalException { if ((PropsValues.BLOGS_IMAGE_MAX_SIZE > 0) && (size > PropsValues.BLOGS_IMAGE_MAX_SIZE)) { throw new EntryImageSizeException(); }//from www . j a v a2 s. com String extension = FileUtil.getExtension(fileName); String[] imageExtensions = PrefsPropsUtil.getStringArray(PropsKeys.BLOGS_IMAGE_EXTENSIONS, StringPool.COMMA); for (String imageExtension : imageExtensions) { if (StringPool.STAR.equals(imageExtension) || imageExtension.equals(StringPool.PERIOD + extension)) { return; } } throw new EntryImageNameException("Invalid image for file name " + fileName); }
From source file:com.liferay.blogs.web.internal.upload.ImageBlogsUploadResponseHandler.java
License:Open Source License
@Override public JSONObject onFailure(PortletRequest portletRequest, PortalException pe) throws PortalException { JSONObject jsonObject = _itemSelectorUploadResponseHandler.onFailure(portletRequest, pe); if (pe instanceof EntryImageNameException || pe instanceof EntryImageSizeException) { String errorMessage = StringPool.BLANK; int errorType = 0; if (pe instanceof EntryImageNameException) { errorType = ServletResponseConstants.SC_FILE_EXTENSION_EXCEPTION; String[] imageExtensions = PrefsPropsUtil.getStringArray(PropsKeys.BLOGS_IMAGE_EXTENSIONS, StringPool.COMMA);/* w w w. j a v a 2 s . c o m*/ errorMessage = StringUtil.merge(imageExtensions); } else if (pe instanceof EntryImageSizeException) { errorType = ServletResponseConstants.SC_FILE_SIZE_EXCEPTION; } JSONObject errorJSONObject = JSONFactoryUtil.createJSONObject(); errorJSONObject.put("errorType", errorType); errorJSONObject.put("message", errorMessage); jsonObject.put("error", errorJSONObject); } return jsonObject; }
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 ww w . j a v a2 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(); } } }