<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.openoffice.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Jimwhite</id>
	<title>Apache OpenOffice Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.openoffice.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Jimwhite"/>
	<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/wiki/Special:Contributions/Jimwhite"/>
	<updated>2026-12-04T09:06:07Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.35.14</generator>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=GroovyForOpenOffice&amp;diff=84518</id>
		<title>GroovyForOpenOffice</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=GroovyForOpenOffice&amp;diff=84518"/>
		<updated>2008-06-23T16:25:55Z</updated>

		<summary type="html">&lt;p&gt;Jimwhite: Initial info page for G4OO&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=GroovyForOpenOffice (G4OO)=&lt;br /&gt;
&lt;br /&gt;
[http://www.ifcx.org/wiki/GroovyForOpenOffice.html GroovyForOpenOffice] is an OpenOffice extension that adds the capability of writing and running macros (scripts) using the [http://groovy.codehaus.org/ Groovy] programming language.&lt;br /&gt;
&lt;br /&gt;
The binary can be easily installed from it&amp;#039;s page on the Extensions web site: [http://extensions.services.openoffice.org/project/GroovyForOpenOffice http://extensions.services.openoffice.org/project/GroovyForOpenOffice].&lt;br /&gt;
&lt;br /&gt;
The binary along with detailed installation instructions, code samples, instructions for building from source, and a copy of [http://www.ifcx.org/wiki/Wings.html IFCX Wings] is available from [http://sourceforge.net/project/showfiles.php?group_id=199110&amp;amp;package_id=237851 the IFCX download page on SF.net].&lt;br /&gt;
&lt;br /&gt;
Additional samples are being posted here (and contributions invited!) in the [[API/Samples/Groovy]] section.&lt;/div&gt;</summary>
		<author><name>Jimwhite</name></author>
	</entry>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=API/Samples/Groovy&amp;diff=84512</id>
		<title>API/Samples/Groovy</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=API/Samples/Groovy&amp;diff=84512"/>
		<updated>2008-06-23T16:15:22Z</updated>

		<summary type="html">&lt;p&gt;Jimwhite: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Under this section you can find examples showing different API use cases implemented in [http://groovy.codehaus.org/ Groovy].&lt;br /&gt;
You will need to install [[GroovyForOpenOffice]] if you want to write or use OOo macros in Groovy.&lt;br /&gt;
&amp;lt;noinclude&amp;gt;[[Category:API]] [[Category:Samples]]&amp;lt;/noinclude&amp;gt;&lt;br /&gt;
==Office==&lt;br /&gt;
&amp;lt;DPL&amp;gt; category=API&lt;br /&gt;
category=Samples&lt;br /&gt;
category=Groovy&lt;br /&gt;
category=Office&amp;lt;/DPL&amp;gt;&lt;br /&gt;
==Writer==&lt;br /&gt;
&amp;lt;DPL&amp;gt; category=API&lt;br /&gt;
category=Samples&lt;br /&gt;
category=Groovy&lt;br /&gt;
category=Writer&amp;lt;/DPL&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jimwhite</name></author>
	</entry>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=API/Samples/Groovy/Office/RuntimeDialog&amp;diff=84462</id>
		<title>API/Samples/Groovy/Office/RuntimeDialog</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=API/Samples/Groovy/Office/RuntimeDialog&amp;diff=84462"/>
		<updated>2008-06-23T11:53:13Z</updated>

		<summary type="html">&lt;p&gt;Jimwhite: Initial import of macro example&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;noinclude&amp;gt;[[Category:API]] [[Category:Samples]] [[Category:Groovy]] [[Category:Office]]&amp;lt;/noinclude&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==About the Runtime Dialog Groovy Example==&lt;br /&gt;
This is an example demonstrates creating a UNO Dialog and features use of XMultiPropertySet via a UNOCategory API helper.  It based on the code in [[Documentation/DevGuide/Basic/Creating_Dialogs_at_Runtime]].&lt;br /&gt;
&lt;br /&gt;
==The Code==&lt;br /&gt;
&amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
import com.sun.star.awt.ActionEvent&lt;br /&gt;
import com.sun.star.awt.XButton&lt;br /&gt;
import com.sun.star.awt.XControl&lt;br /&gt;
import com.sun.star.awt.XControlContainer&lt;br /&gt;
import com.sun.star.awt.XControlModel&lt;br /&gt;
import com.sun.star.awt.XDialog&lt;br /&gt;
import com.sun.star.awt.XFixedText&lt;br /&gt;
import com.sun.star.awt.XToolkit&lt;br /&gt;
import com.sun.star.awt.XWindow&lt;br /&gt;
&lt;br /&gt;
import com.sun.star.beans.XMultiPropertySet&lt;br /&gt;
import com.sun.star.beans.XPropertySet&lt;br /&gt;
&lt;br /&gt;
import com.sun.star.container.XNameContainer&lt;br /&gt;
&lt;br /&gt;
import com.sun.star.lang.EventObject&lt;br /&gt;
import com.sun.star.lang.XComponent&lt;br /&gt;
import com.sun.star.lang.XMultiComponentFactory&lt;br /&gt;
import com.sun.star.lang.XMultiServiceFactory&lt;br /&gt;
&lt;br /&gt;
import com.sun.star.uno.UnoRuntime&lt;br /&gt;
import com.sun.star.uno.XComponentContext&lt;br /&gt;
import com.sun.star.awt.Rectangle&lt;br /&gt;
import com.sun.star.awt.WindowAttribute&lt;br /&gt;
import com.sun.star.awt.XThrobber&lt;br /&gt;
import com.sun.star.awt.XProgressBar&lt;br /&gt;
import com.sun.star.container.XIndexAccess&lt;br /&gt;
&lt;br /&gt;
// Groovy script&lt;br /&gt;
&lt;br /&gt;
/** method for creating a dialog at runtime */&lt;br /&gt;
&lt;br /&gt;
class UnoCategory {&lt;br /&gt;
    public static Object uno(Object unoObj, Class clazz) { UnoRuntime.queryInterface(clazz, unoObj) }&lt;br /&gt;
&lt;br /&gt;
    public static Object getAt(XPropertySet pset, String pname) { pset.getPropertyValue(pname) }&lt;br /&gt;
&lt;br /&gt;
    public static void putAt(XPropertySet pset, String pname, Object newValue)&lt;br /&gt;
    { pset.setPropertyValue(pname, newValue) }&lt;br /&gt;
&lt;br /&gt;
    public static Object getAt(XIndexAccess ndx, int x) { ndx.getByIndex(x) }&lt;br /&gt;
&lt;br /&gt;
    public static void setMultiPropertySet(Object unoObj, Map properties)&lt;br /&gt;
    {&lt;br /&gt;
        XMultiPropertySet pMSet = unoObj.uno(XMultiPropertySet)&lt;br /&gt;
&lt;br /&gt;
        // Nasty hack to workaround problem when setting Height in the same setPropertyValues&lt;br /&gt;
        // call as other properties.&lt;br /&gt;
        // You also have to set Width after PositionX, fortunately the default for a map&lt;br /&gt;
        // literal in Groovy happens to be LinkedHashMap so the order of the keys is preserved.&lt;br /&gt;
        // If that weren&amp;#039;t the case we&amp;#039;d have to deal with that here too.&lt;br /&gt;
        &lt;br /&gt;
        if ((properties.size() &amp;gt; 1) &amp;amp;&amp;amp; properties.containsKey(&amp;#039;Height&amp;#039;)) {&lt;br /&gt;
            String[] propNames = ((properties.keySet() as List) - [&amp;#039;Height&amp;#039;]) as String[]&lt;br /&gt;
            Object[] values = new Object[propNames.length]&lt;br /&gt;
&lt;br /&gt;
            propNames.eachWithIndex { String n, int x -&amp;gt; values[x] = properties.get(n) }&lt;br /&gt;
&lt;br /&gt;
            pMSet.setPropertyValues(propNames, values)&lt;br /&gt;
&lt;br /&gt;
            // We use setProertyValues rather than setPropertyValue because it is probably&lt;br /&gt;
            // more performant than making the two UNO calls that would require.&lt;br /&gt;
            pMSet.setPropertyValues([&amp;#039;Height&amp;#039;] as String[], [properties.get(&amp;#039;Height&amp;#039;)] as Object[])&lt;br /&gt;
&lt;br /&gt;
//            System.out.println(&amp;quot;setMultiPropertySet-Height $propNames $values ${properties.get(&amp;#039;Height&amp;#039;)} &amp;quot;)&lt;br /&gt;
        } else {&lt;br /&gt;
            String[] propNames = properties.keySet() as String[]&lt;br /&gt;
            Object[] values = new Object[propNames.length]&lt;br /&gt;
&lt;br /&gt;
            propNames.eachWithIndex { String n, int x -&amp;gt; values[x] = properties.get(n) }&lt;br /&gt;
&lt;br /&gt;
            pMSet.setPropertyValues(propNames, values)&lt;br /&gt;
&lt;br /&gt;
//            System.out.println(&amp;quot;setMultiPropertySet $propNames $values ${pMSet instanceof XMultiPropertySet} &amp;quot;)&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public static XNameContainer leftShift(XNameContainer container, Map values)&lt;br /&gt;
    {&lt;br /&gt;
//        System.out.println &amp;quot;leftShifting $values&amp;quot;&lt;br /&gt;
        values.each { name, value -&amp;gt; container.insertByName(name, value) }&lt;br /&gt;
        return container&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/** action listener */&lt;br /&gt;
&lt;br /&gt;
public class CountActionListenerImpl implements com.sun.star.awt.XActionListener&lt;br /&gt;
{&lt;br /&gt;
    XFixedText label&lt;br /&gt;
    String labelPrefix&lt;br /&gt;
    XProgressBar progressBar&lt;br /&gt;
&lt;br /&gt;
    private int _nCounts = 0;&lt;br /&gt;
&lt;br /&gt;
    // XEventListener&lt;br /&gt;
    public void disposing(EventObject eventObject)&lt;br /&gt;
    {&lt;br /&gt;
//        System.out.println(&amp;#039;CountActionListener disposing.&amp;#039;)&lt;br /&gt;
        label = null&lt;br /&gt;
        progressBar = null&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    // XActionListener&lt;br /&gt;
    public void actionPerformed(ActionEvent actionEvent)&lt;br /&gt;
    {&lt;br /&gt;
        System.out.println(&amp;#039;CountActionListener actionPerformed.&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
        // increase click counter&lt;br /&gt;
        _nCounts++;&lt;br /&gt;
&lt;br /&gt;
        label.setText(labelPrefix + _nCounts);&lt;br /&gt;
&lt;br /&gt;
        progressBar.value = (progressBar.value + 1) % 10&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public class CancelActionListenerImpl implements com.sun.star.awt.XActionListener&lt;br /&gt;
{&lt;br /&gt;
    private XDialog dialog;&lt;br /&gt;
&lt;br /&gt;
    // XEventListener&lt;br /&gt;
    public void disposing(EventObject eventObject)&lt;br /&gt;
    {&lt;br /&gt;
//        System.out.println(&amp;#039;CancelActionListener disposing.&amp;#039;)&lt;br /&gt;
        dialog = null;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    // XActionListener&lt;br /&gt;
    public void actionPerformed(ActionEvent actionEvent)&lt;br /&gt;
    {&lt;br /&gt;
        System.out.println(&amp;#039;CancelActionListener ending execution.&amp;#039;)&lt;br /&gt;
        dialog.endExecute()&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 This method creates a UNO modal dialog, fills it in, and return the object (com.sun.star.awt.UnoControlDialog).&lt;br /&gt;
 It must be called in the context of a use(UNOCategory).&lt;br /&gt;
*/&lt;br /&gt;
Object createDialog(XComponentContext _xComponentContext) throws com.sun.star.uno.Exception&lt;br /&gt;
{&lt;br /&gt;
    final String _buttonName = &amp;#039;Button1&amp;#039;&lt;br /&gt;
    final String _labelName = &amp;#039;Label1&amp;#039;&lt;br /&gt;
    final String _labelPrefix = &amp;#039;Counts : &amp;#039;&lt;br /&gt;
    final String _cancelButtonName = &amp;#039;CancelButton1&amp;#039;&lt;br /&gt;
    final String _editName = &amp;#039;Edit1&amp;#039;&lt;br /&gt;
    final String _throbberName = &amp;#039;Throbber1&amp;#039;&lt;br /&gt;
&lt;br /&gt;
    // get the service manager from the component context&lt;br /&gt;
    XMultiComponentFactory xMultiComponentFactory = _xComponentContext.getServiceManager();&lt;br /&gt;
&lt;br /&gt;
    // create the dialog model and set the properties&lt;br /&gt;
    Object dialogModel = xMultiComponentFactory.createInstanceWithContext(&lt;br /&gt;
            &amp;quot;com.sun.star.awt.UnoControlDialogModel&amp;quot;, _xComponentContext);&lt;br /&gt;
&lt;br /&gt;
    // Can&amp;#039;t set x/y and width/height at same time.&lt;br /&gt;
    // Just set width/height at let OOo pick the x/y.&lt;br /&gt;
    // This doesn&amp;#039;t work to make dialog window resizable (it is moveable &amp;amp; closeable by default).&lt;br /&gt;
    dialogModel.multiPropertySet = [Width:150, Height:200, Title:&amp;#039;Runtime Dialog Demo&amp;#039;&lt;br /&gt;
        , Closeable: true, Moveable:true, Sizeable:true]&lt;br /&gt;
&lt;br /&gt;
    // get the service manager from the dialog model&lt;br /&gt;
    XMultiServiceFactory xMultiServiceFactory = dialogModel.uno(XMultiServiceFactory)&lt;br /&gt;
&lt;br /&gt;
    // create the button model and set the properties&lt;br /&gt;
    // This button gets the 0th TabIndex because it is the default button.&lt;br /&gt;
    // But just setting TabIndex doesn&amp;#039;t seem to do the job for the default.&lt;br /&gt;
    // Apparently it is the first button added to the container.&lt;br /&gt;
    Object cancelButtonModel = xMultiServiceFactory.createInstance(&amp;#039;com.sun.star.awt.UnoControlButtonModel&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
    cancelButtonModel.multiPropertySet = [PositionX:90, PositionY:10, Width:50, Height:14&lt;br /&gt;
        , Name:_cancelButtonName, TabIndex:0, Label:&amp;quot;Cancel&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
    // create the button model and set the properties&lt;br /&gt;
    Object buttonModel = xMultiServiceFactory.createInstance(&amp;#039;com.sun.star.awt.UnoControlButtonModel&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
    buttonModel.multiPropertySet = [PositionX:10, PositionY:10, Width:50, Height:14&lt;br /&gt;
            , Name:_buttonName, TabIndex:1, Label:&amp;quot;Stop!&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
    // create the label model and set the properties&lt;br /&gt;
    Object labelModel = xMultiServiceFactory.createInstance(&amp;#039;com.sun.star.awt.UnoControlFixedTextModel&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
    labelModel.multiPropertySet = [PositionX:10, PositionY:30, Width:60, Height:14&lt;br /&gt;
        , Name:_labelName, TabIndex:3, Label:_labelPrefix]&lt;br /&gt;
&lt;br /&gt;
    Object editModel = xMultiServiceFactory.createInstance(&amp;#039;com.sun.star.awt.UnoControlEditModel&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
    editModel.multiPropertySet = [PositionX:5, PositionY:45, Width:140, Height:150, Border:2 as Short /* Simple */&lt;br /&gt;
        , Name:_editName, TabIndex:2&lt;br /&gt;
        , HScroll:true, VScroll:true, MultiLine:true&lt;br /&gt;
        , LineEndFormat:2 as Short /* LINE_FEED */&lt;br /&gt;
        , Text:&amp;#039;This is some initial text.\nAnother line.\nFinis.&amp;#039;]&lt;br /&gt;
&lt;br /&gt;
    // create the label model and set the properties&lt;br /&gt;
    Object throbberModel = xMultiServiceFactory.createInstance(&amp;#039;com.sun.star.awt.UnoControlProgressBarModel&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
    throbberModel.multiPropertySet = [PositionX:80, PositionY:30, Width:60, Height:14&lt;br /&gt;
        , Name:_throbberName, TabIndex:4&lt;br /&gt;
        , ProgressValue:0, ProgressValueMin:0, ProgressValueMax:9]&lt;br /&gt;
&lt;br /&gt;
    // insert the control models into the dialog model&lt;br /&gt;
    XNameContainer xNameCont = dialogModel.uno(XNameContainer)&lt;br /&gt;
&lt;br /&gt;
    // Add the default button (Cancel) first.&lt;br /&gt;
    xNameCont.insertByName(_cancelButtonName, cancelButtonModel)&lt;br /&gt;
    xNameCont.insertByName(_buttonName, buttonModel)&lt;br /&gt;
    xNameCont.insertByName(_labelName, labelModel)&lt;br /&gt;
    xNameCont.insertByName(_editName, editModel)&lt;br /&gt;
    xNameCont.insertByName(_throbberName, throbberModel)&lt;br /&gt;
&lt;br /&gt;
    // This is another way to use UnoCategory to do the above, but the syntax is a bit odd and adds some overhead.&lt;br /&gt;
//    dialogModel.uno(XNameContainer) &amp;lt;&amp;lt;&lt;br /&gt;
//        [(_buttonName):buttonModel, (_labelName):labelModel, (_cancelButtonName):cancelButtonModel]&lt;br /&gt;
&lt;br /&gt;
    // create the dialog control and set the model&lt;br /&gt;
    Object dialog = xMultiComponentFactory.createInstanceWithContext(&lt;br /&gt;
            &amp;quot;com.sun.star.awt.UnoControlDialog&amp;quot;, _xComponentContext);&lt;br /&gt;
&lt;br /&gt;
    XControl xControl = dialog.uno(XControl)&lt;br /&gt;
&lt;br /&gt;
    xControl.setModel(dialogModel.uno(XControlModel))&lt;br /&gt;
&lt;br /&gt;
    XDialog xDialog = dialog.uno(XDialog)&lt;br /&gt;
&lt;br /&gt;
    // add an action listener to the button control&lt;br /&gt;
    XControlContainer xControlCont = dialog.uno(XControlContainer)&lt;br /&gt;
&lt;br /&gt;
    xControlCont.getControl(_buttonName).uno(XButton).addActionListener(&lt;br /&gt;
            new CountActionListenerImpl(label:xControlCont.getControl(_labelName).uno(XFixedText)&lt;br /&gt;
                    , labelPrefix:_labelPrefix&lt;br /&gt;
                    , progressBar:xControlCont.getControl(_throbberName).uno(XProgressBar)));&lt;br /&gt;
&lt;br /&gt;
    xControlCont.getControl(_cancelButtonName).uno(XButton).addActionListener(&lt;br /&gt;
            new CancelActionListenerImpl(dialog:xDialog));&lt;br /&gt;
&lt;br /&gt;
    // This doesn&amp;#039;t seem to serve any purpose...&lt;br /&gt;
//    XWindow xWindow = xControl.uno(XWindow)&lt;br /&gt;
//&lt;br /&gt;
//    xWindow.setVisible(false);&lt;br /&gt;
&lt;br /&gt;
//    This doesn&amp;#039;t work to make dialog window resizable.&lt;br /&gt;
//    Short flags = (WindowAttribute.BORDER | WindowAttribute.MOVEABLE&lt;br /&gt;
//        | WindowAttribute.SIZEABLE | WindowAttribute.CLOSEABLE)&lt;br /&gt;
//&lt;br /&gt;
//    Rectangle posSize = xWindow.getPosSize()&lt;br /&gt;
//&lt;br /&gt;
//    xWindow.setPosSize(posSize.X, posSize.Y, posSize.Width, posSize.Height, flags)&lt;br /&gt;
&lt;br /&gt;
    // create a peer&lt;br /&gt;
    Object toolkit = xMultiComponentFactory.createInstanceWithContext(&lt;br /&gt;
            &amp;quot;com.sun.star.awt.Toolkit&amp;quot;, _xComponentContext);&lt;br /&gt;
&lt;br /&gt;
    XToolkit xToolkit = toolkit.uno(XToolkit)&lt;br /&gt;
&lt;br /&gt;
    xControl.createPeer(xToolkit, null);&lt;br /&gt;
&lt;br /&gt;
    return dialog;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
use (UnoCategory) {&lt;br /&gt;
    Object dialog = createDialog(XSCRIPTCONTEXT.componentContext)&lt;br /&gt;
&lt;br /&gt;
    // execute the dialog, which won&amp;#039;t return until it is closed.&lt;br /&gt;
    dialog.uno(XDialog).execute();&lt;br /&gt;
&lt;br /&gt;
    System.out.println(&amp;#039;xDialog.execute has returned!&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
    // we can put it up there again if we like.&lt;br /&gt;
    dialog.uno(XDialog).execute();&lt;br /&gt;
&lt;br /&gt;
    System.out.println(&amp;#039;xDialog.execute has returned again!&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
    // dispose the dialog&lt;br /&gt;
    dialog.uno(XComponent).dispose();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
0&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jimwhite</name></author>
	</entry>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=API/Samples/Groovy/Office/PropertySet&amp;diff=84432</id>
		<title>API/Samples/Groovy/Office/PropertySet</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=API/Samples/Groovy/Office/PropertySet&amp;diff=84432"/>
		<updated>2008-06-23T04:03:39Z</updated>

		<summary type="html">&lt;p&gt;Jimwhite: Add link to CleanUpForHTML sample&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;noinclude&amp;gt;[[Category:API]] [[Category:Samples]] [[Category:Groovy]] [[Category:Office]]&amp;lt;/noinclude&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==About the PropertySet Example==&lt;br /&gt;
This example shows how to access properties in a Groovy macro or extension using a category (aka &amp;quot;mixin&amp;quot;) UNO API helper.&lt;br /&gt;
&lt;br /&gt;
First let&amp;#039;s look what the code for this sample is in Java:&lt;br /&gt;
==The Java Code==&lt;br /&gt;
&amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
// Get the ActionEvent object from the ARGUMENTS list&lt;br /&gt;
ActionEvent event = (ActionEvent) ARGUMENTS[0];&lt;br /&gt;
&lt;br /&gt;
// Each argument is of type Any so we must use the AnyConverter class to&lt;br /&gt;
// convert it into the interface or primitive type we expect&lt;br /&gt;
XButton button = (XButton)AnyConverter.toObject(&lt;br /&gt;
    new Type(XButton.class), event.Source);&lt;br /&gt;
&lt;br /&gt;
// We can now query for the model of the button and get its properties&lt;br /&gt;
XControl control = (XControl)UnoRuntime.queryInterface(XControl.class, button);&lt;br /&gt;
XControlModel cmodel = control.getModel();&lt;br /&gt;
XPropertySet pset = (XPropertySet)UnoRuntime.queryInterface(&lt;br /&gt;
    XPropertySet.class, cmodel);&lt;br /&gt;
&lt;br /&gt;
if (pset.getPropertyValue(&amp;quot;Label&amp;quot;).equals(&amp;quot;Exit&amp;quot;))&lt;br /&gt;
{&lt;br /&gt;
    // We can get the XDialog in which this control appears by calling&lt;br /&gt;
    // getContext() on the XControl interface&lt;br /&gt;
    XDialog xDialog = (XDialog)UnoRuntime.queryInterface(&lt;br /&gt;
        XDialog.class, control.getContext());&lt;br /&gt;
    &lt;br /&gt;
    // Close the dialog&lt;br /&gt;
    xDialog.endExecute();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And now the Groovy way:&lt;br /&gt;
==The Groovy Code==&lt;br /&gt;
&amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
// Get the ActionEvent object from the ARGUMENTS list&lt;br /&gt;
ActionEvent event = (ActionEvent) ARGUMENTS[0];&lt;br /&gt;
&lt;br /&gt;
// Each argument is of type Any so we must use the AnyConverter class to&lt;br /&gt;
// convert it into the interface or primitive type we expect&lt;br /&gt;
XButton button = (XButton)AnyConverter.toObject(new Type(XButton), event.Source);&lt;br /&gt;
&lt;br /&gt;
// We can now query for the model of the button and get its properties&lt;br /&gt;
XControl control = button.uno(XControl)&lt;br /&gt;
XPropertySet pset = control.getModel().uno(XPropertySet)&lt;br /&gt;
&lt;br /&gt;
if (pset[&amp;quot;Label&amp;quot;].equals(&amp;quot;Exit&amp;quot;))&lt;br /&gt;
{&lt;br /&gt;
    // Close the dialog&lt;br /&gt;
    control.getContext().uno(XDialog).endExecute()&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or here&amp;#039;s any even shorter version that makes further use of Groovy&amp;#039;s dynamic typing:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
// Get the ActionEvent object from the ARGUMENTS list&lt;br /&gt;
def event = ARGUMENTS[0]&lt;br /&gt;
&lt;br /&gt;
// Each argument is of type Any so we must use the AnyConverter class to&lt;br /&gt;
// convert it into the interface or primitive type we expect&lt;br /&gt;
def button = AnyConverter.toObject(new Type(XButton), event.Source)&lt;br /&gt;
&lt;br /&gt;
// We can now query for the model of the button and get its properties&lt;br /&gt;
def control = button.uno(XControl)&lt;br /&gt;
def pset = control.model.uno(XPropertySet)&lt;br /&gt;
&lt;br /&gt;
if (pset[&amp;quot;Label&amp;quot;].equals(&amp;quot;Exit&amp;quot;))&lt;br /&gt;
{&lt;br /&gt;
    // Close the dialog&lt;br /&gt;
    control.context.uno(XDialog).endExecute()&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==The UnoCategory API Helper==&lt;br /&gt;
In order to let Groovy know how to make those adaptations for the UNO API, we use a [http://groovy.codehaus.org/Groovy+Categories Groovy Category].  For this sample that code looks like this:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
class UnoCategory {&lt;br /&gt;
    public static Object uno(Object unoObj, Class clazz) {UnoRuntime.queryInterface(clazz, unoObj)}&lt;br /&gt;
    public static Object getAt(XPropertySet pset, String pname) {pset.getPropertyValue(pname)}&lt;br /&gt;
    public static void putAt(XPropertySet pset, String pname, Object newValue) {pset.setPropertyValue(pname, newValue)}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To see this at  work in some real code, see the [[API/Samples/Groovy/Writer/CleanUpForHTML]] example.&lt;/div&gt;</summary>
		<author><name>Jimwhite</name></author>
	</entry>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=API/Samples/Groovy/Writer/CleanUpForHTML&amp;diff=84430</id>
		<title>API/Samples/Groovy/Writer/CleanUpForHTML</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=API/Samples/Groovy/Writer/CleanUpForHTML&amp;diff=84430"/>
		<updated>2008-06-23T03:55:04Z</updated>

		<summary type="html">&lt;p&gt;Jimwhite: Tweak a comment and imports&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;noinclude&amp;gt;[[Category:API]] [[Category:Samples]] [[Category:Groovy]] [[Category:Writer]]&amp;lt;/noinclude&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==About the CleanUpForHTML Example==&lt;br /&gt;
This is an example shows how to access properties in a Groovy macro or extension using a category (aka &amp;quot;mixin&amp;quot;) UNO API helper.  It is the CleanUpForHTML macro used in [http://www.ifcx.org/wiki/Wings.html IFCX Wings] to compensate for issues with the HTML generated by OpenOffice for Writer documents.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Code==&lt;br /&gt;
&amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
/**&lt;br /&gt;
 * IFCX Wings - CleanUpForHTML.groovy macro.&lt;br /&gt;
 * Copyright 2007-2008 by James P. White.  All rights reserved.&lt;br /&gt;
 * mailto:jim@pagesmiths.com&lt;br /&gt;
 * http://www.ifcx.org/&lt;br /&gt;
 *&lt;br /&gt;
 * This software may be redistributed under the term of the GNU GENERAL PUBLIC LICENSE Version 2.&lt;br /&gt;
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html&lt;br /&gt;
 *&lt;br /&gt;
 * For expert professional services and/or distribution under other terms, contact the author:&lt;br /&gt;
 *&lt;br /&gt;
 * James P. White&lt;br /&gt;
 * mailto:jim@pagesmiths.com&lt;br /&gt;
 * 26272 Summerhill Lane&lt;br /&gt;
 * Laguna Hills, CA&lt;br /&gt;
 * USA 92653&lt;br /&gt;
 *&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
package org.ifcx.wings.openoffice&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
    Import standard OpenOffice.org API classes. For more information on&lt;br /&gt;
    these classes and the OpenOffice.org API, see the OpenOffice.org&lt;br /&gt;
    Developers Guide at:&lt;br /&gt;
&lt;br /&gt;
    http://api.openoffice.org/&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
import com.sun.star.uno.UnoRuntime&lt;br /&gt;
import com.sun.star.uno.XInterface&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
    Import XScriptContext class. An instance of this class is available&lt;br /&gt;
    to all BeanShell scripts in the global variable &amp;quot;XSCRIPTCONTEXT&amp;quot;. This&lt;br /&gt;
    variable can be used to access the document for which this script&lt;br /&gt;
    was invoked.&lt;br /&gt;
&lt;br /&gt;
    Methods available are:&lt;br /&gt;
&lt;br /&gt;
        XSCRIPTCONTEXT.getDocument() returns XModel&lt;br /&gt;
        XSCRIPTCONTEXT.getDesktop() returns XDesktop&lt;br /&gt;
        XSCRIPTCONTEXT.getComponentContext() returns XComponentContext&lt;br /&gt;
&lt;br /&gt;
    For more information on using this class see the scripting&lt;br /&gt;
    developer guides at:&lt;br /&gt;
&lt;br /&gt;
        http://framework.openoffice.org/scripting/index.html&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
import com.sun.star.beans.XPropertySet&lt;br /&gt;
&lt;br /&gt;
import com.sun.star.text.XTextRange&lt;br /&gt;
import com.sun.star.text.XTextViewCursorSupplier&lt;br /&gt;
import com.sun.star.view.XViewCursor&lt;br /&gt;
import com.sun.star.text.XParagraphCursor&lt;br /&gt;
&lt;br /&gt;
class UnoCategory {&lt;br /&gt;
    public static Object uno(Object unoObj, Class clazz) {UnoRuntime.queryInterface(clazz, unoObj)}&lt;br /&gt;
&lt;br /&gt;
    public static Object getAt(XPropertySet pset, String pname) {pset.getPropertyValue(pname)}&lt;br /&gt;
&lt;br /&gt;
    public static void putAt(XPropertySet pset, String pname, Object newValue) {pset.setPropertyValue(pname, newValue)}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * In order for the paragraph style to apply to an entire code block (a run of code&lt;br /&gt;
 * paragraphs that Wings evaluates as a single block), we find all multiple line&lt;br /&gt;
 * code blocks and make sure that they are a single paragraph.  It is normal for&lt;br /&gt;
 * code blocks to consist of multiple paragraphs because pressing &amp;#039;return&amp;#039; starts&lt;br /&gt;
 * a new paragraph.&lt;br /&gt;
 */&lt;br /&gt;
def doMergeCode(document) {&lt;br /&gt;
    def viewCursor = document.currentController.uno(XTextViewCursorSupplier).viewCursor&lt;br /&gt;
    // We get the XText from the cursor so that if it is from a frame or table it&amp;#039;ll work.&lt;br /&gt;
    def docText = viewCursor.text&lt;br /&gt;
    XParagraphCursor textCursor = docText.createTextCursorByRange(viewCursor).uno(XParagraphCursor)&lt;br /&gt;
&lt;br /&gt;
    // It&amp;#039;s a &amp;quot;paragraph&amp;quot; cursor, but may be positioned inside one.&lt;br /&gt;
    // We assume that since &amp;quot;GroovyCode&amp;quot; is supposed to be a &amp;quot;paragragh&amp;quot; style&lt;br /&gt;
    // that we&amp;#039;ll still be in &amp;quot;GroovyCode&amp;quot; when we go to the beginning.&lt;br /&gt;
&lt;br /&gt;
    textCursor.gotoStartOfParagraph(false)&lt;br /&gt;
&lt;br /&gt;
    while (true) {&lt;br /&gt;
        // Code blocks are runs of paragraphs whose style name ends with &amp;quot;Code&amp;quot;.&lt;br /&gt;
        while (!(textCursor.uno(XPropertySet)[&amp;#039;ParaStyleName&amp;#039;] =~ /.*Code$/)) {&lt;br /&gt;
//            println &amp;quot;Skipping ahead.&amp;quot;&lt;br /&gt;
            if (!textCursor.gotoNextParagraph(false)) {&lt;br /&gt;
                // Can&amp;#039;t find another paragraph, so we&amp;#039;re done.&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        XParagraphCursor codeRange = docText.createTextCursorByRange(textCursor).uno(XParagraphCursor)&lt;br /&gt;
&lt;br /&gt;
        def codeStyle = textCursor.uno(XPropertySet)[&amp;#039;ParaStyleName&amp;#039;]&lt;br /&gt;
&lt;br /&gt;
        // Move forward paragraphs until the end of the document,&lt;br /&gt;
        // or we find a paragraph that isn&amp;#039;t &amp;quot;GroovyCode&amp;quot; then move back one.&lt;br /&gt;
&lt;br /&gt;
        while (textCursor.gotoNextParagraph(false)) {&lt;br /&gt;
            if (textCursor.uno(XPropertySet)[&amp;#039;ParaStyleName&amp;#039;] != codeStyle) {&lt;br /&gt;
                if (!textCursor.gotoPreviousParagraph(false)) doError(&amp;quot;Couldn&amp;#039;t move back (end)!&amp;quot;);&lt;br /&gt;
                break;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        // The cursor is at the start of the paragraph, move it to the end.&lt;br /&gt;
        textCursor.gotoEndOfParagraph(false);&lt;br /&gt;
&lt;br /&gt;
        // Then select all that text as our code.&lt;br /&gt;
        codeRange.gotoRange(textCursor.end, true)&lt;br /&gt;
&lt;br /&gt;
        def codeString = codeRange.string&lt;br /&gt;
&lt;br /&gt;
//        println codeString&lt;br /&gt;
&lt;br /&gt;
        // the TextRange.getString() will have replaced paragraph end characters with &amp;#039;\n&amp;#039;,&lt;br /&gt;
        // which is the same as line breaks within a paragraph.  So we don&amp;#039;t really know&lt;br /&gt;
        // whether we have multiple paragraphs or not, but we don&amp;#039;t really care.&lt;br /&gt;
&lt;br /&gt;
        if (codeString.contains(&amp;#039;\n&amp;#039;)) {&lt;br /&gt;
//            println &amp;quot;Replacing some&amp;quot;&lt;br /&gt;
            // There are multiple lines, so we replace the paragraph(s) with a single&lt;br /&gt;
            // paragraph of multiple lines.&lt;br /&gt;
            codeRange.text.insertString(codeRange, codeString, true)&lt;br /&gt;
            // The paragraph style is unchanged so we don&amp;#039;t need to do anything about that.&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        if (!textCursor.gotoNextParagraph(false))&lt;br /&gt;
            return&lt;br /&gt;
    }&lt;br /&gt;
}  // def doMergeCode...&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * When saving as HTML, OpenOffice doesn&amp;#039;t take into consideration that all whitespace runs&lt;br /&gt;
 * will be collapsed into a single space (or line break).  That is disaster for most program&lt;br /&gt;
 * text (code and output) which typically depend on leading whitespace on lines to be preserved.&lt;br /&gt;
 * So what this method does is replace all leading whitespace on each line of a style that&lt;br /&gt;
 * looks like it is used for Wings (those whose nanes end with &amp;quot;Code&amp;quot;, &amp;quot;Result&amp;quot;, &amp;quot;Exception&amp;quot;,&lt;br /&gt;
 * &amp;quot;Output&amp;quot;, &amp;quot;Error&amp;quot;, or &amp;quot;Input&amp;quot;) and replace it with non-breaking spaces.&lt;br /&gt;
 */&lt;br /&gt;
def doFixFormatting(document) {&lt;br /&gt;
    def viewCursor = document.currentController.uno(XTextViewCursorSupplier).viewCursor&lt;br /&gt;
    // We get the XText from the cursor so that if it is from a frame or table it&amp;#039;ll work.&lt;br /&gt;
    def docText = viewCursor.text&lt;br /&gt;
    XParagraphCursor textCursor = docText.createTextCursorByRange(viewCursor).uno(XParagraphCursor)&lt;br /&gt;
&lt;br /&gt;
    // It&amp;#039;s a &amp;quot;paragraph&amp;quot; cursor, but may be positioned inside one.&lt;br /&gt;
    // We assume that since &amp;quot;GroovyCode&amp;quot; is supposed to be a &amp;quot;paragragh&amp;quot; style&lt;br /&gt;
    // that we&amp;#039;ll still be in &amp;quot;GroovyCode&amp;quot; when we go to the beginning.&lt;br /&gt;
&lt;br /&gt;
    textCursor.gotoStartOfParagraph(false)&lt;br /&gt;
&lt;br /&gt;
    while (true) {&lt;br /&gt;
        String codeStyle = textCursor.uno(XPropertySet)[&amp;#039;ParaStyleName&amp;#039;]&lt;br /&gt;
&lt;br /&gt;
        // Match style names of interest, if no match then it just falls thru.&lt;br /&gt;
        switch (codeStyle) {&lt;br /&gt;
            case ~/.*Code$/:&lt;br /&gt;
            case ~/.*Result$/:&lt;br /&gt;
            case ~/.*Exception$/:&lt;br /&gt;
            case ~/.*Output$/:&lt;br /&gt;
            case ~/.*Errors$/:&lt;br /&gt;
            case ~/.*Input$/:&lt;br /&gt;
&lt;br /&gt;
                XParagraphCursor codeRange = docText.createTextCursorByRange(textCursor).uno(XParagraphCursor)&lt;br /&gt;
&lt;br /&gt;
                // The cursor is at the start of the paragraph, move it to the end.&lt;br /&gt;
                textCursor.gotoEndOfParagraph(false);&lt;br /&gt;
&lt;br /&gt;
                // Then select all that text as our code.&lt;br /&gt;
                codeRange.gotoRange(textCursor.end, true)&lt;br /&gt;
&lt;br /&gt;
                def codeString = codeRange.string&lt;br /&gt;
&lt;br /&gt;
//                println codeString&lt;br /&gt;
&lt;br /&gt;
                if (codeString.contains(&amp;#039; &amp;#039;) || codeString.contains(&amp;#039;\t&amp;#039;)) {&lt;br /&gt;
//                    println &amp;quot;Replacing some&amp;quot;&lt;br /&gt;
&lt;br /&gt;
                    String[] lines = codeString.split(&amp;#039;\n&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
                    lines.length.times {&lt;br /&gt;
                        String line = lines[it]&lt;br /&gt;
&lt;br /&gt;
                        // Treat tabs as eight spaces.&lt;br /&gt;
                        line = line.replace(&amp;#039;\t&amp;#039;, &amp;#039;        &amp;#039;)&lt;br /&gt;
&lt;br /&gt;
                        if (line.startsWith(&amp;#039; &amp;#039;)) {&lt;br /&gt;
                            char[] chars = line.toCharArray()&lt;br /&gt;
&lt;br /&gt;
                            // Replace the leading spaces with non-breaking spaces.&lt;br /&gt;
                            for (int i = 0; i &amp;lt; chars.length; ++i) {&lt;br /&gt;
                                if (&amp;#039; &amp;#039; != chars[i]) break&lt;br /&gt;
                                chars[i] = &amp;#039;\u00A0&amp;#039;&lt;br /&gt;
                            }&lt;br /&gt;
&lt;br /&gt;
                            lines[it] = new String(chars)&lt;br /&gt;
                        }&lt;br /&gt;
                    }&lt;br /&gt;
&lt;br /&gt;
                    codeRange.text.insertString(codeRange, lines.join(&amp;#039;\n&amp;#039;), true)&lt;br /&gt;
                }&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
//        println &amp;quot;Skipping ahead.&amp;quot;&lt;br /&gt;
        if (!textCursor.gotoNextParagraph(false)) {&lt;br /&gt;
            return;&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
    }&lt;br /&gt;
}  // def doFixFormatting...&lt;br /&gt;
&lt;br /&gt;
////////////// BEGIN //////////////&lt;br /&gt;
// This is the XModel for the currently active document.&lt;br /&gt;
def document = XSCRIPTCONTEXT.document&lt;br /&gt;
&lt;br /&gt;
use(UnoCategory) {&lt;br /&gt;
    doMergeCode(document)&lt;br /&gt;
    doFixFormatting(document)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
0&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jimwhite</name></author>
	</entry>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=API/Samples/Groovy/Writer/CleanUpForHTML&amp;diff=84429</id>
		<title>API/Samples/Groovy/Writer/CleanUpForHTML</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=API/Samples/Groovy/Writer/CleanUpForHTML&amp;diff=84429"/>
		<updated>2008-06-23T03:47:44Z</updated>

		<summary type="html">&lt;p&gt;Jimwhite: Initial import of macro example&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;noinclude&amp;gt;[[Category:API]] [[Category:Samples]] [[Category:Groovy]] [[Category:Writer]]&amp;lt;/noinclude&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==About the CleanUpForHTML Example==&lt;br /&gt;
This is an example shows how to access properties in a Groovy macro or extension using a category (aka &amp;quot;mixin&amp;quot;) UNO API helper.  It is the CleanUpForHTML macro used in [http://www.ifcx.org/wiki/Wings.html IFCX Wings] to compensate for issues with the HTML generated by OpenOffice for Writer documents.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Code==&lt;br /&gt;
&amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
/**&lt;br /&gt;
 * IFCX Wings - CleanUpForHTML.groovy macro.&lt;br /&gt;
 * Copyright 2007-2008 by James P. White.  All rights reserved.&lt;br /&gt;
 * mailto:jim@pagesmiths.com&lt;br /&gt;
 * http://www.ifcx.org/&lt;br /&gt;
 *&lt;br /&gt;
 * This software may be redistributed under the term of the GNU GENERAL PUBLIC LICENSE Version 2.&lt;br /&gt;
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html&lt;br /&gt;
 *&lt;br /&gt;
 * For expert professional services and/or distribution under other terms, contact the author:&lt;br /&gt;
 *&lt;br /&gt;
 * James P. White&lt;br /&gt;
 * mailto:jim@pagesmiths.com&lt;br /&gt;
 * 26272 Summerhill Lane&lt;br /&gt;
 * Laguna Hills, CA&lt;br /&gt;
 * USA 92653&lt;br /&gt;
 *&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
package org.ifcx.wings.openoffice&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
    Import standard OpenOffice.org API classes. For more information on&lt;br /&gt;
    these classes and the OpenOffice.org API, see the OpenOffice.org&lt;br /&gt;
    Developers Guide at:&lt;br /&gt;
&lt;br /&gt;
    http://api.openoffice.org/&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
import com.sun.star.uno.UnoRuntime&lt;br /&gt;
import com.sun.star.uno.XInterface&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
    Import XScriptContext class. An instance of this class is available&lt;br /&gt;
    to all BeanShell scripts in the global variable &amp;quot;XSCRIPTCONTEXT&amp;quot;. This&lt;br /&gt;
    variable can be used to access the document for which this script&lt;br /&gt;
    was invoked.&lt;br /&gt;
&lt;br /&gt;
    Methods available are:&lt;br /&gt;
&lt;br /&gt;
        XSCRIPTCONTEXT.getDocument() returns XModel&lt;br /&gt;
        XSCRIPTCONTEXT.getDesktop() returns XDesktop&lt;br /&gt;
        XSCRIPTCONTEXT.getComponentContext() returns XComponentContext&lt;br /&gt;
&lt;br /&gt;
    For more information on using this class see the scripting&lt;br /&gt;
    developer guides at:&lt;br /&gt;
&lt;br /&gt;
        http://framework.openoffice.org/scripting/index.html&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
import com.sun.star.lang.XTypeProvider&lt;br /&gt;
import com.sun.star.lang.XServiceInfo&lt;br /&gt;
import com.sun.star.beans.XPropertySet&lt;br /&gt;
&lt;br /&gt;
import com.sun.star.text.XTextRange&lt;br /&gt;
import com.sun.star.text.XTextViewCursorSupplier&lt;br /&gt;
import com.sun.star.view.XViewCursor&lt;br /&gt;
import com.sun.star.text.XParagraphCursor&lt;br /&gt;
&lt;br /&gt;
class UnoCategory {&lt;br /&gt;
    public static Object uno(Object unoObj, Class clazz) {UnoRuntime.queryInterface(clazz, unoObj)}&lt;br /&gt;
&lt;br /&gt;
    public static Object getAt(XPropertySet pset, String pname) {pset.getPropertyValue(pname)}&lt;br /&gt;
&lt;br /&gt;
    public static void putAt(XPropertySet pset, String pname, Object newValue) {pset.setPropertyValue(pname, newValue)}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * In order for the paragraph style to apply to an entire code block (a run of code&lt;br /&gt;
 * paragraphs that Wings evaluates as a single block), we find all multiple line&lt;br /&gt;
 * code blocks and make sure that they are a single paragraph.  It is normal for&lt;br /&gt;
 * code blocks to consist of multiple paragraphs because pressing &amp;#039;return&amp;#039; starts&lt;br /&gt;
 * a new paragraph.&lt;br /&gt;
 */&lt;br /&gt;
def doMergeCode(document) {&lt;br /&gt;
    def viewCursor = document.currentController.uno(XTextViewCursorSupplier).viewCursor&lt;br /&gt;
    // We get the XText from the cursor so that if it is from a frame or table it&amp;#039;ll work.&lt;br /&gt;
    def docText = viewCursor.text&lt;br /&gt;
    XParagraphCursor textCursor = docText.createTextCursorByRange(viewCursor).uno(XParagraphCursor)&lt;br /&gt;
&lt;br /&gt;
    // It&amp;#039;s a &amp;quot;paragraph&amp;quot; cursor, but may be positioned inside one.&lt;br /&gt;
    // We assume that since &amp;quot;GroovyCode&amp;quot; is supposed to be a &amp;quot;paragragh&amp;quot; style&lt;br /&gt;
    // that we&amp;#039;ll still be in &amp;quot;GroovyCode&amp;quot; when we go to the beginning.&lt;br /&gt;
&lt;br /&gt;
    textCursor.gotoStartOfParagraph(false)&lt;br /&gt;
&lt;br /&gt;
    while (true) {&lt;br /&gt;
        // Code blocks are runs of paragraphs whose style name ends with &amp;quot;Code&amp;quot;.&lt;br /&gt;
        while (!(textCursor.uno(XPropertySet)[&amp;#039;ParaStyleName&amp;#039;] =~ /.*Code$/)) {&lt;br /&gt;
//            println &amp;quot;Skipping ahead.&amp;quot;&lt;br /&gt;
            if (!textCursor.gotoNextParagraph(false)) {&lt;br /&gt;
                // Can&amp;#039;t find another paragraph, so we&amp;#039;re done.&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        XParagraphCursor codeRange = docText.createTextCursorByRange(textCursor).uno(XParagraphCursor)&lt;br /&gt;
&lt;br /&gt;
        def codeStyle = textCursor.uno(XPropertySet)[&amp;#039;ParaStyleName&amp;#039;]&lt;br /&gt;
&lt;br /&gt;
        // Move forward paragraphs until the end of the document,&lt;br /&gt;
        // or we find a paragraph that isn&amp;#039;t &amp;quot;GroovyCode&amp;quot; then move back one.&lt;br /&gt;
&lt;br /&gt;
        while (textCursor.gotoNextParagraph(false)) {&lt;br /&gt;
            if (textCursor.uno(XPropertySet)[&amp;#039;ParaStyleName&amp;#039;] != codeStyle) {&lt;br /&gt;
                if (!textCursor.gotoPreviousParagraph(false)) doError(&amp;quot;Couldn&amp;#039;t move back (end)!&amp;quot;);&lt;br /&gt;
                break;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        // The cursor is at the start of the paragraph, move it to the end.&lt;br /&gt;
        textCursor.gotoEndOfParagraph(false);&lt;br /&gt;
&lt;br /&gt;
        // Then select all that text as our code.&lt;br /&gt;
        codeRange.gotoRange(textCursor.end, true)&lt;br /&gt;
&lt;br /&gt;
        def codeString = codeRange.string&lt;br /&gt;
&lt;br /&gt;
//        println codeString&lt;br /&gt;
&lt;br /&gt;
        // the TextRange.getString() will have replaced paragraph end characters with &amp;#039;\n&amp;#039;,&lt;br /&gt;
        // which is the same as line breaks within a paragraph.  So we don&amp;#039;t really know&lt;br /&gt;
        // whether we have multiple paragraphs or not, but we don&amp;#039;t really care.&lt;br /&gt;
&lt;br /&gt;
        if (codeString.contains(&amp;#039;\n&amp;#039;)) {&lt;br /&gt;
//            println &amp;quot;Replacing some&amp;quot;&lt;br /&gt;
            // There are multiple lines, so we replace the paragraph(s) with a single&lt;br /&gt;
            // paragraph of multiple lines.&lt;br /&gt;
            codeRange.text.insertString(codeRange, codeString, true)&lt;br /&gt;
            // The paragraph style is unchanged so we don&amp;#039;t need to do anything about that.&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        if (!textCursor.gotoNextParagraph(false))&lt;br /&gt;
            return&lt;br /&gt;
    }&lt;br /&gt;
}  // def doMergeCode...&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * When saving as HTML, OpenOffice doesn&amp;#039;t take into consideration that all whitespace runs&lt;br /&gt;
 * will be collapsed into a single space (or line break).  That is disaster for most program&lt;br /&gt;
 * text (code and output) which typically depend on leading whitespace on lines to be preserved.&lt;br /&gt;
 * So what this method does is replace all leading whitespace on each line of a style that&lt;br /&gt;
 * looks like it is used for Wings (those whose nanes end with &amp;quot;Code&amp;quot;, &amp;quot;Result&amp;quot;, &amp;quot;Exception&amp;quot;,&lt;br /&gt;
 * &amp;quot;Output&amp;quot;, &amp;quot;Error&amp;quot;, or &amp;quot;Input&amp;quot;) and replace it with non-breaking spaces.&lt;br /&gt;
 */&lt;br /&gt;
def doFixFormatting(document) {&lt;br /&gt;
    def viewCursor = document.currentController.uno(XTextViewCursorSupplier).viewCursor&lt;br /&gt;
    // We get the XText from the cursor so that if it is from a frame or table it&amp;#039;ll work.&lt;br /&gt;
    def docText = viewCursor.text&lt;br /&gt;
    XParagraphCursor textCursor = docText.createTextCursorByRange(viewCursor).uno(XParagraphCursor)&lt;br /&gt;
&lt;br /&gt;
    // It&amp;#039;s a &amp;quot;paragraph&amp;quot; cursor, but may be positioned inside one.&lt;br /&gt;
    // We assume that since &amp;quot;GroovyCode&amp;quot; is supposed to be a &amp;quot;paragragh&amp;quot; style&lt;br /&gt;
    // that we&amp;#039;ll still be in &amp;quot;GroovyCode&amp;quot; when we go to the beginning.&lt;br /&gt;
&lt;br /&gt;
    textCursor.gotoStartOfParagraph(false)&lt;br /&gt;
&lt;br /&gt;
    while (true) {&lt;br /&gt;
        String codeStyle = textCursor.uno(XPropertySet)[&amp;#039;ParaStyleName&amp;#039;]&lt;br /&gt;
&lt;br /&gt;
        // Match style names of interest, if no match then it just falls thru.&lt;br /&gt;
        switch (codeStyle) {&lt;br /&gt;
            case ~/.*Code$/:&lt;br /&gt;
            case ~/.*Result$/:&lt;br /&gt;
            case ~/.*Exception$/:&lt;br /&gt;
            case ~/.*Output$/:&lt;br /&gt;
            case ~/.*Errors$/:&lt;br /&gt;
            case ~/.*Input$/:&lt;br /&gt;
&lt;br /&gt;
                XParagraphCursor codeRange = docText.createTextCursorByRange(textCursor).uno(XParagraphCursor)&lt;br /&gt;
&lt;br /&gt;
                // The cursor is at the start of the paragraph, move it to the end.&lt;br /&gt;
                textCursor.gotoEndOfParagraph(false);&lt;br /&gt;
&lt;br /&gt;
                // The select all that text as our code.&lt;br /&gt;
                codeRange.gotoRange(textCursor.end, true)&lt;br /&gt;
&lt;br /&gt;
                def codeString = codeRange.string&lt;br /&gt;
&lt;br /&gt;
//                println codeString&lt;br /&gt;
&lt;br /&gt;
                if (codeString.contains(&amp;#039; &amp;#039;) || codeString.contains(&amp;#039;\t&amp;#039;)) {&lt;br /&gt;
//                    println &amp;quot;Replacing some&amp;quot;&lt;br /&gt;
&lt;br /&gt;
                    String[] lines = codeString.split(&amp;#039;\n&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
                    lines.length.times {&lt;br /&gt;
                        String line = lines[it]&lt;br /&gt;
&lt;br /&gt;
                        // Treat tabs as eight spaces.&lt;br /&gt;
                        line = line.replace(&amp;#039;\t&amp;#039;, &amp;#039;        &amp;#039;)&lt;br /&gt;
&lt;br /&gt;
                        if (line.startsWith(&amp;#039; &amp;#039;)) {&lt;br /&gt;
                            char[] chars = line.toCharArray()&lt;br /&gt;
&lt;br /&gt;
                            for (int i = 0; i &amp;lt; chars.length; ++i) {&lt;br /&gt;
                                if (&amp;#039; &amp;#039; != chars[i]) break&lt;br /&gt;
                                chars[i] = &amp;#039;\u00A0&amp;#039;&lt;br /&gt;
                            }&lt;br /&gt;
&lt;br /&gt;
                            lines[it] = new String(chars)&lt;br /&gt;
                        }&lt;br /&gt;
                    }&lt;br /&gt;
&lt;br /&gt;
                    codeRange.text.insertString(codeRange, lines.join(&amp;#039;\n&amp;#039;), true)&lt;br /&gt;
                }&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
//        println &amp;quot;Skipping ahead.&amp;quot;&lt;br /&gt;
        if (!textCursor.gotoNextParagraph(false)) {&lt;br /&gt;
            return;&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
    }&lt;br /&gt;
}  // def doFixFormatting...&lt;br /&gt;
&lt;br /&gt;
////////////// BEGIN //////////////&lt;br /&gt;
// This is the XModel for the currently active document.&lt;br /&gt;
def document = XSCRIPTCONTEXT.document&lt;br /&gt;
&lt;br /&gt;
use(UnoCategory) {&lt;br /&gt;
    doMergeCode(document)&lt;br /&gt;
    doFixFormatting(document)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
0&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jimwhite</name></author>
	</entry>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=API/Samples/Groovy/Office/PropertySet&amp;diff=84405</id>
		<title>API/Samples/Groovy/Office/PropertySet</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=API/Samples/Groovy/Office/PropertySet&amp;diff=84405"/>
		<updated>2008-06-21T22:30:12Z</updated>

		<summary type="html">&lt;p&gt;Jimwhite: /* The UnoCategory API Helper */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;noinclude&amp;gt;[[Category:API]] [[Category:Samples]] [[Category:Groovy]] [[Category:Office]]&amp;lt;/noinclude&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==About the PropertySet Example==&lt;br /&gt;
This example shows how to access properties in a Groovy macro or extension using a category (aka &amp;quot;mixin&amp;quot;) UNO API helper.&lt;br /&gt;
&lt;br /&gt;
First let&amp;#039;s look what the code for this sample is in Java:&lt;br /&gt;
==The Java Code==&lt;br /&gt;
&amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
// Get the ActionEvent object from the ARGUMENTS list&lt;br /&gt;
ActionEvent event = (ActionEvent) ARGUMENTS[0];&lt;br /&gt;
&lt;br /&gt;
// Each argument is of type Any so we must use the AnyConverter class to&lt;br /&gt;
// convert it into the interface or primitive type we expect&lt;br /&gt;
XButton button = (XButton)AnyConverter.toObject(&lt;br /&gt;
    new Type(XButton.class), event.Source);&lt;br /&gt;
&lt;br /&gt;
// We can now query for the model of the button and get its properties&lt;br /&gt;
XControl control = (XControl)UnoRuntime.queryInterface(XControl.class, button);&lt;br /&gt;
XControlModel cmodel = control.getModel();&lt;br /&gt;
XPropertySet pset = (XPropertySet)UnoRuntime.queryInterface(&lt;br /&gt;
    XPropertySet.class, cmodel);&lt;br /&gt;
&lt;br /&gt;
if (pset.getPropertyValue(&amp;quot;Label&amp;quot;).equals(&amp;quot;Exit&amp;quot;))&lt;br /&gt;
{&lt;br /&gt;
    // We can get the XDialog in which this control appears by calling&lt;br /&gt;
    // getContext() on the XControl interface&lt;br /&gt;
    XDialog xDialog = (XDialog)UnoRuntime.queryInterface(&lt;br /&gt;
        XDialog.class, control.getContext());&lt;br /&gt;
    &lt;br /&gt;
    // Close the dialog&lt;br /&gt;
    xDialog.endExecute();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And now the Groovy way:&lt;br /&gt;
==The Groovy Code==&lt;br /&gt;
&amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
// Get the ActionEvent object from the ARGUMENTS list&lt;br /&gt;
ActionEvent event = (ActionEvent) ARGUMENTS[0];&lt;br /&gt;
&lt;br /&gt;
// Each argument is of type Any so we must use the AnyConverter class to&lt;br /&gt;
// convert it into the interface or primitive type we expect&lt;br /&gt;
XButton button = (XButton)AnyConverter.toObject(new Type(XButton), event.Source);&lt;br /&gt;
&lt;br /&gt;
// We can now query for the model of the button and get its properties&lt;br /&gt;
XControl control = button.uno(XControl)&lt;br /&gt;
XPropertySet pset = control.getModel().uno(XPropertySet)&lt;br /&gt;
&lt;br /&gt;
if (pset[&amp;quot;Label&amp;quot;].equals(&amp;quot;Exit&amp;quot;))&lt;br /&gt;
{&lt;br /&gt;
    // Close the dialog&lt;br /&gt;
    control.getContext().uno(XDialog).endExecute()&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or here&amp;#039;s any even shorter version that makes further use of Groovy&amp;#039;s dynamic typing:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
// Get the ActionEvent object from the ARGUMENTS list&lt;br /&gt;
def event = ARGUMENTS[0]&lt;br /&gt;
&lt;br /&gt;
// Each argument is of type Any so we must use the AnyConverter class to&lt;br /&gt;
// convert it into the interface or primitive type we expect&lt;br /&gt;
def button = AnyConverter.toObject(new Type(XButton), event.Source)&lt;br /&gt;
&lt;br /&gt;
// We can now query for the model of the button and get its properties&lt;br /&gt;
def control = button.uno(XControl)&lt;br /&gt;
def pset = control.model.uno(XPropertySet)&lt;br /&gt;
&lt;br /&gt;
if (pset[&amp;quot;Label&amp;quot;].equals(&amp;quot;Exit&amp;quot;))&lt;br /&gt;
{&lt;br /&gt;
    // Close the dialog&lt;br /&gt;
    control.context.uno(XDialog).endExecute()&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==The UnoCategory API Helper==&lt;br /&gt;
In order to let Groovy know how to make those adaptations for the UNO API, we use a [http://groovy.codehaus.org/Groovy+Categories Groovy Category].  For this sample that code looks like this:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
class UnoCategory {&lt;br /&gt;
    public static Object uno(Object unoObj, Class clazz) {UnoRuntime.queryInterface(clazz, unoObj)}&lt;br /&gt;
    public static Object getAt(XPropertySet pset, String pname) {pset.getPropertyValue(pname)}&lt;br /&gt;
    public static void putAt(XPropertySet pset, String pname, Object newValue) {pset.setPropertyValue(pname, newValue)}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jimwhite</name></author>
	</entry>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=API/Samples/Groovy/Office/PropertySet&amp;diff=84404</id>
		<title>API/Samples/Groovy/Office/PropertySet</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=API/Samples/Groovy/Office/PropertySet&amp;diff=84404"/>
		<updated>2008-06-21T22:26:24Z</updated>

		<summary type="html">&lt;p&gt;Jimwhite: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;noinclude&amp;gt;[[Category:API]] [[Category:Samples]] [[Category:Groovy]] [[Category:Office]]&amp;lt;/noinclude&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==About the PropertySet Example==&lt;br /&gt;
This example shows how to access properties in a Groovy macro or extension using a category (aka &amp;quot;mixin&amp;quot;) UNO API helper.&lt;br /&gt;
&lt;br /&gt;
First let&amp;#039;s look what the code for this sample is in Java:&lt;br /&gt;
==The Java Code==&lt;br /&gt;
&amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
// Get the ActionEvent object from the ARGUMENTS list&lt;br /&gt;
ActionEvent event = (ActionEvent) ARGUMENTS[0];&lt;br /&gt;
&lt;br /&gt;
// Each argument is of type Any so we must use the AnyConverter class to&lt;br /&gt;
// convert it into the interface or primitive type we expect&lt;br /&gt;
XButton button = (XButton)AnyConverter.toObject(&lt;br /&gt;
    new Type(XButton.class), event.Source);&lt;br /&gt;
&lt;br /&gt;
// We can now query for the model of the button and get its properties&lt;br /&gt;
XControl control = (XControl)UnoRuntime.queryInterface(XControl.class, button);&lt;br /&gt;
XControlModel cmodel = control.getModel();&lt;br /&gt;
XPropertySet pset = (XPropertySet)UnoRuntime.queryInterface(&lt;br /&gt;
    XPropertySet.class, cmodel);&lt;br /&gt;
&lt;br /&gt;
if (pset.getPropertyValue(&amp;quot;Label&amp;quot;).equals(&amp;quot;Exit&amp;quot;))&lt;br /&gt;
{&lt;br /&gt;
    // We can get the XDialog in which this control appears by calling&lt;br /&gt;
    // getContext() on the XControl interface&lt;br /&gt;
    XDialog xDialog = (XDialog)UnoRuntime.queryInterface(&lt;br /&gt;
        XDialog.class, control.getContext());&lt;br /&gt;
    &lt;br /&gt;
    // Close the dialog&lt;br /&gt;
    xDialog.endExecute();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And now the Groovy way:&lt;br /&gt;
==The Groovy Code==&lt;br /&gt;
&amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
// Get the ActionEvent object from the ARGUMENTS list&lt;br /&gt;
ActionEvent event = (ActionEvent) ARGUMENTS[0];&lt;br /&gt;
&lt;br /&gt;
// Each argument is of type Any so we must use the AnyConverter class to&lt;br /&gt;
// convert it into the interface or primitive type we expect&lt;br /&gt;
XButton button = (XButton)AnyConverter.toObject(new Type(XButton), event.Source);&lt;br /&gt;
&lt;br /&gt;
// We can now query for the model of the button and get its properties&lt;br /&gt;
XControl control = button.uno(XControl)&lt;br /&gt;
XPropertySet pset = control.getModel().uno(XPropertySet)&lt;br /&gt;
&lt;br /&gt;
if (pset[&amp;quot;Label&amp;quot;].equals(&amp;quot;Exit&amp;quot;))&lt;br /&gt;
{&lt;br /&gt;
    // Close the dialog&lt;br /&gt;
    control.getContext().uno(XDialog).endExecute()&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or here&amp;#039;s any even shorter version that makes further use of Groovy&amp;#039;s dynamic typing:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
// Get the ActionEvent object from the ARGUMENTS list&lt;br /&gt;
def event = ARGUMENTS[0]&lt;br /&gt;
&lt;br /&gt;
// Each argument is of type Any so we must use the AnyConverter class to&lt;br /&gt;
// convert it into the interface or primitive type we expect&lt;br /&gt;
def button = AnyConverter.toObject(new Type(XButton), event.Source)&lt;br /&gt;
&lt;br /&gt;
// We can now query for the model of the button and get its properties&lt;br /&gt;
def control = button.uno(XControl)&lt;br /&gt;
def pset = control.model.uno(XPropertySet)&lt;br /&gt;
&lt;br /&gt;
if (pset[&amp;quot;Label&amp;quot;].equals(&amp;quot;Exit&amp;quot;))&lt;br /&gt;
{&lt;br /&gt;
    // Close the dialog&lt;br /&gt;
    control.context.uno(XDialog).endExecute()&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==The UnoCategory API Helper==&lt;br /&gt;
In order to let Groovy know how to make those adaptations for the UNO API, we use a Groovy Category.  For this sample that code looks like this:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
class UnoCategory {&lt;br /&gt;
    public static Object uno(Object unoObj, Class clazz) {UnoRuntime.queryInterface(clazz, unoObj)}&lt;br /&gt;
    public static Object getAt(XPropertySet pset, String pname) {pset.getPropertyValue(pname)}&lt;br /&gt;
    public static void putAt(XPropertySet pset, String pname, Object newValue) {pset.setPropertyValue(pname, newValue)}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jimwhite</name></author>
	</entry>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=API/Samples/Groovy/Office/PropertySet&amp;diff=84403</id>
		<title>API/Samples/Groovy/Office/PropertySet</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=API/Samples/Groovy/Office/PropertySet&amp;diff=84403"/>
		<updated>2008-06-21T22:23:04Z</updated>

		<summary type="html">&lt;p&gt;Jimwhite: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;noinclude&amp;gt;[[Category:API]] [[Category:Samples]] [[Category:Groovy]] [[Category:Office]]&amp;lt;/noinclude&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==About the PropertySet Example==&lt;br /&gt;
This example shows how to access properties in a Groovy macro or extension using a category (aka &amp;quot;mixin&amp;quot;) UNO API helper.&lt;br /&gt;
&lt;br /&gt;
First let&amp;#039;s look what the code for this sample is in Java:&lt;br /&gt;
==The Java Code==&lt;br /&gt;
&amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
// Get the ActionEvent object from the ARGUMENTS list&lt;br /&gt;
ActionEvent event = (ActionEvent) ARGUMENTS[0];&lt;br /&gt;
&lt;br /&gt;
// Each argument is of type Any so we must use the AnyConverter class to&lt;br /&gt;
// convert it into the interface or primitive type we expect&lt;br /&gt;
XButton button = (XButton)AnyConverter.toObject(&lt;br /&gt;
    new Type(XButton.class), event.Source);&lt;br /&gt;
&lt;br /&gt;
// We can now query for the model of the button and get its properties&lt;br /&gt;
XControl control = (XControl)UnoRuntime.queryInterface(XControl.class, button);&lt;br /&gt;
XControlModel cmodel = control.getModel();&lt;br /&gt;
XPropertySet pset = (XPropertySet)UnoRuntime.queryInterface(&lt;br /&gt;
    XPropertySet.class, cmodel);&lt;br /&gt;
&lt;br /&gt;
if (pset.getPropertyValue(&amp;quot;Label&amp;quot;).equals(&amp;quot;Exit&amp;quot;))&lt;br /&gt;
{&lt;br /&gt;
    // We can get the XDialog in which this control appears by calling&lt;br /&gt;
    // getContext() on the XControl interface&lt;br /&gt;
    XDialog xDialog = (XDialog)UnoRuntime.queryInterface(&lt;br /&gt;
        XDialog.class, control.getContext());&lt;br /&gt;
    &lt;br /&gt;
    // Close the dialog&lt;br /&gt;
    xDialog.endExecute();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And now the Groovy way:&lt;br /&gt;
==The Groovy Code==&lt;br /&gt;
&amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
// Get the ActionEvent object from the ARGUMENTS list&lt;br /&gt;
ActionEvent event = (ActionEvent) ARGUMENTS[0];&lt;br /&gt;
&lt;br /&gt;
// Each argument is of type Any so we must use the AnyConverter class to&lt;br /&gt;
// convert it into the interface or primitive type we expect&lt;br /&gt;
XButton button = (XButton)AnyConverter.toObject(new Type(XButton), event.Source);&lt;br /&gt;
&lt;br /&gt;
// We can now query for the model of the button and get its properties&lt;br /&gt;
XControl control = button.uno(XControl)&lt;br /&gt;
XPropertySet pset = control.getModel().uno(XPropertySet)&lt;br /&gt;
&lt;br /&gt;
if (pset[&amp;quot;Label&amp;quot;].equals(&amp;quot;Exit&amp;quot;))&lt;br /&gt;
{&lt;br /&gt;
    // Close the dialog&lt;br /&gt;
    control.getContext().uno(XDialog).endExecute()&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or here&amp;#039;s any even shorter version that makes further use of Groovy&amp;#039;s dynamic typing:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
// Get the ActionEvent object from the ARGUMENTS list&lt;br /&gt;
def event = ARGUMENTS[0]&lt;br /&gt;
&lt;br /&gt;
// Each argument is of type Any so we must use the AnyConverter class to&lt;br /&gt;
// convert it into the interface or primitive type we expect&lt;br /&gt;
def button = AnyConverter.toObject(new Type(XButton), event.Source)&lt;br /&gt;
&lt;br /&gt;
// We can now query for the model of the button and get its properties&lt;br /&gt;
def control = button.uno(XControl)&lt;br /&gt;
def pset = control.model.uno(XPropertySet)&lt;br /&gt;
&lt;br /&gt;
if (pset[&amp;quot;Label&amp;quot;].equals(&amp;quot;Exit&amp;quot;))&lt;br /&gt;
{&lt;br /&gt;
    // Close the dialog&lt;br /&gt;
    control.context.uno(XDialog).endExecute()&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jimwhite</name></author>
	</entry>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=API/Samples/Groovy/Office/PropertySet&amp;diff=84402</id>
		<title>API/Samples/Groovy/Office/PropertySet</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=API/Samples/Groovy/Office/PropertySet&amp;diff=84402"/>
		<updated>2008-06-21T21:44:33Z</updated>

		<summary type="html">&lt;p&gt;Jimwhite: New page: &amp;lt;noinclude&amp;gt;Category:API Category:Samples Category:Groovy Category:Office&amp;lt;/noinclude&amp;gt;  ==About the PropertySet Example== This example shows how to access properties in a Gro...&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;noinclude&amp;gt;[[Category:API]] [[Category:Samples]] [[Category:Groovy]] [[Category:Office]]&amp;lt;/noinclude&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==About the PropertySet Example==&lt;br /&gt;
This example shows how to access properties in a Groovy macro or extension using a category (aka &amp;quot;mixin&amp;quot;) UNO API helper.&lt;br /&gt;
&lt;br /&gt;
==The Code==&lt;/div&gt;</summary>
		<author><name>Jimwhite</name></author>
	</entry>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=API/Samples/Groovy&amp;diff=84401</id>
		<title>API/Samples/Groovy</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=API/Samples/Groovy&amp;diff=84401"/>
		<updated>2008-06-21T21:40:23Z</updated>

		<summary type="html">&lt;p&gt;Jimwhite: New page: Under this section you can find examples showing different API use cases implemented in Groovy. &amp;lt;noinclude&amp;gt;Category:API Category:Samples&amp;lt;/noinclude&amp;gt; ==Office== &amp;lt;DPL&amp;gt; category=API c...&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Under this section you can find examples showing different API use cases implemented in Groovy.&lt;br /&gt;
&amp;lt;noinclude&amp;gt;[[Category:API]] [[Category:Samples]]&amp;lt;/noinclude&amp;gt;&lt;br /&gt;
==Office==&lt;br /&gt;
&amp;lt;DPL&amp;gt; category=API&lt;br /&gt;
category=Samples&lt;br /&gt;
category=Groovy&lt;br /&gt;
category=Office&amp;lt;/DPL&amp;gt;&lt;br /&gt;
==Writer==&lt;br /&gt;
&amp;lt;DPL&amp;gt; category=API&lt;br /&gt;
category=Samples&lt;br /&gt;
category=Groovy&lt;br /&gt;
category=Writer&amp;lt;/DPL&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jimwhite</name></author>
	</entry>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=API/Samples&amp;diff=84400</id>
		<title>API/Samples</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=API/Samples&amp;diff=84400"/>
		<updated>2008-06-21T21:37:31Z</updated>

		<summary type="html">&lt;p&gt;Jimwhite: /* Samples */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;UNO allows the usage of the OpenOffice.org API from different programming languages and it is often very useful to find some short examples showing different API use cases for different programming languages. Under this section in the wiki you can find examples of such API use case for the different supported programming languages.&lt;br /&gt;
&lt;br /&gt;
==Samples==&lt;br /&gt;
&lt;br /&gt;
* [[API/Samples/Java]]&lt;br /&gt;
* [[API/Samples/Cpp]]&lt;br /&gt;
* [[API/Samples/StarBasic]]&lt;br /&gt;
* [[API/Samples/Python]]&lt;br /&gt;
* [[API/Samples/Groovy]]&lt;br /&gt;
* [[API/Samples/Any_Language]]&lt;br /&gt;
&lt;br /&gt;
==Guideline==&lt;br /&gt;
This example section follows some rules that should be taken into account when somebody wants to contribute to these example collection. The examples for the different languages are collected dynamically and that is one reason why contributors should follow these rules.&lt;br /&gt;
&lt;br /&gt;
* select the right programming language and the appropriate sub category (e.g. Writer, Calc, ....)&lt;br /&gt;
* save your example in an hierarchical structure, e.g API/Samples/Java/Office/MyExample&lt;br /&gt;
* use always the category &amp;#039;&amp;#039;&amp;#039;API&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;Samples&amp;#039;&amp;#039;&amp;#039; and additionally the category for your language ad sub category. In the example above it is &amp;#039;&amp;#039;&amp;#039;Java&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;Office&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
The hierarchical structure can be extended on demand to group examples in a further category!&lt;br /&gt;
&lt;br /&gt;
[[Category:API]]&lt;br /&gt;
[[Category:Samples]]&lt;/div&gt;</summary>
		<author><name>Jimwhite</name></author>
	</entry>
</feed>