Example usage for com.liferay.portal.kernel.exception ImageTypeException ImageTypeException

List of usage examples for com.liferay.portal.kernel.exception ImageTypeException ImageTypeException

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.exception ImageTypeException ImageTypeException.

Prototype

public ImageTypeException() 

Source Link

Usage

From source file:com.liferay.image.uploader.web.internal.portlet.action.UploadImageMVCActionCommand.java

License:Open Source License

protected FileEntry addTempImageFileEntry(PortletRequest portletRequest) throws Exception {

    UploadPortletRequest uploadPortletRequest = _portal.getUploadPortletRequest(portletRequest);

    ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

    String contentType = uploadPortletRequest.getContentType("fileName");

    String fileName = uploadPortletRequest.getFileName("fileName");

    File file = uploadPortletRequest.getFile("fileName");

    String mimeType = MimeTypesUtil.getContentType(file, fileName);

    if (!StringUtil.equalsIgnoreCase(ContentTypes.APPLICATION_OCTET_STREAM, mimeType)) {

        contentType = mimeType;/*from ww  w .  jav  a  2 s  . c o  m*/
    }

    if (!MimeTypesUtil.isWebImage(contentType)) {
        throw new ImageTypeException();
    }

    try {
        TempFileEntryUtil.deleteTempFileEntry(themeDisplay.getScopeGroupId(), themeDisplay.getUserId(),
                UploadImageUtil.getTempImageFolderName(), fileName);
    } catch (Exception e) {
    }

    return TempFileEntryUtil.addTempFileEntry(themeDisplay.getScopeGroupId(), themeDisplay.getUserId(),
            UploadImageUtil.getTempImageFolderName(), fileName, file, contentType);
}