1 /* 2 * To change this template, choose Tools | Templates 3 * and open the template in the editor. 4 */ 5 6 /** 7 * 8 * @author zxf 9 */ 10 11 package complex.passwordcontainer; 12 13 import com.sun.star.lib.uno.helper.WeakBase; 14 import com.sun.star.task.XInteractionContinuation; 15 import com.sun.star.ucb.XInteractionSupplyAuthentication; 16 import com.sun.star.task.XInteractionRequest; 17 import com.sun.star.task.XInteractionHandler; 18 import com.sun.star.task.MasterPasswordRequest; 19 import com.sun.star.uno.UnoRuntime; 20 21 public class MasterPasswdHandler extends WeakBase 22 implements XInteractionHandler { 23 XInteractionHandler m_xHandler; 24 25 public MasterPasswdHandler( XInteractionHandler xHandler ) { 26 m_xHandler = xHandler; 27 } 28 29 public void handle( XInteractionRequest xRequest ) { 30 try { 31 MasterPasswordRequest aMasterPasswordRequest; 32 if( xRequest.getRequest() instanceof MasterPasswordRequest ) { 33 aMasterPasswordRequest = (MasterPasswordRequest)xRequest.getRequest(); 34 if( aMasterPasswordRequest != null ) { 35 XInteractionContinuation xContinuations[] = xRequest.getContinuations(); 36 XInteractionSupplyAuthentication xAuthentication = null; 37 38 for( int i = 0; i < xContinuations.length; ++i ) { 39 xAuthentication = UnoRuntime.queryInterface(XInteractionSupplyAuthentication.class, xContinuations[i]); 40 if( xAuthentication != null ) 41 { 42 break; 43 } 44 } 45 if( xAuthentication.canSetPassword() ) 46 { 47 xAuthentication.setPassword("abcdefghijklmnopqrstuvwxyz123456"); 48 } 49 xAuthentication.select(); 50 } 51 } else { 52 m_xHandler.handle( xRequest ); 53 } 54 } catch( Exception e ) { 55 System.out.println( "MasterPasswordHandler Error: " + e ); 56 } 57 } 58 } 59 60 61 62 63 64 65 66