LibreOffice Module scripting (master) 1
MasterScriptProvider.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#pragma once
21
22#include <rtl/ustring.hxx>
23
25
26#include <com/sun/star/frame/XModel.hpp>
27#include <com/sun/star/lang/XServiceInfo.hpp>
28#include <com/sun/star/container/XNameContainer.hpp>
29#include <com/sun/star/document/XScriptInvocationContext.hpp>
30
31#include <com/sun/star/lang/XInitialization.hpp>
32
33#include <com/sun/star/script/provider/XScriptProvider.hpp>
34#include <com/sun/star/script/browse/XBrowseNode.hpp>
35
36#include "ProviderCache.hxx"
37#include <memory>
38#include <mutex>
39
40namespace func_provider
41{
42
43 typedef ::cppu::WeakImplHelper<
44 css::script::provider::XScriptProvider,
45 css::script::browse::XBrowseNode, css::lang::XServiceInfo,
46 css::lang::XInitialization,
47 css::container::XNameContainer > t_helper;
48
50 public t_helper
51{
52public:
54 explicit MasterScriptProvider(
55 const css::uno::Reference< css::uno::XComponentContext >
56 & xContext );
57 virtual ~MasterScriptProvider() override;
58
59 // XServiceInfo implementation
60 virtual OUString SAL_CALL getImplementationName( ) override;
61
62 // XBrowseNode implementation
63 virtual OUString SAL_CALL getName() override;
64 virtual css::uno::Sequence< css::uno::Reference< css::script::browse::XBrowseNode > > SAL_CALL getChildNodes() override;
65 virtual sal_Bool SAL_CALL hasChildNodes() override;
66 virtual sal_Int16 SAL_CALL getType() override;
67 // XNameContainer
68 virtual void SAL_CALL insertByName( const OUString& aName, const css::uno::Any& aElement ) override;
69 virtual void SAL_CALL removeByName( const OUString& Name ) override;
70
71 // XNameReplace
72 virtual void SAL_CALL replaceByName( const OUString& aName, const css::uno::Any& aElement ) override;
73 // XNameAccess
74 virtual css::uno::Any SAL_CALL getByName( const OUString& aName ) override;
75 virtual css::uno::Sequence< OUString > SAL_CALL getElementNames( ) override;
76 virtual sal_Bool SAL_CALL hasByName( const OUString& aName ) override;
77
78 // XElementAccess
79 virtual css::uno::Type SAL_CALL getElementType( ) override;
80 virtual sal_Bool SAL_CALL hasElements( ) override;
81 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
82 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
83
84 // XScriptProvider implementation
85 virtual css::uno::Reference < css::script::provider::XScript > SAL_CALL
86 getScript( const OUString& scriptURI ) override;
87
94 virtual void SAL_CALL initialize( const css::uno::Sequence < css::uno::Any > & args ) override;
95
96 // returns context string for this provider, eg
97 const OUString& getContextString() const { return m_sCtxString; }
98
99private:
100 static OUString parseLocationName( const OUString& location );
101 void createPkgProvider();
102
104 /* to obtain other services if needed */
105 css::uno::Reference< css::uno::XComponentContext > m_xContext;
106 css::uno::Reference< css::lang::XMultiComponentFactory > m_xMgr;
107 css::uno::Reference< css::frame::XModel > m_xModel;
108 css::uno::Reference< css::document::XScriptInvocationContext > m_xInvocationContext;
109 css::uno::Sequence< css::uno::Any > m_sAargs;
110 OUString m_sNodeName;
111
112 // This component supports XInitialization, it can be created
113 // using createInstanceXXX() or createInstanceWithArgumentsXXX using
114 // the service Manager.
115 // Need to detect proper initialisation and validity
116 // for the object, so m_bIsValid indicates that the object is valid is set in ctor
117 // in case of createInstanceWithArgumentsXXX() called m_bIsValid is set to reset
118 // and then set to true when initialisation is complete
120 // m_bInitialised ensure initialisation only takes place once.
123 css::uno::Reference< css::script::provider::XScriptProvider > m_xMSPPkg;
124 std::unique_ptr<ProviderCache> m_pPCache;
125 std::mutex m_mutex;
126 OUString m_sCtxString;
127};
128
129}
130
131/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual css::uno::Any SAL_CALL getByName(const OUString &aName) override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
css::uno::Reference< css::uno::XComponentContext > m_xContext
virtual sal_Int16 SAL_CALL getType() override
css::uno::Sequence< css::uno::Any > m_sAargs
virtual OUString SAL_CALL getName() override
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &args) override
XInitialise implementation.
css::uno::Reference< css::document::XScriptInvocationContext > m_xInvocationContext
virtual css::uno::Sequence< css::uno::Reference< css::script::browse::XBrowseNode > > SAL_CALL getChildNodes() override
virtual sal_Bool SAL_CALL hasElements() override
virtual void SAL_CALL insertByName(const OUString &aName, const css::uno::Any &aElement) override
css::uno::Reference< css::lang::XMultiComponentFactory > m_xMgr
virtual sal_Bool SAL_CALL hasByName(const OUString &aName) override
virtual void SAL_CALL removeByName(const OUString &Name) override
virtual css::uno::Type SAL_CALL getElementType() override
std::unique_ptr< ProviderCache > m_pPCache
virtual css::uno::Sequence< OUString > SAL_CALL getElementNames() override
MasterScriptProvider(const css::uno::Reference< css::uno::XComponentContext > &xContext)
virtual css::uno::Reference< css::script::provider::XScript > SAL_CALL getScript(const OUString &scriptURI) override
virtual OUString SAL_CALL getImplementationName() override
static OUString parseLocationName(const OUString &location)
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual void SAL_CALL replaceByName(const OUString &aName, const css::uno::Any &aElement) override
css::uno::Reference< css::frame::XModel > m_xModel
virtual sal_Bool SAL_CALL hasChildNodes() override
css::uno::Reference< css::script::provider::XScriptProvider > m_xMSPPkg
OUString aName
::cppu::WeakImplHelper< css::script::provider::XScriptProvider, css::script::browse::XBrowseNode, css::lang::XServiceInfo, css::lang::XInitialization, css::container::XNameContainer > t_helper
args
OUString Name
unsigned char sal_Bool