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 "precompiled_desktop.hxx"
29 #include "sal/config.h"
30 
31 #include "boost/noncopyable.hpp"
32 #include "com/sun/star/beans/PropertyValue.hpp"
33 #include "com/sun/star/frame/DispatchDescriptor.hpp"
34 #include "com/sun/star/frame/XDispatch.hpp"
35 #include "com/sun/star/frame/XDispatchProvider.hpp"
36 #include "com/sun/star/frame/XStatusListener.hpp"
37 #include "com/sun/star/lang/XServiceInfo.hpp"
38 #include "com/sun/star/uno/Exception.hpp"
39 #include "com/sun/star/uno/Reference.hxx"
40 #include "com/sun/star/uno/RuntimeException.hpp"
41 #include "com/sun/star/uno/Sequence.hxx"
42 #include "com/sun/star/uno/XComponentContext.hpp"
43 #include "com/sun/star/uno/XInterface.hpp"
44 #include "com/sun/star/util/URL.hpp"
45 #include "cppuhelper/factory.hxx"
46 #include "cppuhelper/implbase3.hxx"
47 #include "cppuhelper/implementationentry.hxx"
48 #include "cppuhelper/weak.hxx"
49 #include "filter/msfilter/countryid.hxx"
50 #include "osl/diagnose.h"
51 #include "rtl/ustring.h"
52 #include "rtl/ustring.hxx"
53 #include "sal/types.h"
54 #include "uno/lbnames.h"
55 #include "vcl/svapp.hxx"
56 
57 namespace {
58 
59 namespace css = com::sun::star;
60 
61 class Service:
62     public cppu::WeakImplHelper3<
63         css::lang::XServiceInfo, css::frame::XDispatchProvider,
64         css::frame::XDispatch >,
65     private boost::noncopyable
66 {
67 public:
68     static css::uno::Reference< css::uno::XInterface > SAL_CALL static_create(
69         css::uno::Reference< css::uno::XComponentContext > const &)
70         SAL_THROW((css::uno::Exception))
71     { return static_cast< cppu::OWeakObject * >(new Service); }
72 
73     static rtl::OUString SAL_CALL static_getImplementationName();
74 
75     static css::uno::Sequence< rtl::OUString > SAL_CALL
76     static_getSupportedServiceNames();
77 
78 private:
79     Service() {}
80 
81     virtual ~Service() {}
82 
83     virtual rtl::OUString SAL_CALL getImplementationName()
84         throw (css::uno::RuntimeException)
85     { return static_getImplementationName(); }
86 
87     virtual sal_Bool SAL_CALL supportsService(rtl::OUString const & ServiceName)
88         throw (css::uno::RuntimeException)
89     { return ServiceName == getSupportedServiceNames()[0]; } //TODO
90 
91     virtual css::uno::Sequence< rtl::OUString > SAL_CALL
92     getSupportedServiceNames() throw (css::uno::RuntimeException)
93     { return static_getSupportedServiceNames(); }
94 
95     virtual css::uno::Reference< css::frame::XDispatch > SAL_CALL queryDispatch(
96         css::util::URL const &, rtl::OUString const &, sal_Int32)
97         throw (css::uno::RuntimeException)
98     { return this; }
99 
100     virtual css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > >
101     SAL_CALL queryDispatches(
102         css::uno::Sequence< css::frame::DispatchDescriptor > const & Requests)
103         throw (css::uno::RuntimeException);
104 
105     virtual void SAL_CALL dispatch(
106         css::util::URL const &,
107         css::uno::Sequence< css::beans::PropertyValue > const &)
108         throw (css::uno::RuntimeException);
109 
110     virtual void SAL_CALL addStatusListener(
111         css::uno::Reference< css::frame::XStatusListener > const &,
112         css::util::URL const &)
113         throw (css::uno::RuntimeException)
114     {}
115 
116     virtual void SAL_CALL removeStatusListener(
117         css::uno::Reference< css::frame::XStatusListener > const &,
118         css::util::URL const &)
119         throw (css::uno::RuntimeException)
120     {}
121 };
122 
123 rtl::OUString Service::static_getImplementationName() {
124     return rtl::OUString(
125         RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.test.deployment.boxt"));
126 }
127 
128 css::uno::Sequence< rtl::OUString > Service::static_getSupportedServiceNames() {
129     rtl::OUString name(
130         RTL_CONSTASCII_USTRINGPARAM("com.sun.star.test.deployment.boxt"));
131     return css::uno::Sequence< rtl::OUString >(&name, 1);
132 }
133 
134 css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > >
135 Service::queryDispatches(
136     css::uno::Sequence< css::frame::DispatchDescriptor > const & Requests)
137     throw (css::uno::RuntimeException)
138 {
139     css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > s(
140         Requests.getLength());
141     for (sal_Int32 i = 0; i < s.getLength(); ++i) {
142         s[i] = queryDispatch(
143             Requests[i].FeatureURL, Requests[i].FrameName,
144             Requests[i].SearchFlags);
145     }
146     return s;
147 }
148 
149 void Service::dispatch(
150     css::util::URL const &,
151     css::uno::Sequence< css::beans::PropertyValue > const &)
152     throw (css::uno::RuntimeException)
153 {
154     msfilter::ConvertCountryToLanguage(msfilter::COUNTRY_DONTKNOW);
155         // link against some obscure library that is unlikely already loaded
156     Application::ShowNativeErrorBox(
157         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("boxt")),
158         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("test")));
159 }
160 
161 static cppu::ImplementationEntry const services[] = {
162     { &Service::static_create, &Service::static_getImplementationName,
163       &Service::static_getSupportedServiceNames,
164       &cppu::createSingleComponentFactory, 0, 0 },
165     { 0, 0, 0, 0, 0, 0 }
166 };
167 
168 }
169 
170 extern "C" void * SAL_CALL component_getFactory(
171     char const * pImplName, void * pServiceManager, void * pRegistryKey)
172 {
173     return cppu::component_getFactoryHelper(
174         pImplName, pServiceManager, pRegistryKey, services);
175 }
176 
177 extern "C" void SAL_CALL component_getImplementationEnvironment(
178     char const ** ppEnvTypeName, uno_Environment **)
179 {
180     *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
181 }
182 
183 extern "C" sal_Bool SAL_CALL component_writeInfo(
184     void * pServiceManager, void * pRegistryKey)
185 {
186     return component_writeInfoHelper(pServiceManager, pRegistryKey, services);
187 }
188