List of usage examples for com.liferay.portal.kernel.util WebKeys THEME_DISPLAY
String THEME_DISPLAY
To view the source code for com.liferay.portal.kernel.util WebKeys THEME_DISPLAY.
Click Source Link
From source file:com.liferay.document.library.web.internal.portlet.action.ActionUtil.java
License:Open Source License
public static Folder getFolder(HttpServletRequest request) throws PortalException { ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); long folderId = ParamUtil.getLong(request, "folderId"); boolean ignoreRootFolder = ParamUtil.getBoolean(request, "ignoreRootFolder"); if ((folderId <= 0) && !ignoreRootFolder) { PortletDisplay portletDisplay = themeDisplay.getPortletDisplay(); String portletId = portletDisplay.getId(); PortletPreferences portletPreferences = PortletPreferencesFactoryUtil.getPortletPreferences(request, portletId);/*from w w w . j av a2 s .c om*/ folderId = GetterUtil.getLong(portletPreferences.getValue("rootFolderId", null)); } Folder folder = null; if (folderId > 0) { folder = DLAppServiceUtil.getFolder(folderId); if (folder.getModel() instanceof DLFolder) { DLFolder dlFolder = (DLFolder) folder.getModel(); if (dlFolder.isInTrash()) { throw new NoSuchFolderException("{folderId=" + folderId + "}"); } } } else { DLPermission.check(themeDisplay.getPermissionChecker(), themeDisplay.getScopeGroupId(), ActionKeys.VIEW); } return folder; }
From source file:com.liferay.document.library.web.internal.portlet.action.ActionUtil.java
License:Open Source License
public static Repository getRepository(HttpServletRequest request) throws PortalException { ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); long repositoryId = ParamUtil.getLong(request, "repositoryId"); Repository repository = null;/*from w w w.j av a2 s . c o m*/ if (repositoryId > 0) { repository = RepositoryServiceUtil.getRepository(repositoryId); } else { DLPermission.check(themeDisplay.getPermissionChecker(), themeDisplay.getScopeGroupId(), ActionKeys.VIEW); } return repository; }
From source file:com.liferay.document.library.web.internal.portlet.action.DownloadEntriesMVCResourceCommand.java
License:Open Source License
protected void downloadFileEntries(ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) resourceRequest.getAttribute(WebKeys.THEME_DISPLAY); long folderId = ParamUtil.getLong(resourceRequest, "folderId"); File file = null;//from www . j ava2 s . c om InputStream inputStream = null; try { List<FileEntry> fileEntries = ActionUtil.getFileEntries(resourceRequest); List<FileShortcut> fileShortcuts = ActionUtil.getFileShortcuts(resourceRequest); List<Folder> folders = ActionUtil.getFolders(resourceRequest); if (fileEntries.isEmpty() && fileShortcuts.isEmpty() && folders.isEmpty()) { return; } else if ((fileEntries.size() == 1) && fileShortcuts.isEmpty() && folders.isEmpty()) { FileEntry fileEntry = fileEntries.get(0); PortletResponseUtil.sendFile(resourceRequest, resourceResponse, fileEntry.getFileName(), fileEntry.getContentStream(), 0, fileEntry.getMimeType(), HttpHeaders.CONTENT_DISPOSITION_ATTACHMENT); } else if ((fileShortcuts.size() == 1) && fileEntries.isEmpty() && folders.isEmpty()) { FileShortcut fileShortcut = fileShortcuts.get(0); FileEntry fileEntry = _dlAppService.getFileEntry(fileShortcut.getToFileEntryId()); PortletResponseUtil.sendFile(resourceRequest, resourceResponse, fileEntry.getFileName(), fileEntry.getContentStream(), 0, fileEntry.getMimeType(), HttpHeaders.CONTENT_DISPOSITION_ATTACHMENT); } else { String zipFileName = getZipFileName(folderId, themeDisplay); ZipWriter zipWriter = ZipWriterFactoryUtil.getZipWriter(); for (FileEntry fileEntry : fileEntries) { zipFileEntry(fileEntry, StringPool.SLASH, zipWriter); } for (FileShortcut fileShortcut : fileShortcuts) { FileEntry fileEntry = _dlAppService.getFileEntry(fileShortcut.getToFileEntryId()); zipFileEntry(fileEntry, StringPool.SLASH, zipWriter); } for (Folder folder : folders) { zipFolder(folder.getRepositoryId(), folder.getFolderId(), StringPool.SLASH.concat(folder.getName()), zipWriter); } file = zipWriter.getFile(); inputStream = new FileInputStream(file); PortletResponseUtil.sendFile(resourceRequest, resourceResponse, zipFileName, inputStream, ContentTypes.APPLICATION_ZIP); } } finally { StreamUtil.cleanUp(inputStream); if (file != null) { file.delete(); } } }
From source file:com.liferay.document.library.web.internal.portlet.action.DownloadEntriesMVCResourceCommand.java
License:Open Source License
protected void downloadFolder(ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) resourceRequest.getAttribute(WebKeys.THEME_DISPLAY); long repositoryId = ParamUtil.getLong(resourceRequest, "repositoryId"); long folderId = ParamUtil.getLong(resourceRequest, "folderId"); File file = null;/* w w w . j av a 2 s.co m*/ InputStream inputStream = null; try { String zipFileName = getZipFileName(folderId, themeDisplay); ZipWriter zipWriter = ZipWriterFactoryUtil.getZipWriter(); zipFolder(repositoryId, folderId, StringPool.SLASH, zipWriter); file = zipWriter.getFile(); inputStream = new FileInputStream(file); PortletResponseUtil.sendFile(resourceRequest, resourceResponse, zipFileName, inputStream, ContentTypes.APPLICATION_ZIP); } finally { StreamUtil.cleanUp(inputStream); if (file != null) { file.delete(); } } }
From source file:com.liferay.document.library.web.internal.portlet.action.EditFileEntryMVCActionCommand.java
License:Open Source License
protected void addMultipleFileEntries(PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse, String selectedFileName, List<KeyValuePair> validFileNameKVPs, List<KeyValuePair> invalidFileNameKVPs) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); long repositoryId = ParamUtil.getLong(actionRequest, "repositoryId"); long folderId = ParamUtil.getLong(actionRequest, "folderId"); String description = ParamUtil.getString(actionRequest, "description"); String changeLog = ParamUtil.getString(actionRequest, "changeLog"); FileEntry tempFileEntry = null;//from w ww. ja v a 2 s . co m try { tempFileEntry = TempFileEntryUtil.getTempFileEntry(themeDisplay.getScopeGroupId(), themeDisplay.getUserId(), TEMP_FOLDER_NAME, selectedFileName); String originalSelectedFileName = TempFileEntryUtil .getOriginalTempFileName(tempFileEntry.getFileName()); String uniqueFileName = DLUtil.getUniqueFileName(tempFileEntry.getGroupId(), folderId, originalSelectedFileName); String mimeType = tempFileEntry.getMimeType(); InputStream inputStream = tempFileEntry.getContentStream(); long size = tempFileEntry.getSize(); ServiceContext serviceContext = ServiceContextFactory.getInstance(DLFileEntry.class.getName(), actionRequest); _dlAppService.addFileEntry(repositoryId, folderId, uniqueFileName, mimeType, uniqueFileName, description, changeLog, inputStream, size, serviceContext); validFileNameKVPs.add(new KeyValuePair(uniqueFileName, selectedFileName)); return; } catch (Exception e) { String errorMessage = getAddMultipleFileEntriesErrorMessage(portletConfig, actionRequest, actionResponse, e); invalidFileNameKVPs.add(new KeyValuePair(selectedFileName, errorMessage)); } finally { if (tempFileEntry != null) { TempFileEntryUtil.deleteTempFileEntry(tempFileEntry.getFileEntryId()); } } }
From source file:com.liferay.document.library.web.internal.portlet.action.EditFileEntryMVCActionCommand.java
License:Open Source License
protected void addTempFileEntry(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { UploadPortletRequest uploadPortletRequest = _portal.getUploadPortletRequest(actionRequest); ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); long folderId = ParamUtil.getLong(uploadPortletRequest, "folderId"); String sourceFileName = uploadPortletRequest.getFileName("file"); InputStream inputStream = null; try {/*from w ww . j a va 2s . c om*/ String tempFileName = TempFileEntryUtil.getTempFileName(sourceFileName); inputStream = uploadPortletRequest.getFileAsStream("file"); String mimeType = uploadPortletRequest.getContentType("file"); FileEntry fileEntry = _dlAppService.addTempFileEntry(themeDisplay.getScopeGroupId(), folderId, TEMP_FOLDER_NAME, tempFileName, inputStream, mimeType); JSONObject jsonObject = JSONFactoryUtil.createJSONObject(); jsonObject.put("groupId", fileEntry.getGroupId()); jsonObject.put("name", fileEntry.getTitle()); jsonObject.put("title", sourceFileName); jsonObject.put("uuid", fileEntry.getUuid()); JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject); } finally { StreamUtil.cleanUp(inputStream); } }
From source file:com.liferay.document.library.web.internal.portlet.action.EditFileEntryMVCActionCommand.java
License:Open Source License
protected void deleteTempFileEntry(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); long folderId = ParamUtil.getLong(actionRequest, "folderId"); String fileName = ParamUtil.getString(actionRequest, "fileName"); JSONObject jsonObject = JSONFactoryUtil.createJSONObject(); try {/*from w w w . j av a2 s. c o m*/ _dlAppService.deleteTempFileEntry(themeDisplay.getScopeGroupId(), folderId, TEMP_FOLDER_NAME, fileName); jsonObject.put("deleted", Boolean.TRUE); } catch (Exception e) { String errorMessage = themeDisplay.translate("an-unexpected-error-occurred-while-deleting-the-file"); jsonObject.put("deleted", Boolean.FALSE); jsonObject.put("errorMessage", errorMessage); } JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject); }
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;/*ww w . j a v a2s. c o m*/ 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 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 {// w w w.ja va2 s .c o m 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.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()); }/* w w w.java 2s.com*/ 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; } } }