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 | |
@Deprecated |
62 | |
private static final String FILE_BROWSING = "FileBrowsing"; |
63 | |
private static final String GET_RESOURCES = "GetResources"; |
64 | |
@Deprecated |
65 | |
private static final String FOLDER_CREATION = "FolderCreation"; |
66 | |
private static final String CREATE_FOLDER = "CreateFolder"; |
67 | |
private static final String COMPATIBLE_BROWSER = "CompatibleBrowser"; |
68 | |
|
69 | 0 | private static final Set<String> commands = new HashSet<String>(6); |
70 | |
|
71 | |
static { |
72 | 0 | commands.add(FILE_UPLOAD); |
73 | 0 | commands.add(FILE_BROWSING); |
74 | 0 | commands.add(FOLDER_CREATION); |
75 | 0 | commands.add(COMPATIBLE_BROWSER); |
76 | 0 | commands.add(GET_RESOURCES); |
77 | 0 | commands.add(CREATE_FOLDER); |
78 | 0 | } |
79 | |
|
80 | |
private String command; |
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
public void setCommand(String command) throws JspTagException { |
91 | 0 | if (!commands.contains(command)) |
92 | 0 | throw new JspTagException( |
93 | |
"You have to provide one of the following commands: " |
94 | |
+ commands); |
95 | 0 | this.command = command; |
96 | 0 | } |
97 | |
|
98 | |
@Override |
99 | |
public int doStartTag() throws JspException { |
100 | 0 | JspWriter out = pageContext.getOut(); |
101 | |
|
102 | 0 | HttpServletRequest request = (HttpServletRequest) pageContext |
103 | |
.getRequest(); |
104 | 0 | LocalizedMessages lm = LocalizedMessages.getInstance(request); |
105 | 0 | String response = null; |
106 | |
|
107 | 0 | if (command.equals(FILE_UPLOAD)) { |
108 | 0 | if (RequestCycleHandler.isEnabledForFileUpload(request)) |
109 | 0 | response = lm.getFileUploadEnabled(); |
110 | |
else |
111 | 0 | response = lm.getFileUploadDisabled(); |
112 | |
} |
113 | |
|
114 | 0 | if (command.equals(FILE_BROWSING) || command.equals(GET_RESOURCES)) { |
115 | 0 | if (RequestCycleHandler.isEnabledForFileBrowsing(request)) |
116 | 0 | response = lm.getGetResourcesEnabled(); |
117 | |
else |
118 | 0 | response = lm.getGetResourcesDisabled(); |
119 | |
} |
120 | |
|
121 | 0 | if (command.equals(FOLDER_CREATION) || command.equals(CREATE_FOLDER)) { |
122 | 0 | if (RequestCycleHandler.isCreateFolderEnabled(request)) |
123 | 0 | response = lm.getCreateFolderEnabled(); |
124 | |
else |
125 | 0 | response = lm.getCreateFolderDisabled(); |
126 | |
} |
127 | |
|
128 | 0 | if (command.equals(COMPATIBLE_BROWSER)) { |
129 | 0 | if (Compatibility.isCompatibleBrowser(request)) |
130 | 0 | response = lm.getCompatibleBrowserYes(); |
131 | |
else |
132 | 0 | response = lm.getCompatibleBrowserNo(); |
133 | |
} |
134 | |
|
135 | |
try { |
136 | 0 | out.print(response); |
137 | 0 | } catch (IOException e) { |
138 | 0 | throw new JspException( |
139 | |
"Tag response could not be written to the user!", e); |
140 | 0 | } |
141 | |
|
142 | 0 | return SKIP_BODY; |
143 | |
} |
144 | |
|
145 | |
} |