1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package net.fckeditor.handlers;
22
23 import java.util.HashMap;
24 import java.util.Map;
25 import java.util.Set;
26
27 import net.fckeditor.tool.Utils;
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45 @Deprecated
46 public class ExtensionsHandler {
47
48 private static Map<ResourceType, Set<String>> extensionsAllowed = new HashMap<ResourceType, Set<String>>();
49 private static Map<ResourceType, Set<String>> extensionsDenied = new HashMap<ResourceType, Set<String>>();
50
51 static {
52
53 extensionsAllowed.put(ResourceType.FILE, Utils.getSet(PropertiesLoader
54 .getProperty("connector.resourceType.file.extensions.allowed")));
55 extensionsDenied.put(ResourceType.FILE, Utils.getSet(PropertiesLoader
56 .getProperty("connector.resourceType.file.extensions.denied")));
57 extensionsAllowed.put(ResourceType.MEDIA, Utils.getSet(PropertiesLoader
58 .getProperty("connector.resourceType.media.extensions.allowed")));
59 extensionsDenied.put(ResourceType.MEDIA, Utils.getSet(PropertiesLoader
60 .getProperty("connector.resourceType.media.extensions.denied")));
61 extensionsAllowed.put(ResourceType.IMAGE, Utils.getSet(PropertiesLoader
62 .getProperty("connector.resourceType.image.extensions.allowed")));
63 extensionsDenied.put(ResourceType.IMAGE, Utils.getSet(PropertiesLoader
64 .getProperty("connector.resourceType.image.extensions.denied")));
65 extensionsAllowed.put(ResourceType.FLASH, Utils.getSet(PropertiesLoader
66 .getProperty("connector.resourceType.flash.extensions.allowed")));
67 extensionsDenied.put(ResourceType.FLASH, Utils.getSet(PropertiesLoader
68 .getProperty("connector.resourceType.flash.extensions.denied")));
69 }
70
71
72
73
74
75
76
77
78 public static Set<String> getExtensionsAllowed(final ResourceType type) {
79 return extensionsAllowed.get(type);
80 }
81
82
83
84
85
86
87
88
89
90
91
92
93 public static void setExtensionsAllowed(final ResourceType type, final String extensionsList) {
94 if (extensionsList != null) {
95 extensionsAllowed.put(type, Utils.getSet(extensionsList));
96 extensionsDenied.get(type).clear();
97 }
98 }
99
100
101
102
103
104
105
106
107 public static Set<String> getExtensionsDenied(final ResourceType type) {
108 return extensionsDenied.get(type);
109 }
110
111
112
113
114
115
116
117
118
119
120
121
122 public static void setExtensionsDenied(final ResourceType type, final String extensionsList) {
123 if (extensionsList != null) {
124 extensionsDenied.put(type, Utils.getSet(extensionsList));
125 extensionsAllowed.get(type).clear();
126 }
127 }
128
129
130
131
132
133
134
135
136
137
138
139
140 public static boolean isAllowed(final ResourceType type, final String extension) {
141 if (type == null || extension == null)
142 return false;
143 String ext = extension.toLowerCase();
144 Set<String> allowed = extensionsAllowed.get(type);
145 Set<String> denied = extensionsDenied.get(type);
146 if (allowed.isEmpty())
147 return !denied.contains(ext);
148 if (denied.isEmpty())
149 return allowed.contains(ext);
150 return false;
151 }
152 }