1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
package net.fckeditor.tags; |
22 | |
|
23 | |
import java.io.IOException; |
24 | |
import java.util.HashSet; |
25 | |
import java.util.Set; |
26 | |
|
27 | |
import javax.servlet.http.HttpServletRequest; |
28 | |
import javax.servlet.jsp.JspException; |
29 | |
import javax.servlet.jsp.JspTagException; |
30 | |
import javax.servlet.jsp.JspWriter; |
31 | |
import javax.servlet.jsp.tagext.TagSupport; |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
import net.fckeditor.handlers.RequestCycleHandler; |
37 | |
import net.fckeditor.localization.LocalizedMessages; |
38 | |
import net.fckeditor.tool.Compatibility; |
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | 0 | public class CheckTag extends TagSupport { |
57 | |
|
58 | |
private static final long serialVersionUID = -6834095891675681686L; |
59 | |
|
60 | |
private static final String FILE_UPLOAD = "FileUpload"; |
61 | |
private static final String GET_RESOURCES = "GetResources"; |
62 | |
private static final String CREATE_FOLDER = "CreateFolder"; |
63 | |
private static final String COMPATIBLE_BROWSER = "CompatibleBrowser"; |
64 | |
|
65 | 0 | private static final Set<String> commands = new HashSet<String>(4); |
66 | |
|
67 | |
static { |
68 | 0 | commands.add(FILE_UPLOAD); |
69 | 0 | commands.add(COMPATIBLE_BROWSER); |
70 | 0 | commands.add(GET_RESOURCES); |
71 | 0 | commands.add(CREATE_FOLDER); |
72 | 0 | } |
73 | |
|
74 | |
private String command; |
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
public void setCommand(String command) throws JspTagException { |
85 | 0 | if (!commands.contains(command)) |
86 | 0 | throw new JspTagException( |
87 | |
"You have to provide one of the following commands: " |
88 | |
+ commands); |
89 | 0 | this.command = command; |
90 | 0 | } |
91 | |
|
92 | |
@Override |
93 | |
public int doStartTag() throws JspException { |
94 | 0 | JspWriter out = pageContext.getOut(); |
95 | |
|
96 | 0 | HttpServletRequest request = (HttpServletRequest) pageContext |
97 | |
.getRequest(); |
98 | 0 | LocalizedMessages lm = LocalizedMessages.getInstance(request); |
99 | 0 | String response = null; |
100 | |
|
101 | 0 | if (command.equals(FILE_UPLOAD)) { |
102 | 0 | if (RequestCycleHandler.isFileUploadEnabled(request)) |
103 | 0 | response = lm.getFileUploadEnabled(); |
104 | |
else |
105 | 0 | response = lm.getFileUploadDisabled(); |
106 | |
} |
107 | |
|
108 | 0 | if (command.equals(GET_RESOURCES)) { |
109 | 0 | if (RequestCycleHandler.isGetResourcesEnabled(request)) |
110 | 0 | response = lm.getGetResourcesEnabled(); |
111 | |
else |
112 | 0 | response = lm.getGetResourcesDisabled(); |
113 | |
} |
114 | |
|
115 | 0 | if (command.equals(CREATE_FOLDER)) { |
116 | 0 | if (RequestCycleHandler.isCreateFolderEnabled(request)) |
117 | 0 | response = lm.getCreateFolderEnabled(); |
118 | |
else |
119 | 0 | response = lm.getCreateFolderDisabled(); |
120 | |
} |
121 | |
|
122 | 0 | if (command.equals(COMPATIBLE_BROWSER)) { |
123 | 0 | if (Compatibility.isCompatibleBrowser(request)) |
124 | 0 | response = lm.getCompatibleBrowserYes(); |
125 | |
else |
126 | 0 | response = lm.getCompatibleBrowserNo(); |
127 | |
} |
128 | |
|
129 | |
try { |
130 | 0 | out.print(response); |
131 | 0 | } catch (IOException e) { |
132 | 0 | throw new JspException( |
133 | |
"Tag response could not be written to the user!", e); |
134 | 0 | } |
135 | |
|
136 | 0 | return SKIP_BODY; |
137 | |
} |
138 | |
|
139 | |
} |