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