1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_ucb.hxx" 30 31 #include "osl/mutex.hxx" 32 33 #include "com/sun/star/lang/XTypeProvider.hpp" 34 #include "com/sun/star/task/DocumentPasswordRequest.hpp" 35 36 #include "cppuhelper/typeprovider.hxx" 37 #include "ucbhelper/interactionrequest.hxx" 38 39 #include "tdoc_passwordrequest.hxx" 40 41 using namespace com::sun::star; 42 using namespace tdoc_ucp; 43 44 namespace tdoc_ucp 45 { 46 class InteractionSupplyPassword : 47 public ucbhelper::InteractionContinuation, 48 public lang::XTypeProvider, 49 public task::XInteractionPassword 50 { 51 public: 52 InteractionSupplyPassword( ucbhelper::InteractionRequest * pRequest ) 53 : InteractionContinuation( pRequest ) {} 54 55 // XInterface 56 virtual uno::Any SAL_CALL queryInterface( const uno::Type & rType ) 57 throw ( uno::RuntimeException ); 58 virtual void SAL_CALL acquire() 59 throw (); 60 virtual void SAL_CALL release() 61 throw (); 62 63 // XTypeProvider 64 virtual uno::Sequence< uno::Type > SAL_CALL getTypes() 65 throw ( uno::RuntimeException ); 66 virtual uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() 67 throw ( uno::RuntimeException ); 68 69 // XInteractionContinuation 70 virtual void SAL_CALL select() 71 throw ( uno::RuntimeException ); 72 73 // XInteractionPassword 74 virtual void SAL_CALL setPassword( const rtl::OUString & aPasswd ) 75 throw ( uno::RuntimeException ); 76 virtual rtl::OUString SAL_CALL getPassword() 77 throw ( uno::RuntimeException ); 78 79 private: 80 osl::Mutex m_aMutex; 81 rtl::OUString m_aPassword; 82 }; 83 } // namespace tdoc_ucp 84 85 //========================================================================= 86 //========================================================================= 87 // 88 // InteractionSupplyPassword Implementation. 89 // 90 //========================================================================= 91 //========================================================================= 92 93 //========================================================================= 94 // 95 // XInterface methods. 96 // 97 //========================================================================= 98 99 // virtual 100 void SAL_CALL InteractionSupplyPassword::acquire() 101 throw() 102 { 103 OWeakObject::acquire(); 104 } 105 106 //========================================================================= 107 // virtual 108 void SAL_CALL InteractionSupplyPassword::release() 109 throw() 110 { 111 OWeakObject::release(); 112 } 113 114 //========================================================================= 115 // virtual 116 uno::Any SAL_CALL 117 InteractionSupplyPassword::queryInterface( const uno::Type & rType ) 118 throw ( uno::RuntimeException ) 119 { 120 uno::Any aRet = cppu::queryInterface( rType, 121 static_cast< lang::XTypeProvider * >( this ), 122 static_cast< task::XInteractionContinuation * >( this ), 123 static_cast< task::XInteractionPassword * >( this ) ); 124 125 return aRet.hasValue() 126 ? aRet : InteractionContinuation::queryInterface( rType ); 127 } 128 129 //========================================================================= 130 // 131 // XTypeProvider methods. 132 // 133 //========================================================================= 134 135 // virtual 136 uno::Sequence< sal_Int8 > SAL_CALL 137 InteractionSupplyPassword::getImplementationId() 138 throw( uno::RuntimeException ) 139 { 140 static cppu::OImplementationId * pId = 0; 141 if ( !pId ) 142 { 143 osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() ); 144 if ( !pId ) 145 { 146 static cppu::OImplementationId id( sal_False ); 147 pId = &id; 148 } 149 } 150 return (*pId).getImplementationId(); 151 } 152 153 //========================================================================= 154 // virtual 155 uno::Sequence< uno::Type > SAL_CALL InteractionSupplyPassword::getTypes() 156 throw( uno::RuntimeException ) 157 { 158 static cppu::OTypeCollection * pCollection = 0; 159 if ( !pCollection ) 160 { 161 osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() ); 162 if ( !pCollection ) 163 { 164 static cppu::OTypeCollection collection( 165 getCppuType( static_cast< 166 uno::Reference< lang::XTypeProvider > * >( 0 ) ), 167 getCppuType( static_cast< 168 uno::Reference< task::XInteractionPassword > * >( 0 ) ) ); 169 pCollection = &collection; 170 } 171 } 172 return (*pCollection).getTypes(); 173 } 174 175 //========================================================================= 176 // 177 // XInteractionContinuation methods. 178 // 179 //========================================================================= 180 181 // virtual 182 void SAL_CALL InteractionSupplyPassword::select() 183 throw( uno::RuntimeException ) 184 { 185 recordSelection(); 186 } 187 188 //========================================================================= 189 // 190 // XInteractionPassword methods. 191 // 192 //========================================================================= 193 194 // virtual 195 void SAL_CALL 196 InteractionSupplyPassword::setPassword( const ::rtl::OUString& aPasswd ) 197 throw ( uno::RuntimeException ) 198 { 199 osl::MutexGuard aGuard( m_aMutex ); 200 m_aPassword = aPasswd; 201 } 202 203 // virtual 204 rtl::OUString SAL_CALL InteractionSupplyPassword::getPassword() 205 throw ( uno::RuntimeException ) 206 { 207 osl::MutexGuard aGuard( m_aMutex ); 208 return m_aPassword; 209 } 210 211 //========================================================================= 212 //========================================================================= 213 // 214 // DocumentPasswordRequest Implementation. 215 // 216 //========================================================================= 217 //========================================================================= 218 219 DocumentPasswordRequest::DocumentPasswordRequest( 220 task::PasswordRequestMode eMode, 221 const rtl::OUString & rDocumentName ) 222 { 223 // Fill request... 224 task::DocumentPasswordRequest aRequest; 225 // aRequest.Message = // OUString 226 // aRequest.Context = // XInterface 227 aRequest.Classification = task::InteractionClassification_ERROR; 228 aRequest.Mode = eMode; 229 aRequest.Name = rDocumentName; 230 231 setRequest( uno::makeAny( aRequest ) ); 232 233 // Fill continuations... 234 uno::Sequence< 235 uno::Reference< task::XInteractionContinuation > > aContinuations( 3 ); 236 aContinuations[ 0 ] = new ucbhelper::InteractionAbort( this ); 237 aContinuations[ 1 ] = new ucbhelper::InteractionRetry( this ); 238 aContinuations[ 2 ] = new InteractionSupplyPassword( this ); 239 240 setContinuations( aContinuations ); 241 } 242 243