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