01: package org.osbl.client.wings.shell;
02:
03: import java.io.File;
04:
05: import org.wings.*;
06: import org.wings.session.SessionManager;
07:
08: /**
09: * @author hengels
10: * @version $Revision$
11: */
12: public class ContextHelpTool extends AbstractTool {
13: protected SRawTextComponent component = new SRawTextComponent();
14:
15: public ContextHelpTool() {
16: putValue(KEY, "help");
17: putValue(NAME, "Help");
18: }
19:
20: protected String resolve(String helpCode) {
21: if (helpCode.endsWith(".title"))
22: helpCode = helpCode.substring(0, helpCode.length()
23: - ".title".length())
24: + ".html";
25:
26: String helpDirectory = "/help/"
27: + SessionManager.getSession().getLocale().getLanguage()
28: + "/";
29: String fileName = SessionManager.getSession()
30: .getServletContext().getRealPath(
31: helpDirectory + helpCode);
32: File file = new File(fileName);
33: if (file.exists())
34: return "../" + helpDirectory + helpCode;
35: else
36: return null;
37: }
38:
39: public void setHelpCode(String helpCode) {
40: String url = resolve(helpCode);
41:
42: if (url == null) {
43: component
44: .setText("<div style='margin: 10px; font-size: 12px; font-weight: bold;'>"
45: + Client.getInstance()
46: .getResourceProvider().getMessage(
47: "help_file_does_not_exist",
48: helpCode) + "</div>");
49:
50: setEnabled(false);
51: } else {
52: setHelpUrl(url);
53: setEnabled(true);
54: }
55: }
56:
57: protected void setHelpUrl(String url) {
58: if (Client.getInstance().isIE())
59: component.setText("<iframe" + " id=\""
60: + component.getName() + "\"" + " src=\"" + url
61: + "\"" + " frameborder=\"0\""
62: + " style=\"position: absolute;"
63: + " left: 0px; width: 100%;"
64: + " top: 0px; height: 100%;"
65: + " border: none; padding: 0px; margin: 0px;\">"
66: + "</iframe>");
67: else
68: component.setText("<iframe" + " id=\""
69: + component.getName() + "\"" + " src=\"" + url
70: + "\"" + " frameborder=\"0\""
71: + " style=\"position: absolute;"
72: + " left: 0px; right: 0px; top: 0px; bottom: 0px;"
73: + " border: none; padding: 0px; margin: 0px;\">"
74: + "</iframe>");
75: }
76:
77: public SComponent getComponent() {
78: return component;
79: }
80: }
|