1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 /* 23 * To change this template, choose Tools | Templates 24 * and open the template in the editor. 25 */ 26 27 /** 28 * 29 * @author zxf 30 */ 31 32 package complex.passwordcontainer; 33 34 import com.sun.star.lib.uno.helper.WeakBase; 35 import com.sun.star.task.XInteractionContinuation; 36 import com.sun.star.ucb.XInteractionSupplyAuthentication; 37 import com.sun.star.task.XInteractionRequest; 38 import com.sun.star.task.XInteractionHandler; 39 import com.sun.star.task.MasterPasswordRequest; 40 import com.sun.star.uno.UnoRuntime; 41 42 public class MasterPasswdHandler extends WeakBase 43 implements XInteractionHandler { 44 XInteractionHandler m_xHandler; 45 MasterPasswdHandler( XInteractionHandler xHandler )46 public MasterPasswdHandler( XInteractionHandler xHandler ) { 47 m_xHandler = xHandler; 48 } 49 handle( XInteractionRequest xRequest )50 public void handle( XInteractionRequest xRequest ) { 51 try { 52 MasterPasswordRequest aMasterPasswordRequest; 53 if( xRequest.getRequest() instanceof MasterPasswordRequest ) { 54 aMasterPasswordRequest = (MasterPasswordRequest)xRequest.getRequest(); 55 if( aMasterPasswordRequest != null ) { 56 XInteractionContinuation xContinuations[] = xRequest.getContinuations(); 57 XInteractionSupplyAuthentication xAuthentication = null; 58 59 for( int i = 0; i < xContinuations.length; ++i ) { 60 xAuthentication = UnoRuntime.queryInterface(XInteractionSupplyAuthentication.class, xContinuations[i]); 61 if( xAuthentication != null ) 62 { 63 break; 64 } 65 } 66 if( xAuthentication.canSetPassword() ) 67 { 68 xAuthentication.setPassword("abcdefghijklmnopqrstuvwxyz123456"); 69 } 70 xAuthentication.select(); 71 } 72 } else { 73 m_xHandler.handle( xRequest ); 74 } 75 } catch( Exception e ) { 76 System.out.println( "MasterPasswordHandler Error: " + e ); 77 } 78 } 79 } 80 81 82 83 84 85 86 87