Saturday, May 9, 2009

Uno, Symphony, and weird things happening

I totally like the idea of Symphony, being integrated in Notes, being free and all... I was excited to try out Uno and write my own Symphony exports in LotusScript - until I had to deal with some really weird effects, that costed me hours of researching (to give it some credit, there's not too much information out yet). At the end, I landed up deinstalling Symphony and installing OpenOffice (don't worry, just for this project ;-)). And, without *any* changes in the code, everything worked. Mh..

Here is an example (see code at the end of this post). If you want to try it yourself, just place a starWriter (odt)-file in c:/tmp/myfile.odt, that has the text <name> in it (with brackets).

What the code does, or is supposed to do, is open the odt, then search for the tag <name> and replace the text.

Works perfectly in OpenOffice; in Symphony, the document is opend and nothing else happens ..unless we put a "sleep" before "objDocument.replaceAll" (see commented code below) making the code wait a little (!); then, Symphony replaces the tag. Seems that Symphony is so fast, that it is too fast for itself ;-)

After a little research, I found out, that it might have something to with the frames. In the code below, I open the odt file in "_default". Opening it in "_blank" does everything it should. Another Mh..

Now, I don't know where the mistake is... maybe I'm just not understanding the differences between OpenOffice and Symphony. But already opening a file that I detached from a richtext item before, led to problems ("is already in use by another application"); something I have done a thousand times in MS Office. I will definitly keep playing with Symphony and Uno, but, let's say, right now I'm not *as* enthusiastic anymore as I was before. Hope that will change again.

If you are looking for a cool step-by-step introduction into Uno, here's everything you need: John Head's blog posts on UNO

And here is the LotusScript code:

%REM
Testing uno: symphony vs. open office
To use this agent, you must have a file c:/tmp/myfile.odt on your hd, that contains the text ""
Agent will try to replace the "" tag
%END REM

' initialize service manager and desktop

Dim objServiceManager As Variant
Set objServiceManager = CreateObject ("com.sun.star.ServiceManager")

Dim objDesktop As Variant
Set objDesktop = objServiceManager.createInstance ("com.sun.star.frame.Desktop")

' open file

' not as template
Dim args1 As Variant
Set args1= objServiceManager.Bridge_GetStruct ("com.sun.star.beans.PropertyValue")
args1.Name = "AsTemplate"
args1.Value = False

' show us what's happening
Dim args2 As Variant
Set args2= objServiceManager.Bridge_GetStruct ("com.sun.star.beans.PropertyValue")
args2.Name = "Hidden"
args2.Value = False

Dim args(1) As Variant
Set args(0)=args1
Set args(1) = args2

Dim sUrl As String
sUrl = "file:///c:/tmp/myfile.odt" ' this is where the file is located

' open document in "_default" (with "_blank" it works in both oo and symphony)
Dim objDocument As Variant
Set objDocument = objDesktop.loadComponentFromURL(sUrl, "_default", 0, args)

' now try to replace the tag

Dim vInterface As Variant
Set vInterface = objDocument.createReplaceDescriptor()
vInterface.searchstring = "<name>" ' search for this
vInterface.replacestring = "Marcus Foerster" ' replace it with this
vInterface.searchwords = True
vInterface.searchcasesensitive = False

' in symphony, we need a sleep here now, otherwise it won't replace anything
' sleep 1

' now replace it
Dim vNumbers As Variant
vNumbers = objDocument.replaceAll(vInterface)

End Sub

0 Comments:

Post a Comment

Thank you for your comment. It will be published shortly. Keep having a great day!

<< Home