I've been trying to implement a dispatch interceptor for commands in my java component without success. I've been checking different examples on the list and the developers guide but couldn't get any of those to work properly. I don't really know how to connect the interceptor to the actual writer component. As I understand it the Frame has to be connected with the XDispatchProviderInterceptor, which is implemented in my Interceptor class. But how am I connecting this class with the frame?

This is my Interceptor class, which I'd like to start up from another class where I do create a new writer document.


INTERCEPTOR.JAVA
---------------------------------------------------------------------------------
public class Interceptor implements com.sun.star.frame.XFrameActionListener,
       com.sun.star.frame.XDispatchProviderInterceptor,
       com.sun.star.frame.XDispatchProvider, com.sun.star.frame.XDispatch,
       com.sun.star.frame.XInterceptorInfo {
   /**
    * const All these URL's are intercepted by this implementation.
    */
private static final String[] INTERCEPT_URLS_SLOTDBG = { "slot:*", ".uno:*" };

   /**
    * @member m_xMaster use this interceptor if he doesn't handle queried
    *         dispatch request
    * @member m_xSlave we can forward all unhandled requests to this slave
    *         interceptor
    */
   private com.sun.star.frame.XDispatchProvider m_xMaster;

   private com.sun.star.frame.XDispatchProvider m_xSlave;

   /**
    * Indicates, that the Interceptor has been called, and the test worked.
    */
   private boolean mbInterceptorCalled = false;

   private XFrame m_xFrame;

   /**
    * ctor
    */
   public Interceptor(/*IN*/ com.sun.star.frame.XFrame xFrame) {
       m_xFrame = xFrame ;
       m_xSlave = null;
       m_xMaster = null;
   }

   public void startListening() {
       com.sun.star.frame.XFrame xFrame = null;
       synchronized(this)
       {
           xFrame = m_xFrame;
       }
       m_xFrame.addFrameActionListener(this);
   }

   public void execOneway(/* IN */int nRequest,/* IN */Vector lParams) {
   }

   public/* ONEWAY */void frameAction(
           /* IN */com.sun.star.frame.FrameActionEvent aEvent) {
   }

public/* ONEWAY */void dispatch(/* IN */com.sun.star.util.URL aURL,/* IN */
           com.sun.star.beans.PropertyValue[] lArguments) {
       System.out.println("DISPATCHED URL: " + aURL.Complete);
   }

   public com.sun.star.frame.XDispatchProvider getSlaveDispatchProvider() {
       synchronized (this) {
           return m_xSlave;
       }
   }

   public void setSlaveDispatchProvider(
           com.sun.star.frame.XDispatchProvider xSlave) {
       synchronized (this) {
           m_xSlave = xSlave;
       }
   }

public com.sun.star.frame.XDispatchProvider getMasterDispatchProvider() {
       synchronized (this) {
           return m_xMaster;
       }
   }

   public void setMasterDispatchProvider(
           com.sun.star.frame.XDispatchProvider xMaster) {
       synchronized (this) {
           m_xMaster = xMaster;
       }
   }

   public com.sun.star.frame.XDispatch queryDispatch(
/* IN */com.sun.star.util.URL aURL,/* IN */String sTarget,/* IN */
           int nSearchFlags) {
       // output for 'known' URLs
       if (aURL.Complete.startsWith("slot:")
               || aURL.Complete.startsWith(".uno:PrintPreview")
               || aURL.Complete.startsWith(".uno:InsertAuthoritiesEntry")
               || aURL.Complete.startsWith(".uno:FrameDialog")
               || aURL.Complete.startsWith(".uno:InsertTable")) {
new MsgBox(new Frame(""), "IT WORKS", false); System.out.println("***** url complete: " + aURL.Complete
                   + "... works!");
           mbInterceptorCalled = true;
           return this;
       } else {
           System.out.println(" ... ignored");
       }
       // give unknown URLs to slave
       synchronized (this) {
           if (m_xSlave != null) {
               return m_xSlave.queryDispatch(aURL, sTarget, nSearchFlags);
           }
       }
       return null;
   }

   public com.sun.star.frame.XDispatch[] queryDispatches(
           /* IN */com.sun.star.frame.DispatchDescriptor[] lDescriptor) {
       // Resolve any request seperatly by using own "dispatch()" method.
       // Note: Don't pack return list if "null" objects occure!
       int nCount = lDescriptor.length;
com.sun.star.frame.XDispatch[] lDispatcher = new com.sun.star.frame.XDispatch[nCount];
       for (int i = 0; i < nCount; ++i) {
           lDispatcher[i] = queryDispatch(lDescriptor[i].FeatureURL,
                   lDescriptor[i].FrameName, lDescriptor[i].SearchFlags);
       }
       return lDispatcher;
   }

   public/* ONEWAY */void addStatusListener(
           /* IN */com.sun.star.frame.XStatusListener xListener,/* IN */
           com.sun.star.util.URL aURL) {
   }

   // ____________________

   public/* ONEWAY */void removeStatusListener(
           /* IN */com.sun.star.frame.XStatusListener xListener,/* IN */
           com.sun.star.util.URL aURL) {
   }

   public String[] getInterceptedURLs() {
       return INTERCEPT_URLS_SLOTDBG;
   }

public/* ONEAY */void disposing(/* IN */com.sun.star.lang.EventObject aSource) {
   }

   public boolean isInterceptorCalled() {
       synchronized (this) {
           return mbInterceptorCalled;
       }
   }
}

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to