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 | |
import net.fckeditor.handlers.PropertiesLoader; |
34 | |
import net.fckeditor.handlers.RequestCycleHandler; |
35 | |
import net.fckeditor.tool.Compatibility; |
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | 0 | public class CheckTag extends TagSupport { |
46 | |
|
47 | |
private static final long serialVersionUID = -6834095891675681686L; |
48 | |
|
49 | |
private static final String FILE_UPLOAD = "FileUpload"; |
50 | |
private static final String FILE_BROWSING = "FileBrowsing"; |
51 | |
private static final String COMPATIBLE_BROWSER = "CompatibleBrowser"; |
52 | |
private static final String PROPERTY_MESSAGE_FILE_BROWSING_DISABLED = "message.enabled_tag.connector.file_browsing.disabled"; |
53 | |
private static final String PROPERTY_MESSAGE_FILE_BROWSING_ENABLED = "message.enabled_tag.connector.file_browsing.enabled"; |
54 | |
private static final String PROPERTY_MESSAGE_FILE_UPLOAD_DISABLED = "message.enabled_tag.connector.file_upload.disalbed"; |
55 | |
private static final String PROPERTY_MESSAGE_FILE_UPLOAD_ENABLED = "message.enabled_tag.connector.file_upload.enabled"; |
56 | |
private static final String PROPERTY_MESSAGE_NOT_COMPATIBLE_BROWSER = "message.enabled_tag.compatible_browser.no"; |
57 | |
private static final String PROPERTY_MESSAGE_COMPATIBLE_BROWSER = "message.enabled_tag.compatible_browser.yes"; |
58 | 0 | private static Set<String> commands = new HashSet<String>(3); |
59 | |
|
60 | |
static { |
61 | 0 | commands.add(FILE_UPLOAD); |
62 | 0 | commands.add(FILE_BROWSING); |
63 | 0 | commands.add(COMPATIBLE_BROWSER); |
64 | 0 | } |
65 | |
|
66 | |
private String command; |
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
public void setCommand(String command) throws JspTagException { |
74 | 0 | if (!commands.contains(command)) |
75 | 0 | throw new JspTagException("You have to provide one of the following commands: " |
76 | |
+ commands); |
77 | 0 | this.command = command; |
78 | 0 | } |
79 | |
|
80 | |
@Override |
81 | |
public int doStartTag() throws JspException { |
82 | 0 | JspWriter out = pageContext.getOut(); |
83 | |
|
84 | 0 | HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); |
85 | 0 | String response = null; |
86 | |
|
87 | 0 | if (command.equals(FILE_UPLOAD)) { |
88 | 0 | if (RequestCycleHandler.isEnabledForFileUpload(request)) |
89 | 0 | response = PropertiesLoader |
90 | |
.getProperty(CheckTag.PROPERTY_MESSAGE_FILE_UPLOAD_ENABLED); |
91 | |
else |
92 | 0 | response = PropertiesLoader |
93 | |
.getProperty(CheckTag.PROPERTY_MESSAGE_FILE_UPLOAD_DISABLED); |
94 | |
} |
95 | |
|
96 | 0 | if (command.equals(FILE_BROWSING)) { |
97 | 0 | if (RequestCycleHandler.isEnabledForFileBrowsing(request)) |
98 | 0 | response = PropertiesLoader |
99 | |
.getProperty(CheckTag.PROPERTY_MESSAGE_FILE_BROWSING_ENABLED); |
100 | |
else |
101 | 0 | response = PropertiesLoader |
102 | |
.getProperty(CheckTag.PROPERTY_MESSAGE_FILE_BROWSING_DISABLED); |
103 | |
} |
104 | 0 | if (command.equals(COMPATIBLE_BROWSER)) { |
105 | 0 | if (Compatibility.isCompatibleBrowser(request)) |
106 | 0 | response = PropertiesLoader |
107 | |
.getProperty(CheckTag.PROPERTY_MESSAGE_COMPATIBLE_BROWSER); |
108 | |
else |
109 | 0 | response = PropertiesLoader |
110 | |
.getProperty(CheckTag.PROPERTY_MESSAGE_NOT_COMPATIBLE_BROWSER); |
111 | |
} |
112 | |
|
113 | |
try { |
114 | 0 | out.print(response); |
115 | 0 | } catch (IOException e) { |
116 | 0 | throw new JspException("Tag response could not be written to the user!",e); |
117 | 0 | } |
118 | |
|
119 | 0 | return SKIP_BODY; |
120 | |
} |
121 | |
|
122 | |
} |