Using Interactive "frontend_UNO_API_info", An Easy to Use GUI

A BSF4Rexx-application taking advantage of Java swing to create an easy to use interface for "frontend_UNO_API_info.rex". Either enter a fully qualified UNO IDL string or experiment by choosing an UNO IDL string from the drop-down list.





Using "UNO_API_info.rex" from OOo BASIC via UNO Dispatch

The ooRexx script can be invoked via the UNO dispatch interface supplying an UNO object or and UNO IDL string as an argument. In addition rendering options can be given as a second argument in form of an array of PropertyValues, where the name field denotes the option's name and the value the desired value.

"TestCreateApiInfo.bas":

Sub testCreateApiInfo
   DIM sDispatchHelper AS object, xDispatchProvider AS object  ' objects
   DIM macroUrl, library, scriptName, langName, location       ' variants
   DIM args1(0) AS NEW com.sun.star.beans.PropertyValue            ' array of type PropertyValue
   DIM args2(1), options(6)                                    ' arrays of variants
   sDispatchHelper  =createUnoService("com.sun.star.frame.DispatchHelper") ' create DispatchHelper service
   xDispatchProvider=ThisComponent.CurrentController.Frame  ' get dispatch provider interface of current Desktop
   ' define Rexx dispatch target, library "wu_tools", script name "create_UNO_API_info.rex", location "user"
   location   ="user"               ' case sensitive, other possible values: "share" (all users), "application"
   libraryName="wu_tools"           ' case sensitive, name of the Rexx macro library
   scriptName ="UNO_API_info.rex"   ' case sensitive, name of the Rexx script
   langName   ="ooRexx"             ' case sensitive, OOo name of the scripting language
        ' build 'macroUrl' string for the dispatcher
   macroUrl="vnd.sun.star.script:" & libraryName & "." & scriptName & "?language=" & langName & "&location=" & location
   '  ------ use one argument denoting an UNO object from the running program
   ' define one argument (an UNO object from the running program)
   ' remark: the array 'args1' is explicitly defined to be of type com.sun.star.beans.PropertyValue,
   '         hence its element is a PropertyValue object already
   args1(0).name ="arg1"            ' name of the PropertyValue
   args1(0).value=sDispatchHelper   ' value: UNO object to analyze
   ' dispatching to 'create_UNO_API_info.rex' using an UNO object from the running program
   sDispatchHelper.executeDispatch(xDispatchProvider, macroUrl, "", 0, args1())


   '  ------ use one argument denoting an UNO object from the running program
   ' define options; create PropertyValue objects and assign them to the 'options' variant array
   options(0)=createProperty("NrOfLayers",           2)  ' 2="show two levels deep"
   options(1)=createProperty("View",                 1)  ' 1="view in writer"
   options(2)=createProperty("DocumentationSource",  1)  ' 1="use Internet" (base url)
   options(3)=createProperty("NumberingTypeLevel_1", 0)  ' 0="Alpha Uppercase"
   options(4)=createProperty("NumberingTypeLevel_2", 4)  ' 4="arabic"
   options(5)=createProperty("NumberingTypeLevel_3", 3)  ' 3="roman lower"
   options(6)=createProperty("FontName",             "DejaVu Sans Condensed")
   ' define two arguments (an UNO IDL string and formatting options
   ' create PropertyValue objects and assign them to the 'args2' variant array
   args2(0)=createProperty("arg1", "com.sun.star.frame.Desktop") ' an UNO IDL string
   args2(1)=createProperty("arg2", options)                      ' rendering options
   ' dispatching to 'create_UNO_API_info.rex' using an UNO IDL string and rendering options
   sDispatchHelper.executeDispatch(xDispatchProvider, macroUrl, "", 0, args2())

End Sub


' utility function to ease creation of PropertyValue objects
Function createProperty (n AS string, v)
   prop=CreateObject("com.sun.star.beans.PropertyValue") ' create a PropertyValue object
   prop.name=n          ' assign name (a string)
   prop.value=v         ' assign value (a variant, i.e. can be any value)
   createProperty=prop  ' set this function's return value
end Function


Using "UNO_API_info.rex" from Java via UNO Dispatch

The ooRexx script can be invoked via the UNO dispatch interface supplying an UNO object or and UNO IDL string as an argument. In addition rendering options can be given as a second argument in form of an array of PropertyValues, where the name field denotes the option's name and the value the desired value.

