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 javax.servlet.http.HttpServletRequest;
24
25 import net.fckeditor.connector.Connector;
26 import net.fckeditor.requestcycle.UserAction;
27 import net.fckeditor.requestcycle.UserPathBuilder;
28 import net.fckeditor.tool.Utils;
29
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32
33
34
35
36
37
38
39
40 public class RequestCycleHandler {
41 private static final Logger logger = LoggerFactory
42 .getLogger(RequestCycleHandler.class);
43 private static UserAction userAction = null;
44 private static UserPathBuilder userPathBuilder = null;
45
46 static {
47
48
49
50
51 String className = PropertiesLoader.getUserActionImpl();
52 if (Utils.isEmpty(className))
53 logger.error("Empty UserAction implementation class name provided");
54 else {
55 try {
56 Class<?> clazz = Class.forName(className);
57 userAction = (UserAction) clazz.newInstance();
58 logger.info("UserAction initialized to {}", className);
59 } catch (Throwable e) {
60 logger.error("UserAction implementation {} could not be instantiated", className);
61 throw new RuntimeException("UserAction implementation " + className + " could not be instantiated", e);
62 }
63 }
64
65
66 className = PropertiesLoader.getUserPathBuilderImpl();
67 if (Utils.isEmpty(className))
68 logger.error("Empty UserPathBuilder implementation class name provided");
69 else {
70 try {
71 Class<?> clazz = Class.forName(className);
72 userPathBuilder = (UserPathBuilder) clazz.newInstance();
73 logger.info("UserPathBuilder initialized to {}", className);
74 } catch (Throwable e) {
75 logger.error("UserPathBuilder implementation {} could not be instantiated", className);
76 throw new RuntimeException("UserPathBuilder implementation " + className + " could not be instantiated", e);
77 }
78 }
79 }
80
81
82
83
84
85
86
87
88
89
90 public static boolean isGetResourcesEnabled(final HttpServletRequest request) {
91 return userAction.isEnabledForFileBrowsing(request);
92 }
93
94
95
96
97
98
99
100
101
102
103 public static boolean isFileUploadEnabled(HttpServletRequest request) {
104 return userAction.isEnabledForFileUpload(request);
105 }
106
107
108
109
110
111
112
113
114
115
116 public static boolean isCreateFolderEnabled(final HttpServletRequest request) {
117 return userAction.isCreateFolderEnabled(request);
118 }
119
120
121
122
123
124
125
126
127
128
129 public static String getUserFilesPath(final HttpServletRequest request) {
130 return userPathBuilder.getUserFilesPath(request);
131 }
132
133
134
135
136
137
138
139
140
141
142
143
144 public static String getUserFilesAbsolutePath(final HttpServletRequest request) {
145 return userPathBuilder.getUserFilesAbsolutePath(request);
146 }
147 }