Example usage for com.liferay.portal.kernel.util MimeTypesUtil getExtensions

List of usage examples for com.liferay.portal.kernel.util MimeTypesUtil getExtensions

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util MimeTypesUtil getExtensions.

Prototype

public static Set<String> getExtensions(String contentType) 

Source Link

Document

Returns the possible file extensions for the content type.

Usage

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 .jav a  2s.  co  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.portlet.documentlibrary.util.PDFProcessorImpl.java

License:Open Source License

public boolean isSupported(String mimeType) {
    if (Validator.isNull(mimeType)) {
        return false;
    }//from   w w  w.  j av  a2 s .  c  om

    if (mimeType.equals(ContentTypes.APPLICATION_PDF) || mimeType.equals(ContentTypes.APPLICATION_X_PDF)) {

        return true;
    }

    if (DocumentConversionUtil.isEnabled()) {
        Set<String> extensions = MimeTypesUtil.getExtensions(mimeType);

        for (String extension : extensions) {
            extension = extension.substring(1);

            String[] targetExtensions = DocumentConversionUtil.getConversions(extension);

            if (Arrays.binarySearch(targetExtensions, "pdf") >= 0) {
                return true;
            }
        }
    }

    return false;
}