[Solved] [Java] Get current XTextDocument object reference

Discussions about using 3rd party extension with OpenOffice.org
Post Reply
java1cprog
Posts: 6
Joined: Wed Sep 01, 2010 6:54 pm

[Solved] [Java] Get current XTextDocument object reference

Post by java1cprog »

I would like to see a simple code example which show me how to get com.sun.star.text.XTextDocument in dispatch method of OpenOffice.org AddOn.
Last edited by java1cprog on Tue Sep 07, 2010 10:45 am, edited 9 times in total.
OpenOffice 3.2 on Windows XP SP 2
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: How to get current XTextDocument object reference?

Post by Villeroy »

You should find the answer in any code example, in virtually every little piece of documentation.
The MRI extension can even record Java code.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
java1cprog
Posts: 6
Joined: Wed Sep 01, 2010 6:54 pm

Re: How to get current XTextDocument object reference?

Post by java1cprog »

Just show me a code. I think it will be few lines of code. Please.
OpenOffice 3.2 on Windows XP SP 2
User avatar
RoryOF
Moderator
Posts: 34586
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: How to get current XTextDocument object reference with J

Post by RoryOF »

Search for xtextdocument using search box top right of forum screen. Then if you have a query, come back and someone will help.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
hanya
Volunteer
Posts: 885
Joined: Fri Nov 23, 2007 9:27 am
Location: Japan

Re: How to get current XTextDocument object reference with J

Post by hanya »

If you implement your own protocol handler, see:
http://api.openoffice.org/docs/common/r ... ndler.html
Please, edit this thread's initial post and add "[Solved]" to the subject line if your problem has been solved.
Apache OpenOffice 4-dev on Xubuntu 14.04
java1cprog
Posts: 6
Joined: Wed Sep 01, 2010 6:54 pm

Re: How to get current XTextDocument object reference with J

Post by java1cprog »

Villeroy wrote:You should find the answer in any code example, in virtually every little piece of documentation.
The MRI extension can even record Java code.
Unfotunatelly, I didn't find any. I saw a lot of examples where new frame is created. It isn't what I want. I would like to get current XTextDocument. I would not like to get new empty XTextDocument. Do you understand me?

One of possible ways is:

Code: Select all

       ...
       //retrieve the current component
       XComponent xCurrentComponent = xdesktop.getCurrentComponent();
    
      // query its XTextDocument interface
        XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(
                XTextDocument.class, xCurrentComponent);
But when it test this one in my own protocol handler xCurrentComponent is null. This code don't satisfy a need of my target.

How can I do that? I don't understand? Please, don't post links here.
Please, type or copy/paste a working example.
OpenOffice 3.2 on Windows XP SP 2
java1cprog
Posts: 6
Joined: Wed Sep 01, 2010 6:54 pm

Re: [Java] Get current XTextDocument object reference

Post by java1cprog »

Unfortunately, I didn't find answer to my question into present forum's topics. Instead, I carefully read "OpenOffice.org Developer guide" and found answer to my question.
The few strings of code which I have developed by myself is here:

Code: Select all

                XTextDocument textDocument = null;
                XController controller = m_xContext.getController();
                XModel model = controller.getModel();
                textDocument = UnoRuntime.queryInterface(XTextDocument.class, model);
OpenOffice 3.2 on Windows XP SP 2
Giehlman
Posts: 1
Joined: Mon Jun 20, 2016 5:05 pm

Re: [Java] Get current XTextDocument object reference

Post by Giehlman »

Thanks @java1cprog, I was able to make it work. Found a little error in your code though, cf. https://www.openoffice.org/api/docs/com ... Frame.html
java1cprog wrote:Unfortunately, I didn't find answer to my question into present forum's topics. Instead, I carefully read "OpenOffice.org Developer guide" and found answer to my question.
The few strings of code which I have developed by myself is here:

Code: Select all

                XTextDocument textDocument = null;
                XController controller = /* m_xContext.getController(); has to be XFrame --> */ m_xFrame.getController(); 
                XModel model = controller.getModel();
                textDocument = UnoRuntime.queryInterface(XTextDocument.class, model);
OpenOffice 4.0 on Windows 10
Post Reply