rony wrote:
Hi there,
still wanting to make sure that this is an error/issue with OOo, hence
trying to get at an example that uses only genuine OOo Basic and plain
Java.
The following two little programs demonstrate, that invoking an OOo
Basic function via the "XDispatchHelper.executeDispatch(...)" method
unexplainably adds a Boolean value (true) to the list of arguments meant
for the script function.
-------------- cut here --------------
import com.sun.star.beans.PropertyValue;
import com.sun.star.frame.XComponentLoader;
import com.sun.star.frame.XDesktop;
import com.sun.star.frame.XDispatchHelper;
import com.sun.star.frame.XDispatchProvider;
import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;
import com.sun.star.frame.DispatchResultEvent;
class TestBasic {
public static void main (String args[]) {
// excerpted from "HardFormatting.java" from the OOo development package
XDesktop xDesktop = null;
XMultiComponentFactory xMCF = null;
XMultiServiceFactory xMSF = null;
try {
XComponentContext xContext = null;
// bootstrap the UNO runtime environment
xContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
// get the service manager
xMCF = xContext.getServiceManager();
xMSF = (XMultiServiceFactory)
UnoRuntime.queryInterface(XMultiServiceFactory.class, xMCF);
if (xMSF!=null)
{
System.out.println("Connected to a running office ...");
// get XDispatchProvider from XDesktop
Object oDesktop =
xMSF.createInstance("com.sun.star.frame.Desktop");
xDesktop = (XDesktop) UnoRuntime.queryInterface(XDesktop.class,
oDesktop);
XDispatchProvider xDispatchProvider=(XDispatchProvider)
UnoRuntime.queryInterface(XDispatchProvider.class,
xDesktop);
Object sDispatchHelper=
xMSF.createInstance("com.sun.star.frame.DispatchHelper");
XDispatchHelper xDispatchHelper=(XDispatchHelper)
UnoRuntime.queryInterface(XDispatchHelper.class,
sDispatchHelper);
// define arguments
PropertyValue propValue=new PropertyValue();
propValue.Name="arg1"; // not used, but what the
heck
propValue.Value=sDispatchHelper; // an UNO object (could be
an UNO IDL string instead
*PropertyValue parameters[]={propValue}; // ONE argument only
for the Basic function!*
// invoke the ooRexx script to document the UNO object/IDL
// Bug in OOo? Location should be "user", however one must use
"application" instead
String location="application"; // "user" or "share" or
"application"
String
macroUrl="vnd.sun.star.script:Standard.Module1.RgfFuncTest?language=Basic&location="
+location;
// dispatch, supplying arguments
DispatchResultEvent dre=(DispatchResultEvent)
xDispatchHelper.executeDispatch(
xDispatchProvider, // XDispatchProvider
macroUrl, // URL
"", // TargetFrameName
0, // SearchFlags
parameters); // Arguments
System.out.println("Returned from executing dispatch, Result=["+dre.Result+"],
State=["+dre.State+"]");
}
}
catch( Exception e) {
e.printStackTrace(System.err);
System.exit(1);
}
System.err.println("Successful run.");
System.exit(0);
}
}
-------------- cut here --------------
Just add the following Basic code to the user area ("My Macros") to the
library "Standard" and there in the module named "Module1":
-------------- cut here --------------
function RgfFuncTest (arg1 as variant, optional arg2, optional arg3)
dim str as string
vblf=chr$(10)
str="(some Basic datatypes: 0=Empty, 2=Integer, 8=String, 9=Object,
11=Boolean)" & vblf
str=str & vblf & "isMissing(arg1)=" & isMissing(arg1)
if not isMissing(arg1) then
str=str & ", value="
if isObject(arg1) then
str=str & "some" & typeName(arg1)
else
str=str & arg1
end if
str=str & ", datatype=" & varType(arg1)
end if
str=str & vblf & "isMissing(arg2)=" & isMissing(arg2)
if not isMissing(arg2) then
str=str & ", value=" & arg2 & ", datatype=" & varType(arg2)
end if
str=str & vblf & "isMissing(arg3)=" & isMissing(arg3)
if not isMissing(arg3) then
str=str & ", value=" & arg3 & ", datatype=" & varType(arg3)
end if
MsgBox str, 0, "RgfFuncTest()"
RgfFuncTest=str
end function
-------------- cut here --------------
[BTW, please note that there seems to be an error in this area, as from
outside of Basic one must denote "application" rather than the correct
"user" as the location.]
mmh, i am not sure. Well i have never used this but maybe "application"
provides a view from outside of basic on both "user" and "share" and
you don't have to differentiate. But of course using "user" directly
should work probably also.
Compiling and running the Java program above will cause a message box to
popup (needs to be closed by the user, or just comment the
MsgBox-instruction), and at the end of the run will display the result's
value (the result of the Basic function):
-------------- cut here --------------
F:\test\ooo\studenten\diplarbeit\scholz\20090108>java TestBasic
Connected to a running office ...
Returned from executing dispatch, Result=[(some Basic datatypes: 0=Empty,
2=Integer, 8=String, 9=Object, 11=Boolean)
isMissing(arg1)=False, value=someObject, datatype=9
isMissing(arg2)=False, value=True, datatype=11
isMissing(arg3)=True], State=[1]
Successful run.
-------------- cut here --------------
As you can see, the Basic function gets TWO arguments, instead of only
one. The last argument is of type Boolean and has a value of "True".
Any comments/hints/explanations now that only "genuine" OOo
functionality is used? Does this qualify as a bug?
sorry no hints without further investigation ...
Juergen
Regards,
---rony
Rony G. Flatscher (Apache) wrote:
Hi there,
not sure whether "[email protected]" would be the "better" list for
this question, hence cc:'ing it, but reply-to is set to point to
"[email protected]". Please advise, if another e-mail-list would be
better.
rony wrote:
Hi there,
it seems that if using XDispatchHelper.executeDisptatch(...) from Java
the argument list (fifth argument being an array of type PropertyValue)
gets a Boolean entry appended (that is always set to true). Is that
truly the case? (If so, where would that be documented?)
Using OOo 3.0.0 (O300m9, build:9358) and the Java interface to OOo to
invoke "executeDispatch()". Online documentation
<http://api.openoffice.org/docs/common/ref/com/sun/star/frame/XDispatchHelper.html#executeDispatch>,
looking up Parameter "Arguments".
TIA,
---rony
Maybe this was not enough information, so:
* Using XDispatchHelpter.executeDispatch(...), allows one to supply
five arguments, the last argument being an array of PropertyValues,
* Using the OOo scripting framework, the method "invoke(Object[]
aParams, short[][] aOutParamIndex, Object[][] aOutParams)" of the
"com.sun.star.script.framework.provider.XXX.ScriptProviderForXXX"
class is invoked (where "XXX" stands for the scripting language
this class will serve).
o "aParams" will have always one argument more than supplied
by "XDispatchHelpter.executeDispatch(...)", and that
argument is of type Boolean (in my case always set to "true".
Here's an example Java code that employs
"XDispatchHelper.executeDispatch(...)":
----------------- cut here ----------------
// ---rgf, 2009-02-11, Java program to invoke "createApiInfo.rex" from Java
import com.sun.star.beans.PropertyValue;
import com.sun.star.frame.XComponentLoader;
import com.sun.star.frame.XDesktop;
import com.sun.star.frame.XDispatchHelper;
import com.sun.star.frame.XDispatchProvider;
import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;
import com.sun.star.frame.DispatchResultEvent;
class TestCreateApiInfo {
public static void main (String args[]) {
// excerpted from "HardFormatting.java" from the OOo development package
XDesktop xDesktop = null;
XMultiComponentFactory xMCF = null;
XMultiServiceFactory xMSF = null;
try {
XComponentContext xContext = null;
// bootstrap the UNO runtime environment
xContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
// get the service manager
xMCF = xContext.getServiceManager();
xMSF = (XMultiServiceFactory)
UnoRuntime.queryInterface(XMultiServiceFactory.class, xMCF);
if (xMSF!=null)
{
System.out.println("Connected to a running office ...");
// get XDispatchProvider from XDesktop
Object oDesktop =
xMSF.createInstance("com.sun.star.frame.Desktop");
xDesktop = (XDesktop) UnoRuntime.queryInterface(XDesktop.class,
oDesktop);
XDispatchProvider xDispatchProvider=(XDispatchProvider)
UnoRuntime.queryInterface(XDispatchProvider.class,
xDesktop);
Object sDispatchHelper=
xMSF.createInstance("com.sun.star.frame.DispatchHelper");
XDispatchHelper xDispatchHelper=(XDispatchHelper)
UnoRuntime.queryInterface(XDispatchHelper.class,
sDispatchHelper);
// define arguments
PropertyValue propValue=new PropertyValue();
propValue.Name="arg1"; // not used, but what the
heck
propValue.Value=sDispatchHelper; // an UNO object (could be
an UNO IDL string instead)
PropertyValue parameters[]={propValue};
// invoke the ooRexx script to document the UNO object/IDL
String location="user"; // "user" or "share" or "application"
String
macroUrl="vnd.sun.star.script:wu_tools.createApiInfo.rex?language=ooRexx&location="
+location;
// dispatch, supplying arguments
DispatchResultEvent dre=(DispatchResultEvent)
xDispatchHelper.executeDispatch(
xDispatchProvider, // XDispatchProvider
macroUrl, // URL
"", // TargetFrameName
0, // SearchFlags
parameters); // Arguments
System.out.println("Returned from executing dispatch, Result=["+dre.Result+"],
State=["+dre.State+"]");
}
}
catch( Exception e) {
e.printStackTrace(System.err);
System.exit(1);
}
System.err.println("Successful run.");
System.exit(0);
}
}
----------------- cut here ----------------
In this case an ooRexx macro/script is invoked. ooRexx can handle
variable numbers of arguments and in this case there may be up to eight
arguments supplied, but one can omit all but the very first argument.
Now, if OOo supplies one argument too many, this interferes quite
heavily as from the perspective of the receiving (ooRexx) side one
cannot determine whether OOo injected an argument of its own or not.
Looking through the sources of the OOo scripting framework there seems
to be no statement there that appends that argument, so I assume it
happens either in executeDispatch(...) or somewhere on the way to the
scripting framework invocation.
I would really appreciate if anyone could shed some light on this!
---rony
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]