Line 12... |
Line 12... |
12 |
*/
|
12 |
*/
|
13 |
|
13 |
|
14 |
package org.jopendocument.link;
|
14 |
package org.jopendocument.link;
|
15 |
|
15 |
|
16 |
import org.openconcerto.utils.CollectionUtils;
|
16 |
import org.openconcerto.utils.CollectionUtils;
|
- |
|
17 |
import org.openconcerto.utils.tools.SimpleURLClassLoader;
|
- |
|
18 |
import org.openconcerto.utils.tools.SimpleURLClassLoader.URLCollector;
|
17 |
|
19 |
|
18 |
import java.io.File;
|
20 |
import java.io.File;
|
19 |
import java.io.FileNotFoundException;
|
21 |
import java.io.FileNotFoundException;
|
20 |
import java.io.FilePermission;
|
22 |
import java.io.FilePermission;
|
21 |
import java.io.IOException;
|
23 |
import java.io.IOException;
|
Line 51... |
Line 53... |
51 |
org.openconcerto.utils.protocol.Helper.register();
|
53 |
org.openconcerto.utils.protocol.Helper.register();
|
52 |
}
|
54 |
}
|
53 |
|
55 |
|
54 |
static private final URL[] getURLs(final OOInstallation ooInstall) {
|
56 |
static private final URL[] getURLs(final OOInstallation ooInstall) {
|
55 |
final List<URL> res = ooInstall.getURLs(CollectionUtils.createSet("ridl.jar", "jurt.jar", "juh.jar", "unoil.jar"));
|
57 |
final List<URL> res = ooInstall.getURLs(CollectionUtils.createSet("ridl.jar", "jurt.jar", "juh.jar", "unoil.jar"));
|
- |
|
58 |
return res.toArray(new URL[res.size()]);
|
- |
|
59 |
}
|
56 |
|
60 |
|
- |
|
61 |
static private final URL getFwkURL(final OOInstallation ooInstall) {
|
57 |
final String jarName = "OO" + OO_VERSION + "-link.jar";
|
62 |
final String jarName = "OO" + OO_VERSION + "-link.jar";
|
58 |
final URL resource = OOConnexion.class.getResource(jarName);
|
63 |
final URL resource = OOConnexion.class.getResource(jarName);
|
59 |
if (resource == null)
|
64 |
if (resource == null)
|
60 |
// Did you run ant in the OO3Link project (or in ours) ?
|
65 |
// Did you run ant in the OO3Link project (or in ours) ?
|
61 |
throw new IllegalStateException("Missing " + jarName);
|
66 |
throw new IllegalStateException("Missing " + jarName);
|
62 |
res.add(org.openconcerto.utils.protocol.Helper.toJarJar(resource));
|
- |
|
63 |
|
67 |
|
64 |
return res.toArray(new URL[res.size()]);
|
68 |
return resource;
|
65 |
}
|
69 |
}
|
66 |
|
70 |
|
67 |
static private final ClassLoader getLoader(final OOInstallation ooInstall) {
|
71 |
static private final PermissionCollection addPermissions(final PermissionCollection perms, final OOInstallation ooInstall) {
|
68 |
ClassLoader res = loaders.get(ooInstall);
|
- |
|
69 |
if (res == null) {
|
- |
|
70 |
// pass our classloader otherwise the system class loader will be used. This won't work
|
- |
|
71 |
// in webstart since the classpath is loaded by JNLPClassLoader, thus a class loaded by
|
- |
|
72 |
// res couldn't refer to the classpath (e.g. this class) but only to the java library.
|
- |
|
73 |
res = new URLClassLoader(getURLs(ooInstall), OOConnexion.class.getClassLoader()) {
|
- |
|
74 |
@Override
|
- |
|
75 |
protected PermissionCollection getPermissions(CodeSource codesource) {
|
- |
|
76 |
final PermissionCollection perms = super.getPermissions(codesource);
|
- |
|
77 |
perms.add(new FilePermission(ooInstall.getExecutable().getAbsolutePath(), "execute"));
|
72 |
perms.add(new FilePermission(ooInstall.getExecutable().getAbsolutePath(), "execute"));
|
78 |
perms.add(new SocketPermission("localhost:" + PORT + "-" + PORT_MAX, "connect"));
|
73 |
perms.add(new SocketPermission("localhost:" + PORT + "-" + PORT_MAX, "connect"));
|
79 |
// needed by OO jars
|
74 |
// needed by OO jars
|
80 |
perms.add(new PropertyPermission("*", "read"));
|
75 |
perms.add(new PropertyPermission("*", "read"));
|
81 |
// to be able to open any document
|
76 |
// to be able to open any document
|
Line 95... |
Line 90... |
95 |
perms.add(new FilePermission("/bin/ps", "execute"));
|
90 |
perms.add(new FilePermission("/bin/ps", "execute"));
|
96 |
perms.add(new FilePermission("C:/Windows/System32/tasklist.exe", "execute"));
|
91 |
perms.add(new FilePermission("C:/Windows/System32/tasklist.exe", "execute"));
|
97 |
perms.add(new RuntimePermission("getenv.*"));
|
92 |
perms.add(new RuntimePermission("getenv.*"));
|
98 |
// needed by OOConnexion.convertToUrl()
|
93 |
// needed by OOConnexion.convertToUrl()
|
99 |
perms.add(new FilePermission("/usr/bin/gvfs-info", "execute"));
|
94 |
perms.add(new FilePermission("/usr/bin/gvfs-info", "execute"));
|
- |
|
95 |
|
100 |
return perms;
|
96 |
return perms;
|
101 |
}
|
97 |
}
|
- |
|
98 |
|
- |
|
99 |
static synchronized private final ClassLoader getLoader(final OOInstallation ooInstall) {
|
- |
|
100 |
ClassLoader res = loaders.get(ooInstall);
|
- |
|
101 |
if (res == null) {
|
- |
|
102 |
// pass our classloader otherwise the system class loader will be used. This won't work
|
- |
|
103 |
// in webstart since the classpath is loaded by JNLPClassLoader, thus a class loaded by
|
- |
|
104 |
// res couldn't refer to the classpath (e.g. this class) but only to the java library.
|
- |
|
105 |
final URLClassLoader officeLoader = new URLClassLoader(getURLs(ooInstall), OOConnexion.class.getClassLoader()) {
|
- |
|
106 |
@Override
|
- |
|
107 |
protected PermissionCollection getPermissions(CodeSource codesource) {
|
- |
|
108 |
return addPermissions(super.getPermissions(codesource), ooInstall);
|
- |
|
109 |
}
|
- |
|
110 |
};
|
- |
|
111 |
// only use SimpleURLClassLoader when really needed since it is less optimized
|
- |
|
112 |
res = new SimpleURLClassLoader(new URLCollector().addJar(getFwkURL(ooInstall)), officeLoader) {
|
- |
|
113 |
@Override
|
- |
|
114 |
protected PermissionCollection getPermissions(CodeSource codesource) {
|
- |
|
115 |
return addPermissions(super.getPermissions(codesource), ooInstall);
|
- |
|
116 |
}
|
102 |
};
|
117 |
};
|
103 |
loaders.put(ooInstall, res);
|
118 |
loaders.put(ooInstall, res);
|
104 |
}
|
119 |
}
|
105 |
return res;
|
120 |
return res;
|
106 |
}
|
121 |
}
|