From de4d77228308ed50e4ed6c0e1a4b43e36fd99260 Mon Sep 17 00:00:00 2001 From: Ilia Motornyi Date: Thu, 3 May 2018 09:49:59 +0300 Subject: Fix using runo icons in FileTypeResolver (#10858) This patch adds a compatibility version of FileTypeResolver. --- .../java/com/vaadin/util/FileTypeResolver.java | 74 +--------------------- .../tests/server/ClassesSerializableTest.java | 1 + 2 files changed, 3 insertions(+), 72 deletions(-) (limited to 'server') diff --git a/server/src/main/java/com/vaadin/util/FileTypeResolver.java b/server/src/main/java/com/vaadin/util/FileTypeResolver.java index 4606463683..c3fc5c0756 100644 --- a/server/src/main/java/com/vaadin/util/FileTypeResolver.java +++ b/server/src/main/java/com/vaadin/util/FileTypeResolver.java @@ -38,7 +38,7 @@ import com.vaadin.server.ThemeResource; * @since 3.0 */ @SuppressWarnings("serial") -public class FileTypeResolver implements Serializable { +public class FileTypeResolver { /** * Default icon given if no icon is specified for a mime-type. @@ -213,11 +213,6 @@ public class FileTypeResolver implements Serializable { */ private static final Map EXT_TO_MIME_MAP = new ConcurrentHashMap<>(); - /** - * MIME type to Icon mapping. - */ - private static final Map MIME_TO_ICON_MAP = new ConcurrentHashMap<>(); - static { // Initialize extension to MIME map @@ -233,10 +228,6 @@ public class FileTypeResolver implements Serializable { } } - // Initialize Icons - ThemeResource folder = new ThemeResource("../runo/icons/16/folder.png"); - addIcon("inode/drive", folder); - addIcon("inode/directory", folder); } /** @@ -281,45 +272,6 @@ public class FileTypeResolver implements Serializable { return DEFAULT_MIME_TYPE; } - /** - * Gets the descriptive icon representing file, based on the filename. First - * the mime-type for the given filename is resolved, and then the - * corresponding icon is fetched from the internal icon storage. If it is - * not found the default icon is returned. - * - * @param fileName - * the name of the file whose icon is requested. - * @return the icon corresponding to the given file - */ - public static Resource getIcon(String fileName) { - return getIconByMimeType(getMIMEType(fileName)); - } - - private static Resource getIconByMimeType(String mimeType) { - final Resource icon = MIME_TO_ICON_MAP.get(mimeType); - if (icon != null) { - return icon; - } - - // If nothing is known about the file-type, general file - // icon is used - return DEFAULT_ICON; - } - - /** - * Gets the descriptive icon representing a file. First the mime-type for - * the given file name is resolved, and then the corresponding icon is - * fetched from the internal icon storage. If it is not found the default - * icon is returned. - * - * @param file - * the file whose icon is requested. - * @return the icon corresponding to the given file - */ - public static Resource getIcon(File file) { - return getIconByMimeType(getMIMEType(file)); - } - /** * Gets the mime-type for a file. Currently the returned file type is * resolved by the filename extension only. @@ -363,19 +315,6 @@ public class FileTypeResolver implements Serializable { EXT_TO_MIME_MAP.put(extension.toLowerCase(Locale.ROOT), mimeType); } - /** - * Adds a icon for the given mime-type. If the mime-type also has a - * corresponding icon, it is replaced with the new icon. - * - * @param mimeType - * the mime-type whose icon is to be changed. - * @param icon - * the new icon to be associated with MIMEType. - */ - public static void addIcon(String mimeType, Resource icon) { - MIME_TO_ICON_MAP.put(mimeType, icon); - } - /** * Gets the internal file extension to mime-type mapping. * @@ -386,15 +325,6 @@ public class FileTypeResolver implements Serializable { return Collections.unmodifiableMap(EXT_TO_MIME_MAP); } - /** - * Gets the internal mime-type to icon mapping. - * - * @return unmodifiable map containing the current mime-type to icon mapping - */ - public static Map getMIMETypeToIconMapping() { - return Collections.unmodifiableMap(MIME_TO_ICON_MAP); - } - - private FileTypeResolver() { + protected FileTypeResolver() { } } diff --git a/server/src/test/java/com/vaadin/tests/server/ClassesSerializableTest.java b/server/src/test/java/com/vaadin/tests/server/ClassesSerializableTest.java index 0827fc262c..819f0530c1 100644 --- a/server/src/test/java/com/vaadin/tests/server/ClassesSerializableTest.java +++ b/server/src/test/java/com/vaadin/tests/server/ClassesSerializableTest.java @@ -54,6 +54,7 @@ public class ClassesSerializableTest { "com\\.vaadin\\.ui\\.themes\\..*", // // exact class level filtering "com\\.vaadin\\.event\\.FieldEvents", // + "com\\.vaadin\\.util\\.FileTypeResolver", "com\\.vaadin\\.event\\.LayoutEvents", // "com\\.vaadin\\.event\\.MouseEvents", // "com\\.vaadin\\.event\\.UIEvents", // -- cgit v1.2.3