diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2012-03-23 16:05:24 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2012-03-23 16:20:17 +0100 |
commit | dd6c4f4db1d62268d73e09ae52d23f760a967dcc (patch) | |
tree | e0ce307aed079955367686188bd7c4ab4a5787d5 /scripting/java | |
parent | a09d551182d61d67313a7d97a25ab251c88f92e9 (diff) |
fdo#46102: Load Java scripts with class loaders that actually find them
ScriptMetaData.createURL produces weird URLs (ending in "/ucb/", and potentially
still containing vnd.sun.star.expand: prefix) that are apparently good for
loading documents for editing via UCBStreamHandler, but cannot meaningfully be
passed to a URLClassLoader.
It is unclear to me how the Java script provider shall ever have found the
script jars in the past.
Diffstat (limited to 'scripting/java')
6 files changed, 54 insertions, 9 deletions
diff --git a/scripting/java/com/sun/star/script/framework/container/ScriptMetaData.java b/scripting/java/com/sun/star/script/framework/container/ScriptMetaData.java index 1cf99d78292e..178f4806f344 100644 --- a/scripting/java/com/sun/star/script/framework/container/ScriptMetaData.java +++ b/scripting/java/com/sun/star/script/framework/container/ScriptMetaData.java @@ -50,7 +50,14 @@ import com.sun.star.script.framework.io.UCBStreamHandler; import com.sun.star.ucb.XSimpleFileAccess2; +import com.sun.star.uno.AnyConverter; import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XComponentContext; + +import com.sun.star.uri.UriReferenceFactory; +import com.sun.star.uri.XVndSunStarExpandUrl; + +import com.sun.star.util.XMacroExpander; public class ScriptMetaData extends ScriptEntry implements Cloneable { private boolean hasSource = false; @@ -246,7 +253,8 @@ public class ScriptMetaData extends ScriptEntry implements Cloneable { return "\nParcelLocation = " + getParcelLocation() + "\nLocationPlaceHolder = " + locationPlaceHolder + super.toString(); } - public URL[] getClassPath() throws java.net.MalformedURLException + public URL[] getClassPath(XComponentContext context) + throws java.net.MalformedURLException { try { @@ -274,7 +282,7 @@ public class ScriptMetaData extends ScriptEntry implements Cloneable { { String relativeClasspath = (String)stk.nextElement(); String pathToProcess = PathUtils.make_url( parcelPath, relativeClasspath); - URL url = createURL( pathToProcess ); + URL url = expandURL( context, pathToProcess ); if ( url != null ) { classPathVec.add ( url ); @@ -283,7 +291,7 @@ public class ScriptMetaData extends ScriptEntry implements Cloneable { } if ( classPathVec.size() == 0) { - URL url = createURL( parcelPath ); + URL url = expandURL( context, parcelPath ); if ( url != null ) { classPathVec.add(url); @@ -300,6 +308,38 @@ public class ScriptMetaData extends ScriptEntry implements Cloneable { } } + + private URL expandURL(XComponentContext context, String url) + throws java.net.MalformedURLException + { + XVndSunStarExpandUrl exp = UnoRuntime.queryInterface( + XVndSunStarExpandUrl.class, + UriReferenceFactory.create(context).parse(url)); + String expurl; + if (exp == null) { + expurl = url; + } else { + XMacroExpander expander; + try { + expander = (XMacroExpander) AnyConverter.toObject( + XMacroExpander.class, + context.getValueByName( + "/singletons/com.sun.star.util.theMacroExpander")); + } catch (com.sun.star.lang.IllegalArgumentException e) { + throw new RuntimeException(e); + } + try { + expurl = exp.expand(expander); + } catch (com.sun.star.lang.IllegalArgumentException e) { + java.net.MalformedURLException e2 = + new java.net.MalformedURLException(e.toString()); + e2.initCause(e); + throw e2; + } + } + return new URL(expurl); + } + private URL createURL( String path ) throws java.net.MalformedURLException { URL url = null; diff --git a/scripting/java/com/sun/star/script/framework/provider/ClassLoaderFactory.java b/scripting/java/com/sun/star/script/framework/provider/ClassLoaderFactory.java index 641ca589d9a5..081204f3c7b0 100644 --- a/scripting/java/com/sun/star/script/framework/provider/ClassLoaderFactory.java +++ b/scripting/java/com/sun/star/script/framework/provider/ClassLoaderFactory.java @@ -31,6 +31,7 @@ import java.net.*; import com.sun.star.script.framework.log.LogUtils; import com.sun.star.script.framework.container.ScriptMetaData; +import com.sun.star.uno.XComponentContext; /** * Class Loader Factory @@ -42,11 +43,12 @@ public class ClassLoaderFactory { private ClassLoaderFactory() {} - public static ClassLoader getURLClassLoader( ScriptMetaData scriptData ) + public static ClassLoader getURLClassLoader( + XComponentContext context, ScriptMetaData scriptData ) throws NoSuitableClassLoaderException, MalformedURLException { ClassLoader parent = scriptData.getClass().getClassLoader(); - URL[] classPath = scriptData.getClassPath(); + URL[] classPath = scriptData.getClassPath(context); LogUtils.DEBUG("Classpath has length " + classPath.length ); for ( int i=0; i < classPath.length; i++ ) { diff --git a/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptEditorForBeanShell.java b/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptEditorForBeanShell.java index cbbcfc34f78f..9f6739d9ea01 100644 --- a/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptEditorForBeanShell.java +++ b/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptEditorForBeanShell.java @@ -202,7 +202,8 @@ public class ScriptEditorForBeanShell try { ClassLoader cl = null; try { - cl = ClassLoaderFactory.getURLClassLoader( entry ); + cl = ClassLoaderFactory.getURLClassLoader( + context.getComponentContext(), entry ); } catch (Exception ignore) // TODO re-examine error handling { diff --git a/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptProviderForBeanShell.java b/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptProviderForBeanShell.java index 95c727881427..22a9ea8e2b93 100644 --- a/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptProviderForBeanShell.java +++ b/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptProviderForBeanShell.java @@ -196,7 +196,8 @@ class ScriptImpl implements XScript ClassLoader cl = null; URL sourceUrl = null; try { - cl = ClassLoaderFactory.getURLClassLoader( metaData ); + cl = ClassLoaderFactory.getURLClassLoader( + m_xContext, metaData ); sourceUrl = metaData.getSourceURL(); } catch ( java.net.MalformedURLException mfu ) diff --git a/scripting/java/com/sun/star/script/framework/provider/java/ScriptProviderForJava.java b/scripting/java/com/sun/star/script/framework/provider/java/ScriptProviderForJava.java index 707ea05624d9..3f392f792982 100644 --- a/scripting/java/com/sun/star/script/framework/provider/java/ScriptProviderForJava.java +++ b/scripting/java/com/sun/star/script/framework/provider/java/ScriptProviderForJava.java @@ -205,7 +205,7 @@ class ScriptImpl implements XScript try { LogUtils.DEBUG( "Classloader starting..." ); scriptLoader = ClassLoaderFactory.getURLClassLoader( - metaData ); + m_xContext, metaData ); LogUtils.DEBUG( "Classloader finished..." ); } catch (MalformedURLException mfe ) diff --git a/scripting/java/com/sun/star/script/framework/provider/javascript/ScriptProviderForJavaScript.java b/scripting/java/com/sun/star/script/framework/provider/javascript/ScriptProviderForJavaScript.java index 9f04d9105374..39205d480808 100644 --- a/scripting/java/com/sun/star/script/framework/provider/javascript/ScriptProviderForJavaScript.java +++ b/scripting/java/com/sun/star/script/framework/provider/javascript/ScriptProviderForJavaScript.java @@ -195,7 +195,8 @@ class ScriptImpl implements XScript ClassLoader cl = null; URL sourceUrl = null; try { - cl = ClassLoaderFactory.getURLClassLoader( metaData ); + cl = ClassLoaderFactory.getURLClassLoader( + m_xContext, metaData ); sourceUrl = metaData.getSourceURL(); } catch ( java.net.MalformedURLException mfu ) |