On 08.11.2012 03:26, Andrew Douglas Pitonyak wrote:
>
> On 11/07/2012 05:40 PM, Rony G. Flatscher (Apache) wrote:
>> If there is interest, I could also post that nutshell example here.
> Please post the example :-)
O.K., it is at the end of this e-mail. Correction: the kudos for finding it 
goes to Christoph *Jopp*
still from Munich and a great AOO hacker! :)
>
> Wish I was there!
Yes, that would have been nice to meet in person!

---

The following was created yesterday and added to todays presentation "Scripting 
Apache OpenOffice",
which should be uploaded by ASF (no URL yet).

The programming language is ooRexx (http://www.ooRexx.org) which is powerful 
yet its syntax is very
easy and looks like pseudo code. It has a proper message operator (tilde: ~), 
left of it is the
receiving object right of it is the message name (sometimes with arguments in 
round parenthesis).

The logic needed can be found in the routine addItem(), dumpItem() demonstrates 
how to iterate over
an impress XText and learn the outline level in addition:

    xDesktop=uno.createDesktop()        -- bootstrap & get access to XDesktop
    xcl=xDesktop~XComponentLoader       -- get XComponentLoader interface

    uri="private:factory/simpress"      -- new simpress document
    doc=xcl~loadComponentFromURL(uri,"_blank",0,.uno~noProps)

    xDrawPages = doc~XDrawPagesSupplier~getDrawPages   -- get DrawPages

    xDrawPage=xDrawPages~getByIndex(0)  -- get first (empty) page
    xDrawPage~XPropertySet~setPropertyValue("Layout", box("short",0))  -- 
"Title Slide"
    xShapes=xDrawPage~XShapes           -- get access to its shapes
    xShapes~getByIndex(0)~XText~setString("ApacheCon Europe 2012")
    xShapes~getByIndex(1)~XText~setString("Scripting Apache OpenOffice")

    xDrawPage=xDrawPages~~insertNewByIndex(1)~getByIndex(1) -- insert at end, 
get access
    xDrawPage~XPropertySet~setPropertyValue("Layout", box("short",1))  -- 
"Title Content"
    xShapes=xDrawPage~XShapes           -- get access to its shapes
    xShapes~getByIndex(0)~XText~setString("Scripting Apache OpenOffice")

    xText=xShapes~getByIndex(1)~XText   -- content's XText
    call addItem xText, "First",            0  -- add string, determine level
    call addItem xText, "Explored by many", 0
    call addItem xText, "Kudos! go to",     1
    call addItem xText, "Christoph Jopp!",  1
    call addItem xText, "On 2012-11-07",    0, .false

    doc~XModifiable~setModified(.false)
    doc~XPresentationSupplier~getPresentation~~bsf.dispatch("start")  -- start 
presentation

    say "now dumping infos about second page's content XText:"
    call dumpItems xText

    ::requires UNO.CLS                  -- get UNO support

    ::routine addItem                   -- adds string at the given (0-based 
outline) level
      use arg xText, string, level, bNewParagraph=.true

      xTR=xText~XTextRange~getEnd       -- get end, a XTextRange
      xTR~XPropertySet~setPropertyValue("NumberingLevel",level) -- set 
XTextRange level

      xTR~setString(string)             -- set string

      if bNewParagraph=.true then       -- add new paragraph
         xTR~getEnd~setString("0a"x)    -- add linefeed character -> new 
paragraph


    ::routine dumpItems                 -- show level and string from XText
      use arg xText

      enum=xText~XEnumerationAccess~createEnumeration -- enumerate paragraphs
      do i=1 while enum~hasMoreElements
        xtr=enum~nextElement~XTextRange -- we need XTextRange's string & 
properties             
        nl=xtr~XPropertySet~getPropertyValue("NumberingLevel")
        say "     item #" i": NumberingLevel="pp(nl) pp(xtr~getString) 
      end

Should anyone have questions, please come forward!

---rony

Reply via email to