List of usage examples for com.liferay.portal.util PrefsPropsUtil getStringArray
public static String[] getStringArray(String name, String delimiter)
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);/* www.j a va 2 s. co 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 ww w . ja v a 2 s . c o m*/ 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 ww.jav 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); } 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(); }// w ww . j a v a2 s . c o m 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);/*from w ww . j a v a 2s . co 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.document.library.web.internal.portlet.action.EditFileEntryMVCActionCommand.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 . j a v a 2 s . c om ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY); PortletDisplay portletDisplay = themeDisplay.getPortletDisplay(); DLPortletInstanceSettings dlPortletInstanceSettings = DLPortletInstanceSettings .getInstance(themeDisplay.getLayout(), portletDisplay.getId()); Set<String> extensions = new HashSet<>(); String[] mimeTypes = dlPortletInstanceSettings.getMimeTypes(); for (String mimeType : mimeTypes) { extensions.addAll(MimeTypesUtil.getExtensions(mimeType)); } return extensions.toArray(new String[extensions.size()]); } }
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(); }/*ww w . j a v a 2 s. c om*/ 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) throws PortalException, SystemException { if (!isValidName(fileName)) { throw new FileNameException(fileName); }//from w ww. j ava2 s . c om if (validateFileExtension) { boolean validFileExtension = false; String[] fileExtensions = PrefsPropsUtil.getStringArray(PropsKeys.DL_FILE_EXTENSIONS, StringPool.COMMA); for (String fileExtension : fileExtensions) { if (StringPool.STAR.equals(fileExtension) || StringUtil.endsWith(fileName, fileExtension) //Looks like Liferay's bug. Original file name should be checked! //But in this place we have changed fileName. //So, also checked original name. || StringUtil.endsWith(fileName, fileExtension + "_temp.tmp")) { validFileExtension = true; break; } } if (!validFileExtension) { throw new FileExtensionException(fileName); } } }
From source file:com.liferay.portlet.documentlibrary.util.DLFileEntryIndexer.java
License:Open Source License
@Override protected Document doGetDocument(Object obj) throws Exception { DLFileEntry dlFileEntry = (DLFileEntry) obj; _log.info("COGNIZANT@@@@doGetDocument::::: TILE::::" + dlFileEntry.getTitle() + "FileEntryID::::" + dlFileEntry.getFileEntryId()); if (_log.isDebugEnabled()) { _log.debug("Indexing document " + dlFileEntry); }/*from w w w. j a v a2s. c o m*/ boolean indexContent = true; InputStream is = null; try { if (PropsValues.DL_FILE_INDEXING_MAX_SIZE == 0) { indexContent = false; } else if (PropsValues.DL_FILE_INDEXING_MAX_SIZE != -1) { if (dlFileEntry.getSize() > PropsValues.DL_FILE_INDEXING_MAX_SIZE) { indexContent = false; } } if (indexContent) { String[] ignoreExtensions = PrefsPropsUtil .getStringArray(PropsKeys.DL_FILE_INDEXING_IGNORE_EXTENSIONS, StringPool.COMMA); if (ArrayUtil.contains(ignoreExtensions, StringPool.PERIOD + dlFileEntry.getExtension())) { indexContent = false; } } if (indexContent) { is = dlFileEntry.getFileVersion().getContentStream(false); } } catch (Exception e) { _log.error("COGNIZANT@@@@doGetDocument@@CATCH1:::::" + dlFileEntry.getFileEntryId() + "@@@@@" + dlFileEntry.getTitle() + "@@@@", e); fileLog.error("FileEntry ID" + dlFileEntry.getFileEntryId()); try { fileWriter = generateCsvFile(dlFileEntry.getFileEntryId(), fileCsvpath); } catch (IOException e1) { _log.error("Error Generating CSV", e1); } } DLFileVersion dlFileVersion = dlFileEntry.getFileVersion(); try { Document document = getBaseModelDocument(PORTLET_ID, dlFileEntry, dlFileVersion); if (indexContent) { if (is != null) { try { document.addFile(Field.CONTENT, is, dlFileEntry.getTitle()); } catch (IOException ioe) { throw new SearchException("Cannot extract text from file" + dlFileEntry); } } else if (_log.isDebugEnabled()) { _log.debug("Document " + dlFileEntry + " does not have any content"); } } document.addKeyword(Field.CLASS_TYPE_ID, dlFileEntry.getFileEntryTypeId()); document.addText(Field.DESCRIPTION, dlFileEntry.getDescription()); document.addKeyword(Field.FOLDER_ID, dlFileEntry.getFolderId()); document.addKeyword(Field.HIDDEN, dlFileEntry.isInHiddenFolder()); document.addText(Field.PROPERTIES, dlFileEntry.getLuceneProperties()); document.addText(Field.TITLE, dlFileEntry.getTitle()); document.addKeyword(Field.TREE_PATH, StringUtil.split(dlFileEntry.getTreePath(), CharPool.SLASH)); document.addKeyword("dataRepositoryId", dlFileEntry.getDataRepositoryId()); document.addText("ddmContent", extractContent(dlFileVersion, LocaleUtil.getSiteDefault())); document.addKeyword("extension", dlFileEntry.getExtension()); document.addKeyword("fileEntryTypeId", dlFileEntry.getFileEntryTypeId()); document.addKeyword("mimeType", StringUtil.replace(dlFileEntry.getMimeType(), CharPool.FORWARD_SLASH, CharPool.UNDERLINE)); document.addKeyword("path", dlFileEntry.getTitle()); document.addKeyword("readCount", dlFileEntry.getReadCount()); document.addKeyword("size", dlFileEntry.getSize()); ExpandoBridge expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(dlFileEntry.getCompanyId(), DLFileEntry.class.getName(), dlFileVersion.getFileVersionId()); ExpandoBridgeIndexerUtil.addAttributes(document, expandoBridge); addFileEntryTypeAttributes(document, dlFileVersion); if (dlFileEntry.isInHiddenFolder()) { try { Repository repository = RepositoryLocalServiceUtil.getRepository(dlFileEntry.getRepositoryId()); String portletId = repository.getPortletId(); for (Indexer indexer : IndexerRegistryUtil.getIndexers()) { if (portletId.equals(indexer.getPortletId())) { indexer.addRelatedEntryFields(document, obj); } } } catch (Exception e) { _log.error("COGNIZANT@@@@doGetDocument@@CATCH2:::" + dlFileEntry.getFileEntryId() + "@@@@" + dlFileEntry.getTitle() + "@@@@", e); fileLog.error("FileEntry ID" + dlFileEntry.getFileEntryId()); try { fileWriter = generateCsvFile(dlFileEntry.getFileEntryId(), fileCsvpath); } catch (IOException e1) { _log.error("Error Generating CSV", e1); } } } if (_log.isDebugEnabled()) { _log.debug("Document " + dlFileEntry + " indexed successfully"); } return document; } finally { if (is != null) { try { is.close(); } catch (IOException ioe) { _log.error("COGNIZANT@@@@doGetDocument@@CATCH3:::" + dlFileEntry.getFileEntryId() + "@@@@" + dlFileEntry.getTitle() + "@@@@", ioe); fileLog.error("FileEntry ID" + dlFileEntry.getFileEntryId()); try { fileWriter = generateCsvFile(dlFileEntry.getFileEntryId(), fileCsvpath); } catch (IOException e1) { _log.error("Error Generating CSV", e1); } } } } }
From source file:com.liferay.portlet.documentlibrary.util.DLIndexer.java
License:Open Source License
@Override protected Document doGetDocument(Object obj) throws Exception { DLFileEntry dlFileEntry = (DLFileEntry) obj; if (_log.isDebugEnabled()) { _log.debug("Indexing document " + dlFileEntry); }// w ww. jav a 2s . c o m boolean indexContent = true; InputStream is = null; try { if (PropsValues.DL_FILE_INDEXING_MAX_SIZE == 0) { indexContent = false; } else if (PropsValues.DL_FILE_INDEXING_MAX_SIZE != -1) { if (dlFileEntry.getSize() > PropsValues.DL_FILE_INDEXING_MAX_SIZE) { indexContent = false; } } if (indexContent) { String[] ignoreExtensions = PrefsPropsUtil .getStringArray(PropsKeys.DL_FILE_INDEXING_IGNORE_EXTENSIONS, StringPool.COMMA); if (ArrayUtil.contains(ignoreExtensions, StringPool.PERIOD + dlFileEntry.getExtension())) { indexContent = false; } } if (indexContent) { is = dlFileEntry.getFileVersion().getContentStream(false); } } catch (Exception e) { } if (indexContent && (is == null)) { if (_log.isDebugEnabled()) { _log.debug("Document " + dlFileEntry + " does not have any content"); } return null; } try { Document document = new DocumentImpl(); long fileEntryId = dlFileEntry.getFileEntryId(); document.addUID(PORTLET_ID, fileEntryId); List<AssetCategory> assetCategories = AssetCategoryLocalServiceUtil .getCategories(DLFileEntry.class.getName(), fileEntryId); long[] assetCategoryIds = StringUtil .split(ListUtil.toString(assetCategories, AssetCategory.CATEGORY_ID_ACCESSOR), 0L); document.addKeyword(Field.ASSET_CATEGORY_IDS, assetCategoryIds); String[] assetCategoryNames = StringUtil .split(ListUtil.toString(assetCategories, AssetCategory.NAME_ACCESSOR)); document.addKeyword(Field.ASSET_CATEGORY_NAMES, assetCategoryNames); String[] assetTagNames = AssetTagLocalServiceUtil.getTagNames(DLFileEntry.class.getName(), fileEntryId); document.addKeyword(Field.ASSET_TAG_NAMES, assetTagNames); document.addKeyword(Field.COMPANY_ID, dlFileEntry.getCompanyId()); if (indexContent) { try { document.addFile(Field.CONTENT, is, dlFileEntry.getTitle()); } catch (IOException ioe) { throw new SearchException("Cannot extract text from file" + dlFileEntry); } } document.addText(Field.DESCRIPTION, dlFileEntry.getDescription()); document.addKeyword(Field.ENTRY_CLASS_NAME, DLFileEntry.class.getName()); document.addKeyword(Field.ENTRY_CLASS_PK, fileEntryId); document.addKeyword(Field.FOLDER_ID, dlFileEntry.getFolderId()); document.addKeyword(Field.GROUP_ID, getParentGroupId(dlFileEntry.getGroupId())); document.addDate(Field.MODIFIED_DATE, dlFileEntry.getModifiedDate()); document.addKeyword(Field.PORTLET_ID, PORTLET_ID); document.addText(Field.PROPERTIES, dlFileEntry.getLuceneProperties()); document.addKeyword(Field.SCOPE_GROUP_ID, dlFileEntry.getGroupId()); DLFileVersion dlFileVersion = dlFileEntry.getFileVersion(); document.addKeyword(Field.STATUS, dlFileVersion.getStatus()); document.addText(Field.TITLE, dlFileEntry.getTitle()); long userId = dlFileEntry.getUserId(); document.addKeyword(Field.USER_ID, userId); document.addKeyword(Field.USER_NAME, PortalUtil.getUserName(userId, dlFileEntry.getUserName()), true); document.addKeyword("dataRepositoryId", dlFileEntry.getDataRepositoryId()); document.addKeyword("extension", dlFileEntry.getExtension()); document.addKeyword("fileEntryTypeId", dlFileEntry.getFileEntryTypeId()); document.addKeyword("path", dlFileEntry.getTitle()); ExpandoBridge expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(dlFileEntry.getCompanyId(), DLFileEntry.class.getName(), dlFileVersion.getFileVersionId()); ExpandoBridgeIndexerUtil.addAttributes(document, expandoBridge); addFileEntryTypeAttributes(document, dlFileVersion); if (_log.isDebugEnabled()) { _log.debug("Document " + dlFileEntry + " indexed successfully"); } return document; } finally { if (is != null) { try { is.close(); } catch (IOException ioe) { } } } }