blob: df50bfbc4496648937f9791bd4834444197d1a7f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
package org.singinst.uf.view;
import java.applet.Applet;
import java.rmi.UnexpectedException;
import netscape.javascript.JSObject;
import org.singinst.uf.common.LogUtil;
import org.w3c.dom.Element;
import org.w3c.dom.html.HTMLDocument;
import org.w3c.dom.html.HTMLIFrameElement;
import com.sun.java.browser.dom.DOMAccessor;
import com.sun.java.browser.dom.DOMAction;
import com.sun.java.browser.dom.DOMService;
public class AppletBrowser {
private DOMService service;
private static AppletBrowser instance;
private final Applet applet;
public AppletBrowser(Applet applet) {
this.applet = applet;
try {
service = DOMService.getService(applet);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Switch shown help page.
*/
public void loadPage(final String helpName) {
if (service != null) {
try {
service.invokeAndWait(new DOMAction()
{
/**
* Firefox on Mac has some issues with accessing HTML elements
* from applets and is currently not working.
*
* See http://forums.sun.com/thread.jspa?threadID=5391691.
*
* This method is an approach that doesn't work, but might be used
* as a starting point.
*/
private void getMacSidebar() {
// element.getOwnerDocument() // Get document from element
// applet.getDocumentBase() // Get URL for applet base
JSObject w = JSObject.getWindow(applet);
Object o = w.eval("getSidebar()");
Object o2 = w.eval("document.getElementById('sidebar')");
LogUtil.info("getSidebar(): " + o);
LogUtil.info("document.getElementById('sidebar'): " + o2 + ", " + o2.getClass());
LogUtil.info("sidebar object has class: " + o.getClass());
if (o instanceof HTMLIFrameElement) {
HTMLIFrameElement e = (HTMLIFrameElement) o;
e.setAttribute("class", "fooBar");
}
Class c = o.getClass();
}
public Object run(DOMAccessor accessor)
{
LogUtil.info("Applet: " + applet);
HTMLDocument doc = (HTMLDocument) accessor.getDocument(applet);
LogUtil.info("HTML document: " + doc);
// if (ViewUtil.runningOnApple()) {
// LogUtil.info("Running on OS X");
// } else {
// LogUtil.info("Running on ~OS X");
// }
if (doc == null) {
LogUtil.error(new UnexpectedException("HTML document could not be accessed!"));
return null;
}
Element element = doc.getElementById("sidebar");
LogUtil.info("Element with id sidebar: " + element);
if (element.getAttribute("name").startsWith("ufHelp")) {
String pageName = "ufHelp/" + helpName + ".html";
element.setAttribute("src", pageName);
}
return null;
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
}
public static void init(Applet applet) {
instance = new AppletBrowser(applet);
}
public static AppletBrowser getInstance() {
return instance;
}
}
|