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 #ifndef _DBAUI_INTERACTION_HXX_
25 #define _DBAUI_INTERACTION_HXX_
26 
27 #ifndef _CPPUHELPER_IMPLBASE2_HXX_
28 #include <cppuhelper/implbase2.hxx>
29 #endif
30 
31 #include "moduledbu.hxx"
32 #include "apitools.hxx"
33 
34 /** === begin UNO includes === **/
35 #include <com/sun/star/lang/XServiceInfo.hpp>
36 #include <com/sun/star/task/XInteractionHandler2.hpp>
37 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
38 #include <com/sun/star/ucb/AuthenticationRequest.hpp>
39 #include <com/sun/star/sdb/ParametersRequest.hpp>
40 #include <com/sun/star/sdb/DocumentSaveRequest.hpp>
41 /** === end UNO includes === **/
42 
43 namespace dbtools
44 {
45 	class SQLExceptionInfo;
46 }
47 
48 //.........................................................................
49 namespace dbaui
50 {
51 //.........................................................................
52 
53 	//=========================================================================
54 	//= BasicInteractionHandler
55 	//=========================================================================
56 	typedef ::cppu::WeakImplHelper2	<	::com::sun::star::lang::XServiceInfo
57 									,	::com::sun::star::task::XInteractionHandler2
58 									>	BasicInteractionHandler_Base;
59 	/** implements an <type scope="com.sun.star.task">XInteractionHandler</type> for
60 		database related interaction requests.
61 		<p/>
62 		Supported interaction requests by now (specified by an exception: The appropriate exception
63 		has to be returned by the getRequest method of the object implementing the
64 		<type scope="com.sun.star.task">XInteractionRequest</type> interface.
65 			<ul>
66 				<li><b><type scope="com.sun.star.sdbc">SQLException</type></b>: requests to display a
67 					standard error dialog for the (maybe chained) exception given</li>
68 			</ul>
69 	*/
70 	class BasicInteractionHandler
71 				:public BasicInteractionHandler_Base
72 	{
73 		const OModuleClient m_aModuleClient;
74 		const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >
75 				            m_xORB;
76         const bool          m_bFallbackToGeneric;
77 
78     public:
79 		BasicInteractionHandler(
80             const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& i_rORB,
81             const bool i_bFallbackToGeneric
82         );
83 
84         // XInteractionHandler2
85         virtual ::sal_Bool SAL_CALL handleInteractionRequest( const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionRequest >& Request ) throw (::com::sun::star::uno::RuntimeException);
86 
87 	    // XInteractionHandler
88 		virtual void SAL_CALL handle( const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionRequest >& Request ) throw(::com::sun::star::uno::RuntimeException);
89 
90 	protected:
91         sal_Bool
92                 impl_handle_throw( const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionRequest >& i_Request );
93 
94 		/// handle SQLExceptions (and derived classes)
95 		void	implHandle(
96 					const ::dbtools::SQLExceptionInfo& _rSqlInfo,
97 					const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionContinuation > >& _rContinuations);
98 
99 		/// handle parameter requests
100 		void	implHandle(
101 					const ::com::sun::star::sdb::ParametersRequest& _rParamRequest,
102 					const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionContinuation > >& _rContinuations);
103 
104 		/// handle document save requests
105 		void	implHandle(
106 					const ::com::sun::star::sdb::DocumentSaveRequest& _rParamRequest,
107 					const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionContinuation > >& _rContinuations);
108 
109         /// handles requests which are not SDB-specific
110         bool    implHandleUnknown(
111                     const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionRequest >& _rxRequest );
112 
113 		/// known continuation types
114 		enum Continuation
115 		{
116 			APPROVE,
117 			DISAPPROVE,
118 			RETRY,
119 			ABORT,
120 			SUPPLY_PARAMETERS,
121 			SUPPLY_DOCUMENTSAVE
122 		};
123 		/** check if a given continuation sequence contains a given continuation type<p/>
124 			@return		the index within <arg>_rContinuations</arg> of the first occurence of a continuation
125 						of the requested type, -1 of no such continuation exists
126 		*/
127 		sal_Int32 getContinuation(
128 			Continuation _eCont,
129 			const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionContinuation > >& _rContinuations);
130 	};
131 
132 	//=========================================================================
133 	//= SQLExceptionInteractionHandler
134 	//=========================================================================
135     class SQLExceptionInteractionHandler : public BasicInteractionHandler
136     {
137     public:
SQLExceptionInteractionHandler(const::com::sun::star::uno::Reference<::com::sun::star::lang::XMultiServiceFactory> & i_rORB)138         SQLExceptionInteractionHandler(
139                 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& i_rORB
140             )
141             :BasicInteractionHandler( i_rORB, false )
142         {
143         }
144 
145         // XServiceInfo
146 		DECLARE_SERVICE_INFO_STATIC();
147     };
148 
149 	//=========================================================================
150 	//= SQLExceptionInteractionHandler
151 	//=========================================================================
152     /** an implementation for the legacy css.sdb.InteractionHandler
153 
154         css.sdb.InteractionHandler is deprecated, as it does not only handle database related interactions,
155         but also delegates all kind of unknown requests to a css.task.InteractionHandler.
156 
157         In today's architecture, there's only one central css.task.InteractionHandler, which is to be used
158         for all requests. Depending on configuration information, it decides which handler implementation
159         to delegate a request to.
160 
161         SQLExceptionInteractionHandler is the delegatee which handles only database related interactions.
162         LegacyInteractionHandler is the version which first checks for a database related interaction, and
163         forwards everything else to the css.task.InteractionHandler.
164     */
165     class LegacyInteractionHandler : public BasicInteractionHandler
166     {
167     public:
LegacyInteractionHandler(const::com::sun::star::uno::Reference<::com::sun::star::lang::XMultiServiceFactory> & i_rORB)168         LegacyInteractionHandler(
169                 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& i_rORB
170             )
171             :BasicInteractionHandler( i_rORB, true )
172         {
173         }
174 
175         // XServiceInfo
176 		DECLARE_SERVICE_INFO_STATIC();
177     };
178 
179 //.........................................................................
180 }	// namespace dbaui
181 //.........................................................................
182 
183 #endif // _DBAUI_INTERACTION_HXX_
184 
185