List of usage examples for com.liferay.portal.kernel.upload UploadException UploadException
public UploadException(Throwable cause)
From source file:com.liferay.image.uploader.web.internal.portlet.action.UploadImageMVCActionCommand.java
License:Open Source License
protected FileEntry saveTempImageFileEntry(ActionRequest actionRequest) throws Exception { try {//from ww w. j av a 2 s .c om FileEntry tempFileEntry = UploadImageUtil.getTempImageFileEntry(actionRequest); try (InputStream tempImageStream = tempFileEntry.getContentStream()) { ImageBag imageBag = ImageToolUtil.read(tempImageStream); RenderedImage renderedImage = imageBag.getRenderedImage(); String cropRegionJSON = ParamUtil.getString(actionRequest, "cropRegion"); if (Validator.isNotNull(cropRegionJSON)) { JSONObject jsonObject = JSONFactoryUtil.createJSONObject(cropRegionJSON); int height = jsonObject.getInt("height"); int width = jsonObject.getInt("width"); int x = jsonObject.getInt("x"); int y = jsonObject.getInt("y"); if ((x == 0) && (y == 0) && (renderedImage.getHeight() == height) && (renderedImage.getWidth() == width)) { return tempFileEntry; } if ((height + y) > renderedImage.getHeight()) { height = renderedImage.getHeight() - y; } if ((width + x) > renderedImage.getWidth()) { width = renderedImage.getWidth() - x; } renderedImage = ImageToolUtil.crop(renderedImage, height, width, x, y); } byte[] bytes = ImageToolUtil.getBytes(renderedImage, imageBag.getType()); ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); File file = FileUtil.createTempFile(bytes); try { TempFileEntryUtil.deleteTempFileEntry(themeDisplay.getScopeGroupId(), themeDisplay.getUserId(), UploadImageUtil.getTempImageFolderName(), getTempImageFileName(actionRequest)); } catch (Exception e) { } return TempFileEntryUtil.addTempFileEntry(themeDisplay.getScopeGroupId(), themeDisplay.getUserId(), UploadImageUtil.getTempImageFolderName(), getTempImageFileName(actionRequest), file, tempFileEntry.getMimeType()); } } catch (NoSuchFileEntryException nsfee) { throw new UploadException(nsfee); } catch (NoSuchRepositoryException nsre) { throw new UploadException(nsre); } }
From source file:com.liferay.portlet.layoutsadmin.action.EditLayoutSetAction.java
License:Open Source License
protected void updateLogo(ActionRequest actionRequest, long liveGroupId, long stagingGroupId, boolean privateLayout, boolean hasLogo) throws Exception { UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest); boolean useLogo = ParamUtil.getBoolean(actionRequest, "useLogo"); InputStream inputStream = null; try {/*from w w w .j a v a 2 s .co m*/ File file = uploadPortletRequest.getFile("logoFileName"); if (useLogo && !file.exists()) { if (hasLogo) { return; } throw new UploadException("No logo uploaded for use"); } if (file.exists()) { inputStream = new ByteArrayFileInputStream(file, 1024); } if (inputStream != null) { inputStream.mark(0); } LayoutSetServiceUtil.updateLogo(liveGroupId, privateLayout, useLogo, inputStream, false); if (inputStream != null) { inputStream.reset(); } if (stagingGroupId > 0) { LayoutSetServiceUtil.updateLogo(stagingGroupId, privateLayout, useLogo, inputStream, false); } } finally { StreamUtil.cleanUp(inputStream); } }