#i12906# - pass XComponentContext to BrowseNode hierarchy to allow proper
computing of script locations
This commit is contained in:
@@ -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 {
|
||||
|
@@ -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);
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
|
@@ -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
|
||||
{
|
||||
|
Reference in New Issue
Block a user