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