OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Using Xray from Beanshell

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Code Snippets
View previous topic :: View next topic  
Author Message
ms777
Super User
Super User


Joined: 07 Feb 2004
Posts: 1355

PostPosted: Thu Sep 01, 2005 1:47 am    Post subject: Using Xray from Beanshell Reply with quote

Recently I started to (try to) program some scripts in Beanshell. As an old Basic programmer, I immediately missed the great functionality of B Marcelly's Xray tool. The below Beanshell code shows, how to call Xray from a Beanshell script. Run this with an open writer document.

Code:
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;
import com.sun.star.frame.XDesktop;
import com.sun.star.frame.XModel;

import drafts.com.sun.star.script.provider.XScriptContext;

xCompCont = XSCRIPTCONTEXT.getComponentContext();
xMultiComponentFactory = xCompCont.getServiceManager();

//----------------------------- XRay-specific initializations and function definitions / start -----------

import com.sun.star.script.provider.XScriptProviderFactory;
import com.sun.star.script.provider.XScriptProvider;

Object oMSPFac =   xMultiComponentFactory.createInstanceWithContext(  "com.sun.star.script.provider.MasterScriptProviderFactory",  xCompCont);
xScriptProviderFactory = (XScriptProviderFactory)  UnoRuntime.queryInterface(XScriptProviderFactory.class, oMSPFac);

Object oMSP    = xScriptProviderFactory.createScriptProvider("");
xScriptProvider = (XScriptProvider)  UnoRuntime.queryInterface(XScriptProvider.class, oMSP);

oXrayScript = xScriptProvider.getScript("vnd.sun.star.script:Xray._Main.Xray?language=Basic&location=application");

public void XrayBSH(Object oXrayScript, Object oObj) {
Object ObjArrayIn = new Object[ 1 ];
ObjArrayIn[0] = oObj;
Object a;
Object b;
oXrayScript.invoke(ObjArrayIn, a, b);
  }

//----------------------------- XRay-specific initializations and function definitions / end   ---------
//----------------------------- now you can use the following command to XRay your Object oObj ---------
//----------------------------- XrayBSH(oXrayScript, oObj);


import com.sun.star.text.XTextDocument;
import com.sun.star.text.XText;
import com.sun.star.text.XTextRange;
import com.sun.star.text.XTextCursor;

oDoc = XSCRIPTCONTEXT.getDocument();
xTextDoc = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class,oDoc);
xText =  xTextDoc.getText();

xText.setString("");

xTextCursor = xText.createTextCursor();

xText.insertString(xTextCursor, "Some Text in the first line\n", false);
xText.insertString(xTextCursor, "Some Text in the second line\n", false);

XrayBSH(oXrayScript, xTextCursor);

return 0;
Back to top
View user's profile Send private message
B Marcelly
Super User
Super User


Joined: 12 May 2004
Posts: 1453
Location: France

PostPosted: Thu Sep 01, 2005 4:05 am    Post subject: Reply with quote

Quote:
The below Beanshell code shows, how to call Xray from a Beanshell script.

Fantastic code Very Happy I made it work without a hitch.
Perhaps it is possible to do the equivalent in Python or even C++ (look, SergeM!)
Exchanging objects between scripts opens up lots of possibilities. Thanks a lot Cool
______
Bernard
Back to top
View user's profile Send private message Visit poster's website
SergeM
Super User
Super User


Joined: 09 Sep 2003
Posts: 3211
Location: Troyes France

PostPosted: Thu Sep 01, 2005 5:39 am    Post subject: Reply with quote

I will have a look and translate this code in C++.
Thank you for this code.
_________________
Linux & Windows OOo3.0
UNO & C++ : WIKI
http://wiki.services.openoffice.org/wiki/Using_Cpp_with_the_OOo_SDK
In French
http://wiki.services.openoffice.org/wiki/Documentation/FR/Cpp_Guide
Back to top
View user's profile Send private message Visit poster's website
hol.sten
Super User
Super User


Joined: 14 Nov 2004
Posts: 3533
Location: Hamburg, Germany

PostPosted: Sat Mar 08, 2008 9:59 am    Post subject: Reply with quote

B Marcelly wrote:
Quote:
The below Beanshell code shows, how to call Xray from a Beanshell script.

Fantastic code Very Happy I made it work without a hitch.

I gave Xray my first try today. And the above posted code didn't work. I got it running with Xray 5.2, OOo 2.3.1 on Windows XP after I changed the line
Code:
oXrayScript = xScriptProvider.getScript("vnd.sun.star.script:Xray._Main.Xray?language=Basic&location=application");
to
Code:
oXrayScript = xScriptProvider.getScript("vnd.sun.star.script:XrayTool._Main.Xray?language=Basic&location=application");
.
Back to top
View user's profile Send private message
B Marcelly
Super User
Super User


Joined: 12 May 2004
Posts: 1453
Location: France

PostPosted: Sat Mar 08, 2008 11:18 am    Post subject: Reply with quote

hol.sten wrote:
I gave Xray my first try today. And the above posted code didn't work. I got it running with Xray 5.2, OOo 2.3.1 on Windows XP after I changed the line
Code:
oXrayScript = xScriptProvider.getScript("vnd.sun.star.script:Xray._Main.Xray?language=Basic&location=application");
to
Code:
oXrayScript = xScriptProvider.getScript("vnd.sun.star.script:XrayTool._Main.Xray?language=Basic&location=application");
.

FYI, read Xray documentation, chapter 4.2. There is a code to call Xray from Beanshell Wink
______
Bernard
Back to top
View user's profile Send private message Visit poster's website
hol.sten
Super User
Super User


Joined: 14 Nov 2004
Posts: 3533
Location: Hamburg, Germany

PostPosted: Sat Mar 08, 2008 11:30 am    Post subject: Reply with quote

B Marcelly wrote:
hol.sten wrote:
I gave Xray my first try today. And the above posted code didn't work. I got it running with Xray 5.2, OOo 2.3.1 on Windows XP after I changed the line
Code:
oXrayScript = xScriptProvider.getScript("vnd.sun.star.script:Xray._Main.Xray?language=Basic&location=application");
to
Code:
oXrayScript = xScriptProvider.getScript("vnd.sun.star.script:XrayTool._Main.Xray?language=Basic&location=application");
.

FYI, read Xray documentation, chapter 4.2. There is a code to call Xray from Beanshell Wink

Yes, I already found that. But I was puzzled why the example in chapter 4.2 workd for me, but the above didn't. Finally all I did was posting what I changed in the above code to get it working.
Back to top
View user's profile Send private message
B Marcelly
Super User
Super User


Joined: 12 May 2004
Posts: 1453
Location: France

PostPosted: Sat Mar 08, 2008 11:38 pm    Post subject: Reply with quote

Quote:
I was puzzled why the example in chapter 4.2 workd for me, but the above didn't.

ms777 was correct with version 4 of Xray.
The library name was changed from Xray to XrayTool with version 5 of Xray.
______
Bernard
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Code Snippets All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group