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 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 private static Set<String> commands = new HashSet<String>(3);
59
60 static {
61 commands.add(FILE_UPLOAD);
62 commands.add(FILE_BROWSING);
63 commands.add(COMPATIBLE_BROWSER);
64 }
65
66 private String command;
67
68
69
70
71
72
73 public void setCommand(String command) throws JspTagException {
74 if (!commands.contains(command))
75 throw new JspTagException("You have to provide one of the following commands: "
76 + commands);
77 this.command = command;
78 }
79
80 @Override
81 public int doStartTag() throws JspException {
82 JspWriter out = pageContext.getOut();
83
84 HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
85 String response = null;
86
87 if (command.equals(FILE_UPLOAD)) {
88 if (RequestCycleHandler.isEnabledForFileUpload(request))
89 response = PropertiesLoader
90 .getProperty(CheckTag.PROPERTY_MESSAGE_FILE_UPLOAD_ENABLED);
91 else
92 response = PropertiesLoader
93 .getProperty(CheckTag.PROPERTY_MESSAGE_FILE_UPLOAD_DISABLED);
94 }
95
96 if (command.equals(FILE_BROWSING)) {
97 if (RequestCycleHandler.isEnabledForFileBrowsing(request))
98 response = PropertiesLoader
99 .getProperty(CheckTag.PROPERTY_MESSAGE_FILE_BROWSING_ENABLED);
100 else
101 response = PropertiesLoader
102 .getProperty(CheckTag.PROPERTY_MESSAGE_FILE_BROWSING_DISABLED);
103 }
104 if (command.equals(COMPATIBLE_BROWSER)) {
105 if (Compatibility.isCompatibleBrowser(request))
106 response = PropertiesLoader
107 .getProperty(CheckTag.PROPERTY_MESSAGE_COMPATIBLE_BROWSER);
108 else
109 response = PropertiesLoader
110 .getProperty(CheckTag.PROPERTY_MESSAGE_NOT_COMPATIBLE_BROWSER);
111 }
112
113 try {
114 out.print(response);
115 } catch (IOException e) {
116 throw new JspException("Tag response could not be written to the user!",e);
117 }
118
119 return SKIP_BODY;
120 }
121
122 }