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