"TestCreateApiInfo.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("Java: connected to the bootstrapped office ...\n---");
                // 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);
                // invoke the ooRexx script to document the UNO object/IDL
                // define Rexx dispatch target, library "wu_tools", script name "create_UNO_API_info.rex", location "user"
                String location   ="user",              // case sensitive, other possible values: "share" (all users), "application"
                       libraryName="wu_tools",          // case sensitive, name of the Rexx macro library
                       scriptName ="UNO_API_info.rex",  // case sensitive, name of the Rexx script
                       langName   ="ooRexx";            // case sensitive, OOo name of the scripting language
                    // build 'macroUrl' string for the dispatcher
                String macroUrl="vnd.sun.star.script:"+libraryName+"."+scriptName+
                                          "?language="+langName+
                                          "&location="+location;
                // define one argument (an UNO object from the running program)
                PropertyValue args1[]={createProperty("arg1", sDispatchHelper) };
                System.out.println("Java: dispatching to 'create_UNO_API_info.rex' using an UNO object from the running program...");
                // dispatch, supplying arguments
                xDispatchHelper.executeDispatch(
                            xDispatchProvider,  // XDispatchProvider
                            macroUrl,           // URL
                            "",                 // TargetFrameName
                            0,                  // SearchFlags
                            args1);        // Arguments


                // ============================== next dispatch uses an UNO IDL string and options
                System.out.println("---");
                   // define options
                PropertyValue options[]= {
                    createProperty("NrOfLayers",           new Integer(2)), // 2="show two levels deep"
                    createProperty("View",                 new Integer(1)), // 1="view in writer"
                    createProperty("DocumentationSource",  new Integer(1)), // 1="use Internet" (base url)
                    createProperty("NumberingTypeLevel_1", new Integer(0)), // 0="Alpha Uppercase"
                    createProperty("NumberingTypeLevel_2", new Integer(4)), // 4="arabic"
                    createProperty("NumberingTypeLevel_3", new Integer(3)), // 3="roman lower"
                    createProperty("FontName",             "DejaVu Sans Condensed")
                };
                // define two arguments
                PropertyValue args2[]=
                {
                    createProperty("arg1", "com.sun.star.frame.Desktop"), // analyze UNO IDL name
                    createProperty("arg2", options)                       // rendering options
                };
                System.out.println("Java: dispatching to 'create_UNO_API_info.rex' using an UNO IDL string and rendering options...");
                // dispatch, supplying arguments
                xDispatchHelper.executeDispatch(
                            xDispatchProvider,  // XDispatchProvider
                            macroUrl,           // URL
                            "",                 // TargetFrameName
                            0,                  // SearchFlags
                            args2);             // Arguments

            }
        }
        catch( Exception e) {
            e.printStackTrace(System.err);
            System.exit(1);
        }
        System.err.println("end of program run.");
        System.exit(0);
    }
    // utility method to ease creation of PropertyValue objects
    static PropertyValue createProperty(String n, Object v)
    {
        PropertyValue prop=new PropertyValue();
        prop.Name =n;
        prop.Value=v;
        return prop;
    }
}


Using "UNO_API_info.rex" from ooRexx via UNO Dispatch

The ooRexx script can be invoked via the UNO dispatch interface supplying an UNO object or and UNO IDL string as an argument. In addition rendering options can be given as a second argument in form of an array of PropertyValues, where the name field denotes the option's name and the value the desired value.

"TestCreateApiInfo_ooRexx.rex":

-- try to get a script context, will be .nil, if script was not invoked by OOo
call bsfShowErrorMessage .true
xScriptContext = uno.getScriptContext()
if (xScriptContext<>.nil) then  -- invoked as a macro/via the dispatch interface
do
   xComponentContext = xScriptContext~getComponentContext
   xDesktop = xScriptContext~getDesktop
   xDocument = xScriptContext~getDocument
end
else  -- called from outside of OOo
do
   xComponentContext = UNO.connect()     -- get a connection
   service = "com.sun.star.frame.Desktop"
   sDesktop = xComponentContext~getServiceManager~XMultiServiceFactory~createInstance(service)
   xDesktop = sDesktop~XDesktop
