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
26 import net.fckeditor.tool.Utils;
27
28
29
30
31
32
33 public class ResourceTypeHandler {
34
35 private String name;
36 private static Map<String, ResourceTypeHandler> types = new HashMap<String, ResourceTypeHandler>(
37 4);
38 private static Map<ResourceTypeHandler, String> paths = new HashMap<ResourceTypeHandler, String>(
39 4);
40 public static final ResourceTypeHandler FILE = new ResourceTypeHandler("File");
41 public static final ResourceTypeHandler FLASH = new ResourceTypeHandler("Flash");
42 public static final ResourceTypeHandler IMAGE = new ResourceTypeHandler("Image");
43 public static final ResourceTypeHandler MEDIA = new ResourceTypeHandler("Media");
44
45 static {
46
47 types.put(FILE.getName(), FILE);
48 types.put(FLASH.getName(), FLASH);
49 types.put(IMAGE.getName(), IMAGE);
50 types.put(MEDIA.getName(), MEDIA);
51
52
53 paths.put(FILE, PropertiesLoader.getProperty("connector.resourceType.file.path"));
54 paths.put(IMAGE, PropertiesLoader.getProperty("connector.resourceType.image.path"));
55 paths.put(FLASH, PropertiesLoader.getProperty("connector.resourceType.flash.path"));
56 paths.put(MEDIA, PropertiesLoader.getProperty("connector.resourceType.media.path"));
57 }
58
59 private ResourceTypeHandler(final String name) {
60 this.name = name;
61 }
62
63
64
65
66
67
68 public String getName() {
69 return name;
70 }
71
72
73
74
75
76
77 public String getPath() {
78 return paths.get(this);
79 }
80
81
82
83
84
85
86
87
88
89
90
91 public static ResourceTypeHandler valueOf(final String name) throws IllegalArgumentException {
92 if (Utils.isEmpty(name))
93 throw new IllegalArgumentException();
94
95 ResourceTypeHandler rt = types.get(name);
96 if (rt == null)
97 throw new IllegalArgumentException();
98 return rt;
99 }
100
101
102
103
104
105
106
107
108
109
110 public static boolean isValid(final String name) {
111 return types.containsKey(name);
112 }
113
114
115
116
117
118
119
120
121 public static ResourceTypeHandler getDefaultResourceType(final String name) {
122 ResourceTypeHandler rt = getResourceType(name);
123 return rt == null ? FILE : rt;
124 }
125
126
127
128
129
130
131
132
133
134
135 public static ResourceTypeHandler getResourceType(final String name) {
136 try {
137 return ResourceTypeHandler.valueOf(name);
138 } catch (Exception e) {
139 return null;
140 }
141 }
142
143
144
145
146
147
148 @Override
149 public boolean equals(Object obj) {
150 if (obj == null)
151 return false;
152 try {
153 ResourceTypeHandler rt = (ResourceTypeHandler) obj;
154 return name.equals(rt.getName());
155 } catch (ClassCastException e) {
156 return false;
157 }
158 }
159
160
161
162
163
164
165 @Override
166 public int hashCode() {
167 return name.hashCode();
168 }
169
170
171
172
173
174
175 @Override
176 public String toString() {
177 return name;
178 }
179 }