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 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_ucb.hxx"
26 
27 #include "osl/mutex.hxx"
28 
29 #include "com/sun/star/lang/XTypeProvider.hpp"
30 #include "com/sun/star/task/DocumentPasswordRequest.hpp"
31 
32 #include "cppuhelper/typeprovider.hxx"
33 #include "ucbhelper/interactionrequest.hxx"
34 
35 #include "tdoc_passwordrequest.hxx"
36 
37 using namespace com::sun::star;
38 using namespace tdoc_ucp;
39 
40 namespace tdoc_ucp
41 {
42     class InteractionSupplyPassword :
43                       public ucbhelper::InteractionContinuation,
44                       public lang::XTypeProvider,
45                       public task::XInteractionPassword
46     {
47     public:
InteractionSupplyPassword(ucbhelper::InteractionRequest * pRequest)48         InteractionSupplyPassword( ucbhelper::InteractionRequest * pRequest )
49         : InteractionContinuation( pRequest ) {}
50 
51         // XInterface
52         virtual uno::Any SAL_CALL queryInterface( const uno::Type & rType )
53             throw ( uno::RuntimeException );
54         virtual void SAL_CALL acquire()
55             throw ();
56         virtual void SAL_CALL release()
57             throw ();
58 
59         // XTypeProvider
60         virtual uno::Sequence< uno::Type > SAL_CALL getTypes()
61             throw ( uno::RuntimeException );
62         virtual uno::Sequence< sal_Int8 > SAL_CALL getImplementationId()
63             throw ( uno::RuntimeException );
64 
65         // XInteractionContinuation
66         virtual void SAL_CALL select()
67             throw ( uno::RuntimeException );
68 
69         // XInteractionPassword
70         virtual void SAL_CALL setPassword( const rtl::OUString & aPasswd )
71             throw ( uno::RuntimeException );
72         virtual rtl::OUString SAL_CALL getPassword()
73             throw ( uno::RuntimeException );
74 
75     private:
76         osl::Mutex m_aMutex;
77         rtl::OUString m_aPassword;
78     };
79 } // namespace tdoc_ucp
80 
81 //=========================================================================
82 //=========================================================================
83 //
84 // InteractionSupplyPassword Implementation.
85 //
86 //=========================================================================
87 //=========================================================================
88 
89 //=========================================================================
90 //
91 // XInterface methods.
92 //
93 //=========================================================================
94 
95 // virtual
acquire()96 void SAL_CALL InteractionSupplyPassword::acquire()
97     throw()
98 {
99     OWeakObject::acquire();
100 }
101 
102 //=========================================================================
103 // virtual
release()104 void SAL_CALL InteractionSupplyPassword::release()
105     throw()
106 {
107     OWeakObject::release();
108 }
109 
110 //=========================================================================
111 // virtual
112 uno::Any SAL_CALL
queryInterface(const uno::Type & rType)113 InteractionSupplyPassword::queryInterface( const uno::Type & rType )
114     throw ( uno::RuntimeException )
115 {
116     uno::Any aRet = cppu::queryInterface( rType,
117                 static_cast< lang::XTypeProvider * >( this ),
118                 static_cast< task::XInteractionContinuation * >( this ),
119                 static_cast< task::XInteractionPassword * >( this ) );
120 
121     return aRet.hasValue()
122             ? aRet : InteractionContinuation::queryInterface( rType );
123 }
124 
125 //=========================================================================
126 //
127 // XTypeProvider methods.
128 //
129 //=========================================================================
130 
131 // virtual
132 uno::Sequence< sal_Int8 > SAL_CALL
getImplementationId()133 InteractionSupplyPassword::getImplementationId()
134     throw( uno::RuntimeException )
135 {
136     static cppu::OImplementationId * pId = 0;
137     if ( !pId )
138     {
139         osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
140         if ( !pId )
141         {
142             static cppu::OImplementationId id( sal_False );
143             pId = &id;
144         }
145     }
146     return (*pId).getImplementationId();
147 }
148 
149 //=========================================================================
150 // virtual
getTypes()151 uno::Sequence< uno::Type > SAL_CALL InteractionSupplyPassword::getTypes()
152     throw( uno::RuntimeException )
153 {
154     static cppu::OTypeCollection * pCollection = 0;
155     if ( !pCollection )
156     {
157         osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
158         if ( !pCollection )
159         {
160             static cppu::OTypeCollection collection(
161                 getCppuType( static_cast<
162                     uno::Reference< lang::XTypeProvider > * >( 0 ) ),
163                 getCppuType( static_cast<
164                     uno::Reference< task::XInteractionPassword > * >( 0 ) ) );
165             pCollection = &collection;
166         }
167     }
168     return (*pCollection).getTypes();
169 }
170 
171 //=========================================================================
172 //
173 // XInteractionContinuation methods.
174 //
175 //=========================================================================
176 
177 // virtual
select()178 void SAL_CALL InteractionSupplyPassword::select()
179     throw( uno::RuntimeException )
180 {
181     recordSelection();
182 }
183 
184 //=========================================================================
185 //
186 // XInteractionPassword methods.
187 //
188 //=========================================================================
189 
190 // virtual
191 void SAL_CALL
setPassword(const::rtl::OUString & aPasswd)192 InteractionSupplyPassword::setPassword( const ::rtl::OUString& aPasswd )
193     throw ( uno::RuntimeException )
194 {
195     osl::MutexGuard aGuard( m_aMutex );
196     m_aPassword = aPasswd;
197 }
198 
199 // virtual
getPassword()200 rtl::OUString SAL_CALL InteractionSupplyPassword::getPassword()
201     throw ( uno::RuntimeException )
202 {
203     osl::MutexGuard aGuard( m_aMutex );
204     return m_aPassword;
205 }
206 
207 //=========================================================================
208 //=========================================================================
209 //
210 // DocumentPasswordRequest Implementation.
211 //
212 //=========================================================================
213 //=========================================================================
214 
DocumentPasswordRequest(task::PasswordRequestMode eMode,const rtl::OUString & rDocumentName)215 DocumentPasswordRequest::DocumentPasswordRequest(
216     task::PasswordRequestMode eMode,
217     const rtl::OUString & rDocumentName )
218 {
219     // Fill request...
220     task::DocumentPasswordRequest aRequest;
221 //    aRequest.Message        = // OUString
222 //    aRequest.Context        = // XInterface
223     aRequest.Classification = task::InteractionClassification_ERROR;
224     aRequest.Mode           = eMode;
225     aRequest.Name           = rDocumentName;
226 
227     setRequest( uno::makeAny( aRequest ) );
228 
229     // Fill continuations...
230     uno::Sequence<
231         uno::Reference< task::XInteractionContinuation > > aContinuations( 3 );
232     aContinuations[ 0 ] = new ucbhelper::InteractionAbort( this );
233     aContinuations[ 1 ] = new ucbhelper::InteractionRetry( this );
234     aContinuations[ 2 ] = new InteractionSupplyPassword( this );
235 
236     setContinuations( aContinuations );
237 }
238 
239