diff options
author | Bjoern Michaelsen <bjoern.michaelsen@canonical.com> | 2015-09-19 00:58:47 +0200 |
---|---|---|
committer | Bjoern Michaelsen <bjoern.michaelsen@canonical.com> | 2015-09-19 00:58:47 +0200 |
commit | 4abd8fe7cc30e305169cef8027209a7cb66e29f1 (patch) | |
tree | 81736db34202d79af71384fa10519fe3a8f51161 /unotools | |
parent | 55cb4638a0cd051bc254de935335ce501f12a572 (diff) |
add implementation for theServiceDocumenter singleton
- make utl library use servicedecl.hxx
- thus remove superflous XServiceInfo implementation for XTempFile
- make XTempfile,hxx first include to ensure the header file is
self-contained
- while touching this, fix some indenting in XTempFile.hxx
Change-Id: Id51d99e817d406a919a63505ba01f3372f3111bf
Diffstat (limited to 'unotools')
-rw-r--r-- | unotools/Library_utl.mk | 2 | ||||
-rw-r--r-- | unotools/source/misc/ServiceDocumenter.cxx | 64 | ||||
-rw-r--r-- | unotools/source/misc/ServiceDocumenter.hxx | 50 | ||||
-rw-r--r-- | unotools/source/misc/unotoolsservices.cxx | 27 | ||||
-rw-r--r-- | unotools/source/ucbhelper/XTempFile.hxx | 49 | ||||
-rw-r--r-- | unotools/source/ucbhelper/xtempfile.cxx | 76 | ||||
-rw-r--r-- | unotools/util/utl.component | 3 |
7 files changed, 169 insertions, 102 deletions
diff --git a/unotools/Library_utl.mk b/unotools/Library_utl.mk index 52f2eff48653..a3481de726c0 100644 --- a/unotools/Library_utl.mk +++ b/unotools/Library_utl.mk @@ -104,6 +104,8 @@ $(eval $(call gb_Library_add_exception_objects,utl,\ unotools/source/misc/mediadescriptor \ unotools/source/misc/sharedunocomponent \ unotools/source/misc/syslocale \ + unotools/source/misc/unotoolsservices \ + unotools/source/misc/ServiceDocumenter \ unotools/source/streaming/streamhelper \ unotools/source/streaming/streamwrap \ unotools/source/ucbhelper/localfilehelper \ diff --git a/unotools/source/misc/ServiceDocumenter.cxx b/unotools/source/misc/ServiceDocumenter.cxx new file mode 100644 index 000000000000..8991cc31807c --- /dev/null +++ b/unotools/source/misc/ServiceDocumenter.cxx @@ -0,0 +1,64 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +#include <ServiceDocumenter.hxx> +#include <comphelper/servicedecl.hxx> +#include <com/sun/star/system/XSystemShellExecute.hpp> +using namespace com::sun::star; +using uno::Reference; +using lang::XServiceInfo; +using lang::XTypeProvider; + +void unotools::misc::ServiceDocumenter::showCoreDocs(const Reference<XServiceInfo>& xService) +{ + if(!xService.is()) + return; + auto xMSF(m_xContext->getServiceManager()); + Reference<system::XSystemShellExecute> xShell(xMSF->createInstanceWithContext("com.sun.star.system.SystemShellExecute", m_xContext), uno::UNO_QUERY); + xShell->execute(m_sCoreBaseUrl + xService->getImplementationName(), "", 0); +} + +void unotools::misc::ServiceDocumenter::showInterfaceDocs(const Reference<XTypeProvider>& xTypeProvider) +{ + if(!xTypeProvider.is()) + return; + auto xMSF(m_xContext->getServiceManager()); + Reference<system::XSystemShellExecute> xShell(xMSF->createInstanceWithContext("com.sun.star.system.SystemShellExecute", m_xContext), uno::UNO_QUERY); + for(auto aType : xTypeProvider->getTypes()) + { + auto sUrl = aType.getTypeName(); + sal_Int32 nIdx = 0; + while(nIdx != -1) + sUrl = sUrl.replaceFirst(".", "_1_1", &nIdx); + xShell->execute(m_sServiceBaseUrl + "/interface" + sUrl + ".html", "", 0); + } +} + +void unotools::misc::ServiceDocumenter::showServiceDocs(const Reference<XServiceInfo>& xService) +{ + if(!xService.is()) + return; + auto xMSF(m_xContext->getServiceManager()); + Reference<system::XSystemShellExecute> xShell(xMSF->createInstanceWithContext("com.sun.star.system.SystemShellExecute", m_xContext), uno::UNO_QUERY); + for(auto sService : xService->getSupportedServiceNames()) + { + auto sUrl = sService; + sal_Int32 nIdx = 0; + while(nIdx != -1) + sUrl = sUrl.replaceFirst(".", "_1_1", &nIdx); + xShell->execute(m_sServiceBaseUrl + "/service" + sUrl + ".html", "", 0); + } +} + +namespace sdecl = ::comphelper::service_decl; +sdecl::class_< unotools::misc::ServiceDocumenter > ServiceDocumenterImpl; +extern const sdecl::ServiceDecl ServiceDocumenterDecl( + ServiceDocumenterImpl, + "com.sun.star.comp.unotools.misc.ServiceDocumenter", + ""); + diff --git a/unotools/source/misc/ServiceDocumenter.hxx b/unotools/source/misc/ServiceDocumenter.hxx new file mode 100644 index 000000000000..ad84623bbaf8 --- /dev/null +++ b/unotools/source/misc/ServiceDocumenter.hxx @@ -0,0 +1,50 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +#ifndef INCLUDED_UNOTOOLS_INC_SERVICEDOCUMENTER_HXX +#define INCLUDED_UNOTOOLS_INC_SERVICEDOCUMENTER_HXX + +#include <com/sun/star/uno/XComponentContext.hpp> +#include <cppuhelper/implbase.hxx> +#include <com/sun/star/script/XServiceDocumenter.hpp> + +namespace unotools { namespace misc { + +class ServiceDocumenter : public ::cppu::WeakImplHelper< + ::com::sun::star::script::XServiceDocumenter> +{ + public: + ServiceDocumenter(::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext> const& xContext) + : m_xContext(xContext) + , m_sCoreBaseUrl("http://example.com") + , m_sServiceBaseUrl("http://api.libreoffice.org/docs/idl/ref") + {}; + // XServiceDocumenter + virtual OUString getCoreBaseUrl() SAL_OVERRIDE + { return m_sCoreBaseUrl; }; + virtual void setCoreBaseUrl( const OUString& sCoreBaseUrl ) SAL_OVERRIDE + { m_sCoreBaseUrl = sCoreBaseUrl; }; + virtual OUString getServiceBaseUrl() SAL_OVERRIDE + { return m_sServiceBaseUrl; }; + virtual void setServiceBaseUrl( const OUString& sServiceBaseUrl ) SAL_OVERRIDE + { m_sServiceBaseUrl = sServiceBaseUrl; }; + virtual void showServiceDocs( const ::css::uno::Reference< ::css::lang::XServiceInfo >& xService) SAL_OVERRIDE; + virtual void showInterfaceDocs( const ::css::uno::Reference< ::css::lang::XTypeProvider >& xTypeProvider ) SAL_OVERRIDE; + virtual void showCoreDocs( const ::css::uno::Reference< ::css::lang::XServiceInfo >& xService) SAL_OVERRIDE; + protected: + virtual ~ServiceDocumenter() + {}; + private: + css::uno::Reference< css::uno::XComponentContext> m_xContext; + OUString m_sCoreBaseUrl; + OUString m_sServiceBaseUrl; +}; + +}} +#endif +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/unotools/source/misc/unotoolsservices.cxx b/unotools/source/misc/unotoolsservices.cxx new file mode 100644 index 000000000000..2455ed065932 --- /dev/null +++ b/unotools/source/misc/unotoolsservices.cxx @@ -0,0 +1,27 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <comphelper/servicedecl.hxx> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <uno/environment.h> + +namespace sdecl = ::comphelper::service_decl; + +extern sdecl::ServiceDecl const OTempFileServiceDecl; +extern sdecl::ServiceDecl const ServiceDocumenterDecl; + + +extern "C" SAL_DLLPUBLIC_EXPORT void* SAL_CALL utl_component_getFactory( + sal_Char const* pImplName, void*, void*) +{ + return component_getFactoryHelper( pImplName, + OTempFileServiceDecl, ServiceDocumenterDecl); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/unotools/source/ucbhelper/XTempFile.hxx b/unotools/source/ucbhelper/XTempFile.hxx index 9aa6c40b35d4..855e073f377b 100644 --- a/unotools/source/ucbhelper/XTempFile.hxx +++ b/unotools/source/ucbhelper/XTempFile.hxx @@ -34,28 +34,25 @@ class SvStream; namespace utl { class TempFile; } -typedef ::cppu::WeakImplHelper< ::com::sun::star::io::XTempFile - , ::com::sun::star::io::XInputStream - , ::com::sun::star::io::XOutputStream - , ::com::sun::star::io::XTruncate - , ::com::sun::star::lang::XServiceInfo - > - OTempFileBase; -class OTempFileService : - public OTempFileBase, - public ::cppu::PropertySetMixin< ::com::sun::star::io::XTempFile > +typedef ::cppu::WeakImplHelper< ::com::sun::star::io::XTempFile + , ::com::sun::star::io::XInputStream + , ::com::sun::star::io::XOutputStream + , ::com::sun::star::io::XTruncate > OTempFileBase; + +class OTempFileService : public OTempFileBase + , public ::cppu::PropertySetMixin< ::com::sun::star::io::XTempFile > { protected: - ::utl::TempFile* mpTempFile; - ::osl::Mutex maMutex; - SvStream* mpStream; - bool mbRemoveFile; - bool mbInClosed; - bool mbOutClosed; + ::utl::TempFile* mpTempFile; + ::osl::Mutex maMutex; + SvStream* mpStream; + bool mbRemoveFile; + bool mbInClosed; + bool mbOutClosed; - sal_Int64 mnCachedPos; - bool mbHasCachedPos; + sal_Int64 mnCachedPos; + bool mbHasCachedPos; void checkError () const; void checkConnected (); @@ -120,24 +117,8 @@ public: // XTruncate virtual void SAL_CALL truncate() throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; - // XServiceInfo - virtual OUString SAL_CALL getImplementationName() - throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; - virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) - throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; - virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() - throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; - //::com::sun::star::uno::Reference < ::com::sun::star::uno::XInterface > SAL_CALL XTempFile_createInstance( ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > const & context); - static OUString getImplementationName_Static (); - static ::com::sun::star::uno::Sequence < OUString > getSupportedServiceNames_Static(); - - static ::com::sun::star::uno::Reference < com::sun::star::lang::XSingleComponentFactory > createServiceFactory_Static(); - -private: - OTempFileService( OTempFileService & ) SAL_DELETED_FUNCTION; virtual ~OTempFileService (); - }; #endif diff --git a/unotools/source/ucbhelper/xtempfile.cxx b/unotools/source/ucbhelper/xtempfile.cxx index 0ec6f47ae0fd..2f59ebcfc4c0 100644 --- a/unotools/source/ucbhelper/xtempfile.cxx +++ b/unotools/source/ucbhelper/xtempfile.cxx @@ -17,13 +17,14 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include "XTempFile.hxx" #include <cppuhelper/factory.hxx> #include <cppuhelper/supportsservice.hxx> #include <cppuhelper/typeprovider.hxx> +#include <comphelper/servicedecl.hxx> #include <osl/file.hxx> #include <unotools/configmgr.hxx> #include <unotools/tempfile.hxx> -#include "XTempFile.hxx" OTempFileService::OTempFileService(css::uno::Reference< css::uno::XComponentContext > const & context) : ::cppu::PropertySetMixin< css::io::XTempFile >( @@ -411,72 +412,11 @@ throw ( css::io::IOException, css::uno::RuntimeException, std::exception ) checkError(); } -// XServiceInfo - -OUString SAL_CALL OTempFileService::getImplementationName() -throw ( css::uno::RuntimeException, std::exception ) -{ - return getImplementationName_Static(); -} - -sal_Bool SAL_CALL OTempFileService::supportsService( OUString const & rServiceName ) -throw ( css::uno::RuntimeException, std::exception ) -{ - return cppu::supportsService(this, rServiceName); -} - -css::uno::Sequence < OUString > SAL_CALL OTempFileService::getSupportedServiceNames() -throw ( css::uno::RuntimeException, std::exception ) -{ - return getSupportedServiceNames_Static(); -} - -OUString OTempFileService::getImplementationName_Static () -{ - return OUString ( "com.sun.star.io.comp.TempFile" ); -} -css::uno::Sequence < OUString > OTempFileService::getSupportedServiceNames_Static() -{ - css::uno::Sequence < OUString > aNames ( 1 ); - aNames[0] = "com.sun.star.io.TempFile"; - return aNames; -} -css::uno::Reference < css::uno::XInterface >SAL_CALL XTempFile_createInstance( - css::uno::Reference< css::uno::XComponentContext > const & context) -{ - return static_cast< ::cppu::OWeakObject * >( new OTempFileService(context) ); -} - -css::uno::Reference < css::lang::XSingleComponentFactory > OTempFileService::createServiceFactory_Static() -{ - return ::cppu::createSingleComponentFactory( XTempFile_createInstance, getImplementationName_Static(), getSupportedServiceNames_Static() ); -} - -/** - * This function is called to get service factories for an implementation. - * @param pImplName name of implementation - * @param pServiceManager generic uno interface providing a service manager to instantiate components - * @param pRegistryKey registry data key to read and write component persistent data - * @return a component factory (generic uno interface) - */ -extern "C" SAL_DLLPUBLIC_EXPORT void * SAL_CALL utl_component_getFactory( - const sal_Char * pImplName, void * pServiceManager, - SAL_UNUSED_PARAMETER void * /*pRegistryKey*/ ) -{ - void * pRet = 0; - css::uno::Reference< css::lang::XMultiServiceFactory > xSMgr( - static_cast< css::lang::XMultiServiceFactory * >( pServiceManager ) ); - css::uno::Reference< css::lang::XSingleComponentFactory > xFactory; - - if (OTempFileService::getImplementationName_Static().equalsAscii( pImplName ) ) - xFactory = OTempFileService::createServiceFactory_Static(); - - if ( xFactory.is() ) - { - xFactory->acquire(); - pRet = xFactory.get(); - } - return pRet; -} +namespace sdecl = ::comphelper::service_decl; +sdecl::class_< OTempFileService> OTempFileServiceImpl; +extern const sdecl::ServiceDecl OTempFileServiceDecl( + OTempFileServiceImpl, + "com.sun.star.io.comp.TempFile", + "com.sun.star.io.TempFile"); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/unotools/util/utl.component b/unotools/util/utl.component index ef929f2a9b77..8b9371343582 100644 --- a/unotools/util/utl.component +++ b/unotools/util/utl.component @@ -22,4 +22,7 @@ <implementation name="com.sun.star.io.comp.TempFile"> <service name="com.sun.star.io.TempFile"/> </implementation> + <implementation name="com.sun.star.comp.unotools.misc.ServiceDocumenter"> + <singleton name="com.sun.star.util.theServiceDocumenter"/> + </implementation> </component> |