diff options
4 files changed, 128 insertions, 73 deletions
diff --git a/compatibility-server/src/main/java/com/vaadin/v7/data/util/FilesystemContainer.java b/compatibility-server/src/main/java/com/vaadin/v7/data/util/FilesystemContainer.java index 6789e9bd81..f5105343c5 100644 --- a/compatibility-server/src/main/java/com/vaadin/v7/data/util/FilesystemContainer.java +++ b/compatibility-server/src/main/java/com/vaadin/v7/data/util/FilesystemContainer.java @@ -30,7 +30,7 @@ import java.util.LinkedList; import java.util.List; import com.vaadin.server.Resource; -import com.vaadin.util.FileTypeResolver; +import com.vaadin.v7.util.FileTypeResolver; import com.vaadin.v7.data.Container; import com.vaadin.v7.data.Item; import com.vaadin.v7.data.Property; diff --git a/compatibility-server/src/main/java/com/vaadin/v7/util/FileTypeResolver.java b/compatibility-server/src/main/java/com/vaadin/v7/util/FileTypeResolver.java new file mode 100644 index 0000000000..2a46c25b09 --- /dev/null +++ b/compatibility-server/src/main/java/com/vaadin/v7/util/FileTypeResolver.java @@ -0,0 +1,124 @@ +/* + * Copyright 2000-2018 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.vaadin.v7.util; + +import java.io.File; +import java.io.Serializable; +import java.util.Collections; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import com.vaadin.server.Resource; +import com.vaadin.server.ThemeResource; + +/** + * Utility class that can figure out mime-types and icons related to files. + * <p> + * Note : The icons are associated purely to mime-types, so a file may not have + * a custom icon accessible with this class. + * </p> + * + * @author Vaadin Ltd. + * @since 3.0 + * @deprecated Only used for compatibility-server + */ +@Deprecated +@SuppressWarnings("serial") +public class FileTypeResolver extends com.vaadin.util.FileTypeResolver implements Serializable { + + /** + * Default icon given if no icon is specified for a mime-type. + */ + public static Resource DEFAULT_ICON = new ThemeResource( + "../runo/icons/16/document.png"); + + /** + * MIME type to Icon mapping. + */ + private static final Map<String, Resource> MIME_TO_ICON_MAP = new ConcurrentHashMap<>(); + + static { + // Initialize Icon2s + ThemeResource folder = new ThemeResource("../runo/icons/16/folder.png"); + addIcon("inode/drive", folder); + addIcon("inode/directory", folder); + } + + /** + * 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)); + } + + /** + * 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 <code>MIMEType</code>. + */ + public static void addIcon(String mimeType, Resource icon) { + MIME_TO_ICON_MAP.put(mimeType, icon); + } + + /** + * Gets the internal mime-type to icon mapping. + * + * @return unmodifiable map containing the current mime-type to icon mapping + */ + public static Map<String, Resource> getMIMETypeToIconMapping() { + return Collections.unmodifiableMap(MIME_TO_ICON_MAP); + } + + private FileTypeResolver() { + } +} 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<String, String> EXT_TO_MIME_MAP = new ConcurrentHashMap<>(); - /** - * MIME type to Icon mapping. - */ - private static final Map<String, Resource> 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); } /** @@ -282,45 +273,6 @@ public class FileTypeResolver implements Serializable { } /** - * 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. * @@ -364,19 +316,6 @@ public class FileTypeResolver implements Serializable { } /** - * 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 <code>MIMEType</code>. - */ - public static void addIcon(String mimeType, Resource icon) { - MIME_TO_ICON_MAP.put(mimeType, icon); - } - - /** * Gets the internal file extension to mime-type mapping. * * @return unmodifiable map containing the current file extension to @@ -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<String, Resource> 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", // |