Kaydet (Commit) 4abd8fe7 authored tarafından Bjoern Michaelsen's avatar Bjoern Michaelsen

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
üst 55cb4638
...@@ -104,6 +104,8 @@ $(eval $(call gb_Library_add_exception_objects,utl,\ ...@@ -104,6 +104,8 @@ $(eval $(call gb_Library_add_exception_objects,utl,\
unotools/source/misc/mediadescriptor \ unotools/source/misc/mediadescriptor \
unotools/source/misc/sharedunocomponent \ unotools/source/misc/sharedunocomponent \
unotools/source/misc/syslocale \ unotools/source/misc/syslocale \
unotools/source/misc/unotoolsservices \
unotools/source/misc/ServiceDocumenter \
unotools/source/streaming/streamhelper \ unotools/source/streaming/streamhelper \
unotools/source/streaming/streamwrap \ unotools/source/streaming/streamwrap \
unotools/source/ucbhelper/localfilehelper \ unotools/source/ucbhelper/localfilehelper \
......
/* -*- 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",
"");
/* -*- 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: */
/* -*- 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: */
...@@ -34,28 +34,25 @@ ...@@ -34,28 +34,25 @@
class SvStream; class SvStream;
namespace utl { class TempFile; } 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 : typedef ::cppu::WeakImplHelper< ::com::sun::star::io::XTempFile
public OTempFileBase, , ::com::sun::star::io::XInputStream
public ::cppu::PropertySetMixin< ::com::sun::star::io::XTempFile > , ::com::sun::star::io::XOutputStream
, ::com::sun::star::io::XTruncate > OTempFileBase;
class OTempFileService : public OTempFileBase
, public ::cppu::PropertySetMixin< ::com::sun::star::io::XTempFile >
{ {
protected: protected:
::utl::TempFile* mpTempFile; ::utl::TempFile* mpTempFile;
::osl::Mutex maMutex; ::osl::Mutex maMutex;
SvStream* mpStream; SvStream* mpStream;
bool mbRemoveFile; bool mbRemoveFile;
bool mbInClosed; bool mbInClosed;
bool mbOutClosed; bool mbOutClosed;
sal_Int64 mnCachedPos; sal_Int64 mnCachedPos;
bool mbHasCachedPos; bool mbHasCachedPos;
void checkError () const; void checkError () const;
void checkConnected (); void checkConnected ();
...@@ -120,24 +117,8 @@ public: ...@@ -120,24 +117,8 @@ public:
// XTruncate // XTruncate
virtual void SAL_CALL truncate() virtual void SAL_CALL truncate()
throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; 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 (); virtual ~OTempFileService ();
}; };
#endif #endif
......
...@@ -17,13 +17,14 @@ ...@@ -17,13 +17,14 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 . * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/ */
#include "XTempFile.hxx"
#include <cppuhelper/factory.hxx> #include <cppuhelper/factory.hxx>
#include <cppuhelper/supportsservice.hxx> #include <cppuhelper/supportsservice.hxx>
#include <cppuhelper/typeprovider.hxx> #include <cppuhelper/typeprovider.hxx>
#include <comphelper/servicedecl.hxx>
#include <osl/file.hxx> #include <osl/file.hxx>
#include <unotools/configmgr.hxx> #include <unotools/configmgr.hxx>
#include <unotools/tempfile.hxx> #include <unotools/tempfile.hxx>
#include "XTempFile.hxx"
OTempFileService::OTempFileService(css::uno::Reference< css::uno::XComponentContext > const & context) OTempFileService::OTempFileService(css::uno::Reference< css::uno::XComponentContext > const & context)
: ::cppu::PropertySetMixin< css::io::XTempFile >( : ::cppu::PropertySetMixin< css::io::XTempFile >(
...@@ -411,72 +412,11 @@ throw ( css::io::IOException, css::uno::RuntimeException, std::exception ) ...@@ -411,72 +412,11 @@ throw ( css::io::IOException, css::uno::RuntimeException, std::exception )
checkError(); checkError();
} }
// XServiceInfo namespace sdecl = ::comphelper::service_decl;
sdecl::class_< OTempFileService> OTempFileServiceImpl;
OUString SAL_CALL OTempFileService::getImplementationName() extern const sdecl::ServiceDecl OTempFileServiceDecl(
throw ( css::uno::RuntimeException, std::exception ) OTempFileServiceImpl,
{ "com.sun.star.io.comp.TempFile",
return getImplementationName_Static(); "com.sun.star.io.TempFile");
}
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;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -22,4 +22,7 @@ ...@@ -22,4 +22,7 @@
<implementation name="com.sun.star.io.comp.TempFile"> <implementation name="com.sun.star.io.comp.TempFile">
<service name="com.sun.star.io.TempFile"/> <service name="com.sun.star.io.TempFile"/>
</implementation> </implementation>
<implementation name="com.sun.star.comp.unotools.misc.ServiceDocumenter">
<singleton name="com.sun.star.util.theServiceDocumenter"/>
</implementation>
</component> </component>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment