LibreOffice Module filter (master) 1
frameloaderfactory.cxx
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
22
23#include <com/sun/star/lang/XInitialization.hpp>
25
26
27namespace filter::config{
28
29FrameLoaderFactory::FrameLoaderFactory(const css::uno::Reference< css::uno::XComponentContext >& rxContext)
30 : m_xContext(rxContext)
31{
32 BaseContainer::init("com.sun.star.comp.filter.config.FrameLoaderFactory" ,
33 { "com.sun.star.frame.FrameLoaderFactory" },
35}
36
37
39{
40}
41
42
43css::uno::Reference< css::uno::XInterface > SAL_CALL FrameLoaderFactory::createInstance(const OUString& sLoader)
44{
45 return createInstanceWithArguments(sLoader, css::uno::Sequence< css::uno::Any >());
46}
47
48
49css::uno::Reference< css::uno::XInterface > SAL_CALL FrameLoaderFactory::createInstanceWithArguments(const OUString& sLoader ,
50 const css::uno::Sequence< css::uno::Any >& lArguments)
51{
52 // SAFE ->
53 std::unique_lock aLock(m_aMutex);
54
55 auto & cache = GetTheFilterCache();
56
57 // search loader on cache
58 CacheItem aLoader = cache.getItem(m_eType, sLoader);
59
60 // create service instance
61 css::uno::Reference< css::uno::XInterface > xLoader = m_xContext->getServiceManager()->createInstanceWithContext(sLoader, m_xContext);
62
63 // initialize filter
64 css::uno::Reference< css::lang::XInitialization > xInit(xLoader, css::uno::UNO_QUERY);
65 if (xInit.is())
66 {
67 // format: lInitData[0] = seq<PropertyValue>, which contains all configuration properties of this loader
68 // lInitData[1] = lArguments[0]
69 // ...
70 // lInitData[n] = lArguments[n-1]
71 css::uno::Sequence< css::beans::PropertyValue > lConfig;
72 aLoader >> lConfig;
73
74 ::std::vector< css::uno::Any > stlArguments(comphelper::sequenceToContainer< ::std::vector<css::uno::Any> >(lArguments));
75 stlArguments.insert(stlArguments.begin(), css::uno::Any(lConfig));
76
77 xInit->initialize(comphelper::containerToSequence(stlArguments));
78 }
79
80 return xLoader;
81 // <- SAFE
82}
83
84
85css::uno::Sequence< OUString > SAL_CALL FrameLoaderFactory::getAvailableServiceNames()
86{
87 // must be the same list as ((XNameAccess*)this)->getElementNames() return!
89}
90
91} // namespace filter::config
92
93
94extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
96 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&)
97{
98 return cppu::acquire(new filter::config::FrameLoaderFactory(context));
99}
100
101
102/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XComponentContext > m_xContext
Definition: OdfFlatXml.cxx:62
void init(const OUString &sImplementationName, const css::uno::Sequence< OUString > &lServiceNames, FilterCache::EItemType eType)
initialize this generic instance with some specialized values from our derived object.
virtual css::uno::Sequence< OUString > SAL_CALL getElementNames() override
represent an item of a FilterCache instance.
Definition: cacheitem.hxx:40
implements the service <type scope="com.sun.star.document">FrameLoaderFactory</type>.
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstance(const OUString &sLoader) override
virtual css::uno::Sequence< OUString > SAL_CALL getAvailableServiceNames() override
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstanceWithArguments(const OUString &sLoader, const css::uno::Sequence< css::uno::Any > &lArguments) override
FrameLoaderFactory(const css::uno::Reference< css::uno::XComponentContext > &rxContext)
standard ctor to connect this interface wrapper to the global filter cache instance ....
css::uno::Reference< css::uno::XComponentContext > m_xContext
virtual ~FrameLoaderFactory() override
standard dtor.
const EnumerationType m_eType
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * filter_FrameLoaderFactory_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
std::mutex m_aMutex
DstType sequenceToContainer(const css::uno::Sequence< SrcType > &i_Sequence)
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
FilterCache & GetTheFilterCache()