diff options
author | Duncan Foster <dfoster@openoffice.org> | 2003-10-09 13:37:47 +0000 |
---|---|---|
committer | Duncan Foster <dfoster@openoffice.org> | 2003-10-09 13:37:47 +0000 |
commit | 143e8128b2a51fa2a3e98e114dec021725f69802 (patch) | |
tree | 7d8c4078c6db6db9d1c321cfed48b79cafee393a /scripting | |
parent | 2ff057e9c9a32dbc8c90c7126f27add6669ae989 (diff) |
#i12906# - pass XComponentContext to BrowseNode hierarchy to allow proper
computing of script locations
Diffstat (limited to 'scripting')
4 files changed, 105 insertions, 17 deletions
diff --git a/scripting/java/com/sun/star/script/framework/browse/ParcelBrowseNode.java b/scripting/java/com/sun/star/script/framework/browse/ParcelBrowseNode.java index 2e5b0478ad12..2c28e3d326b2 100644 --- a/scripting/java/com/sun/star/script/framework/browse/ParcelBrowseNode.java +++ b/scripting/java/com/sun/star/script/framework/browse/ParcelBrowseNode.java @@ -2,9 +2,9 @@ * * $RCSfile: ParcelBrowseNode.java,v $ * - * $Revision: 1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: toconnor $ $Date: 2003-09-10 10:44:23 $ + * last change: $Author: dfoster $ $Date: 2003-10-09 14:37:43 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -66,7 +66,8 @@ import drafts.com.sun.star.script.framework.browse.BrowseNodeTypes; import com.sun.star.beans.PropertyAttribute; import com.sun.star.lib.uno.helper.PropertySet; import com.sun.star.uno.Type; - +import com.sun.star.uno.XComponentContext; +import com.sun.star.script.framework.provider.PathUtils; import java.io.*; import java.util.*; @@ -76,28 +77,29 @@ public class ParcelBrowseNode extends PropertySet implements XBrowseNode { private String name; private String location; private Collection browsenodes; - + private XComponentContext m_XCtx; public boolean deletable = false; public boolean editable = false; public ParcelBrowseNode(String name) { this.name = name; - registerProperty("Deletable", new Type(boolean.class), (short)0, "deletable"); registerProperty("Editable", new Type(boolean.class), (short)0, "editable"); } - public ParcelBrowseNode(File dir) { + public ParcelBrowseNode(XComponentContext ctx, File dir) { this(dir.getName()); - this.location = dir.getAbsolutePath(); + this.m_XCtx = ctx; + this.location = PathUtils.toScriptLocation( m_XCtx, dir.getAbsolutePath() ); this.pd = ParcelDescriptor.getParcelDescriptor(dir); this.deletable = true; } - public ParcelBrowseNode(InputStream is, String name) { + public ParcelBrowseNode(XComponentContext ctx,InputStream is, String name) { this(name); + this.m_XCtx = ctx; this.location = "document"; try { diff --git a/scripting/java/com/sun/star/script/framework/browse/ScriptBrowseNode.java b/scripting/java/com/sun/star/script/framework/browse/ScriptBrowseNode.java index bf273154b9c9..326548e2e375 100644 --- a/scripting/java/com/sun/star/script/framework/browse/ScriptBrowseNode.java +++ b/scripting/java/com/sun/star/script/framework/browse/ScriptBrowseNode.java @@ -2,9 +2,9 @@ * * $RCSfile: ScriptBrowseNode.java,v $ * - * $Revision: 1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: toconnor $ $Date: 2003-09-10 10:44:23 $ + * last change: $Author: dfoster $ $Date: 2003-10-09 14:37:43 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -80,7 +80,7 @@ public class ScriptBrowseNode extends PropertySet implements XBrowseNode { public ScriptBrowseNode(ScriptEntry entry, String location) { uri = "script://" + entry.getLogicalName() + "?function=" + entry.getLanguageName() + - "?language=" + entry.getLanguage() + + "&language=" + entry.getLanguage() + "&location=" + location; System.out.println("Creating ScriptBrowseNode: " + uri); diff --git a/scripting/java/com/sun/star/script/framework/provider/PathUtils.java b/scripting/java/com/sun/star/script/framework/provider/PathUtils.java index 9c8a264e6089..f923a017547b 100644 --- a/scripting/java/com/sun/star/script/framework/provider/PathUtils.java +++ b/scripting/java/com/sun/star/script/framework/provider/PathUtils.java @@ -2,9 +2,9 @@ * * $RCSfile: PathUtils.java,v $ * - * $Revision: 1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: toconnor $ $Date: 2003-09-10 10:44:27 $ + * last change: $Author: dfoster $ $Date: 2003-10-09 14:37:47 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -77,9 +77,13 @@ import com.sun.star.uno.XComponentContext; import com.sun.star.script.framework.log.LogUtils; +import com.sun.star.util.XMacroExpander; +import com.sun.star.uno.Type; +import com.sun.star.uno.AnyConverter; public class PathUtils { public static String FILE_URL_PREFIX; + public static String BOOTSTRAP_NAME; private static boolean m_windows = false; static { @@ -88,6 +92,7 @@ public class PathUtils { m_windows = true; FILE_URL_PREFIX = m_windows ? "file:///" : "file://"; + BOOTSTRAP_NAME = m_windows ? "bootstrap.ini" : "bootstraprc"; } private PathUtils() { @@ -253,4 +258,85 @@ public class PathUtils { } return returnPath; } + public static String toScriptLocation(XComponentContext ctxt, String path) { + String sharePath = getSharePath(ctxt); + String userPath = getUserPath(ctxt); + + LogUtils.DEBUG("toScriptLocation, path: " + path); + LogUtils.DEBUG("toScriptLocation, share path: " + sharePath); + LogUtils.DEBUG("toScriptLocation, user path: " + userPath); + + try { + path = URLDecoder.decode(path, "UTF-8"); + } + catch (java.io.UnsupportedEncodingException ignore) { + // ignore + } + + if (m_windows) { + path = replaceWindowsPathSeparators(path); + } + + if (path.indexOf(sharePath) != -1) { + return "share"; + } + else if (path.indexOf(userPath) != -1) { + return "user"; + } + return path; + } + + private static String getOfficeURL(XComponentContext ctxt, String name) { + + String result = null; + + try { + Object serviceObj = ctxt.getValueByName( + "/singletons/com.sun.star.util.theMacroExpander"); + + LogUtils.DEBUG("got serviceObj"); + XMacroExpander me = (XMacroExpander) AnyConverter.toObject( + new Type(XMacroExpander.class), serviceObj); + + result = me.expandMacros(name); + } + catch (com.sun.star.lang.IllegalArgumentException iae) { + LogUtils.DEBUG("Caught IllegalArgumentException trying to " + + "expand dir: " + name); + } + + return result; + } + + public static String getShareURL(XComponentContext ctxt) { + return getOfficeURL(ctxt, + "${$SYSBINDIR/" + BOOTSTRAP_NAME + + "::BaseInstallation}/share"); + } + + public static String getSharePath(XComponentContext ctxt) { + String s = getShareURL(ctxt); + + if (s.startsWith(FILE_URL_PREFIX)) { + s = s.substring(FILE_URL_PREFIX.length()); + } + + return s; + } + + public static String getUserURL(XComponentContext ctxt) { + return getOfficeURL(ctxt, + "${$SYSBINDIR/" + BOOTSTRAP_NAME + + "::UserInstallation}/user"); + } + + public static String getUserPath(XComponentContext ctxt) { + String s = getUserURL(ctxt); + + if (s.startsWith(FILE_URL_PREFIX)) { + s = s.substring(FILE_URL_PREFIX.length()); + } + + return s; + } } diff --git a/scripting/java/com/sun/star/script/framework/provider/ScriptProvider.java b/scripting/java/com/sun/star/script/framework/provider/ScriptProvider.java index 9b7baab4d363..61812b56ca71 100755 --- a/scripting/java/com/sun/star/script/framework/provider/ScriptProvider.java +++ b/scripting/java/com/sun/star/script/framework/provider/ScriptProvider.java @@ -2,9 +2,9 @@ * * $RCSfile: ScriptProvider.java,v $ * -* $Revision: 1.1 $ +* $Revision: 1.2 $ * -* last change: $Author: toconnor $ $Date: 2003-09-10 10:44:28 $ +* last change: $Author: dfoster $ $Date: 2003-10-09 14:37:47 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -172,13 +172,13 @@ public abstract class ScriptProvider "SCRIPTING_DOC_REF")); LogUtils.DEBUG("creating DocBrowseNode, model: " + model.getURL()); - m_browseNodeProxy = new DocBrowseNode(model, language); + m_browseNodeProxy = new DocBrowseNode(m_xContext,model, language); } else if (AnyConverter.isString(aArguments[0]) == true) { String path = AnyConverter.toString(aArguments[0]); LogUtils.DEBUG("creating DirBrowseNode, path: " + path); - m_browseNodeProxy = new DirBrowseNode(path, language); + m_browseNodeProxy = new DirBrowseNode(m_xContext, path, language); } else { |