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 #include "iahndl.hxx"
25 #include "interactionhandler.hxx"
26 
27 using namespace com::sun::star;
28 
UUIInteractionHandler(uno::Reference<lang::XMultiServiceFactory> const & rServiceFactory)29 UUIInteractionHandler::UUIInteractionHandler(
30     uno::Reference< lang::XMultiServiceFactory > const &
31         rServiceFactory)
32     SAL_THROW(())
33         : m_xServiceFactory(rServiceFactory),
34           m_pImpl(new UUIInteractionHelper(m_xServiceFactory))
35 {
36 }
37 
~UUIInteractionHandler()38 UUIInteractionHandler::~UUIInteractionHandler()
39 {
40     delete m_pImpl;
41 }
42 
getImplementationName()43 rtl::OUString SAL_CALL UUIInteractionHandler::getImplementationName()
44     throw (uno::RuntimeException)
45 {
46     return rtl::OUString::createFromAscii(m_aImplementationName);
47 }
48 
49 sal_Bool SAL_CALL
supportsService(rtl::OUString const & rServiceName)50 UUIInteractionHandler::supportsService(rtl::OUString const & rServiceName)
51     throw (uno::RuntimeException)
52 {
53     uno::Sequence< rtl::OUString >
54 	aNames(getSupportedServiceNames_static());
55     for (sal_Int32 i = 0; i < aNames.getLength(); ++i)
56         if (aNames[i] == rServiceName)
57             return true;
58     return false;
59 }
60 
61 uno::Sequence< rtl::OUString > SAL_CALL
getSupportedServiceNames()62 UUIInteractionHandler::getSupportedServiceNames()
63     throw (uno::RuntimeException)
64 {
65     return getSupportedServiceNames_static();
66 }
67 
68 void SAL_CALL
initialize(uno::Sequence<uno::Any> const & rArguments)69 UUIInteractionHandler::initialize(
70     uno::Sequence< uno::Any > const & rArguments)
71     throw (uno::Exception)
72 {
73     delete m_pImpl;
74     m_pImpl = new UUIInteractionHelper(m_xServiceFactory, rArguments);
75 }
76 
77 void SAL_CALL
handle(uno::Reference<task::XInteractionRequest> const & rRequest)78 UUIInteractionHandler::handle(
79     uno::Reference< task::XInteractionRequest > const & rRequest)
80     throw (uno::RuntimeException)
81 {
82     try
83     {
84         m_pImpl->handleRequest(rRequest);
85     }
86     catch (uno::RuntimeException const & ex)
87     {
88         throw uno::RuntimeException(ex.Message, *this);
89     }
90 }
91 
handleInteractionRequest(const uno::Reference<task::XInteractionRequest> & _Request)92 ::sal_Bool SAL_CALL UUIInteractionHandler::handleInteractionRequest(
93     const uno::Reference< task::XInteractionRequest >& _Request ) throw ( uno::RuntimeException )
94 {
95     try
96     {
97         return m_pImpl->handleRequest( _Request );
98     }
99     catch (uno::RuntimeException const & ex)
100     {
101         throw uno::RuntimeException( ex.Message, *this );
102     }
103     return sal_False;
104 }
105 
106 char const UUIInteractionHandler::m_aImplementationName[]
107     = "com.sun.star.comp.uui.UUIInteractionHandler";
108 
109 uno::Sequence< rtl::OUString >
getSupportedServiceNames_static()110 UUIInteractionHandler::getSupportedServiceNames_static()
111 {
112     uno::Sequence< rtl::OUString > aNames(3);
113     aNames[0] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
114                     "com.sun.star.task.InteractionHandler"));
115     // added to indicate support for configuration.backend.MergeRecoveryRequest
116     aNames[1] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
117 		    "com.sun.star.configuration.backend.InteractionHandler"));
118     aNames[2] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
119                     "com.sun.star.uui.InteractionHandler"));
120     // for backwards compatibility
121     return aNames;
122 }
123 
124 uno::Reference< uno::XInterface > SAL_CALL
createInstance(uno::Reference<lang::XMultiServiceFactory> const & rServiceFactory)125 UUIInteractionHandler::createInstance(
126     uno::Reference< lang::XMultiServiceFactory > const &
127         rServiceFactory)
128     SAL_THROW((uno::Exception))
129 {
130     try
131     {
132         return *new UUIInteractionHandler(rServiceFactory);
133     }
134     catch (std::bad_alloc const &)
135     {
136         throw uno::RuntimeException(
137 	    rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("out of memory")),
138 	    0);
139     }
140 }
141