end
-- this macro just works externally, called by rexxj or rexx
-- create DispatchHelper service and query its interface
xMultiServiceFactory = xComponentContext~getServiceManager~XMultiServiceFactory
sDispatchHelper = xMultiServiceFactory~createInstance("com.sun.star.frame.DispatchHelper")
xDispatchHelper = sDispatchHelper~XDispatchHelper
-- get dispatch provider interface of current Desktop
xDispatchProvider = xDesktop~XDispatchProvider
-- define Rexx dispatch target, library "wu_tools", script name "create_UNO_API_info.rex", location "user"
location   ="user"               -- case sensitive, other possible values: "share" (all users), "application"
libraryName="wu_tools"           -- case sensitive, name of the Rexx macro library
scriptName ="UNO_API_info.rex"   -- case sensitive, name of the Rexx script
langName   ="ooRexx"             -- case sensitive, OOo name of the scripting language
   --  build -- macroUrl--  string for the dispatcher
macroUrl="vnd.sun.star.script:"libraryName"."scriptName"?language="langName"&location="location
say "ooRexx: dispatching to 'create_UNO_API_info.rex' using an UNO object from the running program..."
   -- define one argument (an UNO object from the running program)
args=uno.CreateArray(.UNO~PROPERTYVALUE, 1)  -- array for argument
args[1] = uno.createProperty("arg1", sDispatchHelper)
   -- dispatch
res = xDispatchHelper~executeDispatch(xDispatchProvider, macroURL, "", 0, args)
-- say "ooRexx: res~result:" pp(res~result)   "res~state:" pp(res~state)
say "---"


say "ooRexx: dispatching to 'create_UNO_API_info.rex' using an UNO IDL string and rendering options..."
   -- define options
options = uno.CreateArray(.UNO~PROPERTYVALUE, 7)   /* define array for options   */
options[1] = uno.createProperty("NrOfLayers",           2)  -- 2="show two levels deep"
options[2] = uno.createProperty("View",                 1)  -- 1="view in writer"
options[3] = uno.createProperty("DocumentationSource",  1)  -- 1="use Internet" (base url)
options[4] = uno.createProperty("NumberingTypeLevel_1", 0)  -- 0="Alpha Uppercase"
options[5] = uno.createProperty("NumberingTypeLevel_2", 4)  -- 4="arabic"
options[6] = uno.createProperty("NumberingTypeLevel_3", 3)  -- 3="roman lower"
options[7] = uno.createProperty("FontName",             "DejaVu Sans Condensed")
   -- define two arguments
args=uno.createArray(.uno~propertyValue, 2)  -- we have two arguments
args[1]=uno.createProperty("arg1", "com.sun.star.frame.Desktop")  -- an UNO IDL string
args[2]=uno.createProperty("arg2", options)  -- the öptions for rendering
   -- dispatch
res = xDispatchHelper~executeDispatch(xDispatchProvider, macroURL, "", 0, args)
-- say "ooRexx: res~result:" pp(res~result)   "res~state:" pp(res~state)
say "---"

::requires UNO.CLS   -- get the UNO-support (includes BSF.CLS, i.e. Java-support)

Using "UNO_API_info.rex" Directly from ooRexx

The ooRexx script can be invoked directly from an ooRexx program supplying an UNO object or and UNO IDL string as an argument. In addition rendering options can be given as a second argument in form of an array of an ooRexx directory object, where the index denotes the option's name and the value the desired value.

"TestCreateApiInfo_ooRexx_direct.rex":

-- try to get a script context, will be .nil, if script was not invoked by OOo
call "UNO_API_info"     -- incorporate all public routines and classes
xDesktop = UNO.createDesktop()~XDesktop   -- create Desktop object, query XDesktop interface
say "ooRexx: invoking 'analyzeAndCreateReference' using an UNO object from the running program..."
call analyzeAndCreateReference xDesktop
say "---"
say "ooRexx: invoking 'analyzeAndCreateReference' using an UNO IDL string and rendering options..."
   -- define options
options = .directory~new
options~NrOfLayers          =2  -- 2=show two levels deep
options~View                =1  -- 1=view in writer
options~DocumentationSource =1  -- 1=use Internet (base url
options~NumberingTypeLevel_1=0  -- 0=Alpha Uppercase
options~NumberingTypeLevel_2=4  -- 4=arabic
options~NumberingTypeLevel_3=3  -- 3=roman lower
options~FontName            ="DejaVu Sans Condensed"
call analyzeAndCreateReference "com.sun.star.frame.Desktop", options
say "---"

::requires UNO.CLS   -- get the UNO-support (includes BSF.CLS, i.e. Java-support)



Rony G. Flatscher, Vienna, Austria, as of: 2009-10-20