Intercepting Hyperlinks from Java

Java, C++, C#, Delphi... - Using the UNO bridges
Post Reply
bracho
Posts: 11
Joined: Sat Dec 13, 2008 3:23 am

Intercepting Hyperlinks from Java

Post by bracho »

Hi everyone.

I'm running OpenOffice Writer through a Java application and I'm desperately trying to intercept clicks on hyperlinks.

I refered to this topic in oooforum this topic in oooforum and managed to get interception on .uno commands (save, save as, etc.).

But I did not find how to intercept hyperlinks. Still wondering wether this could be done through a dispatch interceptor on the frame.

Anyone has an idea ?

Many thanks in advance.
OOo 3.3 on MS Windows XP
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Intercepting Hyperlinks from Java

Post by Villeroy »

In the SDK there used to be an example for a ProtocolHandler add-on. As far as I know, you need to implement a protocol handler for the http: protocol.
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
bracho
Posts: 11
Joined: Sat Dec 13, 2008 3:23 am

Re: Intercepting Hyperlinks from Java

Post by bracho »

Many thanks for your reply, Villeroy.

I'll keep digging in this direction and will let you know if it's a success...
OOo 3.3 on MS Windows XP
hanya
Volunteer
Posts: 885
Joined: Fri Nov 23, 2007 9:27 am
Location: Japan

Re: Intercepting Hyperlinks from Java

Post by hanya »

It seems to open hyperlink on documents does not pass through dispatch framework. I tried to make a protocol handler for http protocol but it does not used at the link opening. When I set a http item for one of menu item, it called.

But link to the file is opened by css.system.SystemShellExecute service. So I have tried to replace it with my one: http://extensions.services.openoffice.o ... ultBrowser
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
bracho
Posts: 11
Joined: Sat Dec 13, 2008 3:23 am

Re: Intercepting Hyperlinks from Java

Post by bracho »

Many thanks for your response, hanya.

I dezipped your extension and try to understand how you wrote it, but I'm discovering oxt format and python language...

By the way, one question, though : in your search, did you consider intercepting mouse clicks, trying then to determine if the pointer is on a hyperlink ?

I'm asking because I would have liked to intercept clicks on hyperlinks, even those which don't lead to opening a browser (for instance, leading to a file or to a bookmark.

Thanks once again for helping.
Last edited by bracho on Thu Feb 09, 2012 11:03 am, edited 1 time in total.
OOo 3.3 on MS Windows XP
hanya
Volunteer
Posts: 885
Joined: Fri Nov 23, 2007 9:27 am
Location: Japan

Re: Intercepting Hyperlinks from Java

Post by hanya »

By the way, one question, though : in your search, did you consider intercepting mouse clicks, tryning then to determine if the pointer is on a hyperlink ?
MouseHandler and accessibility api might be used this task.
Jump to bookmark is executed by .uno:JumpToMark and opening another file with link is done by .uno:Open command, it seems. So, keyword for this way is css.frame.XDispatchProviderInterception.
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
bracho
Posts: 11
Joined: Sat Dec 13, 2008 3:23 am

Re: Intercepting Hyperlinks from Java

Post by bracho »

Many thanks hanya.

I believe intercepting "jump to bookmark" will be just fine for my needs.

Unfortunately, I did not succeed in intercepting this command url. I'm actually trying to adapt this code :

Code: Select all

public class MyInterceptor implements XDispatchProviderInterceptor { 

   private XDispatchProvider slaveDispatchProvider; 
   private XDispatchProvider masterDispatchProvider; 
    
   public XDispatchProvider getMasterDispatchProvider() { 
      return masterDispatchProvider; 
   } 

   public XDispatchProvider getSlaveDispatchProvider() { 
      return slaveDispatchProvider; 
   } 

   public void setMasterDispatchProvider(XDispatchProvider arg0) { 
      masterDispatchProvider = arg0; 
       
   } 

   public void setSlaveDispatchProvider(XDispatchProvider arg0) { 
      slaveDispatchProvider = arg0; 
       
   } 
   /** 
    * intercepts the command URLs and dispatches to the user defined handlers. 
    */ 
   public XDispatch queryDispatch(URL arg0, String arg1, int arg2) { 
      // To intercept the .uno:Save 
      if(arg0.Complete.equals(".uno:Save")) { 
         // your command handler 
         return new MySave(); 
      } else if(arg0.Complete.equals(".uno:Paste")) { 
         // return your paste command handler 
      }    
      return getSlaveDispatchProvider().queryDispatch(arg0, arg1, arg2); // to get next command url. 
   } 

   public XDispatch[] queryDispatches(DispatchDescriptor[] arg0) { 
      return getSlaveDispatchProvider().queryDispatches(arg0); 
   } 
called from :

Code: Select all

XDispatchProviderInterception xDPI = (XDispatchProviderInterception) UnoRuntime.queryInterface(XDispatchProviderInterception.class, xFrame); 
MyInterceptor interceptor = new MyInterceptor(); 
xDPI.registerDispatchProviderInterceptor(interceptor);
But, doing so, I'm only able to intercept commands that are present in menus or toolbars.

Sorry to bother you with that, but could you give me a clue (or a piece of code) that would allow me to intercept the ".uno:JumpToBookmark" command ?

Many thanks once again !
OOo 3.3 on MS Windows XP
hanya
Volunteer
Posts: 885
Joined: Fri Nov 23, 2007 9:27 am
Location: Japan

Re: Intercepting Hyperlinks from Java

Post by hanya »

I am sorry for that I have not tried to capture JumpToBookmark call by clicking hyperlinks. It does not work on my environment also.
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
Post Reply