LibreOffice Module filter (master) 1
contenthandlerfactory.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
29ContentHandlerFactory::ContentHandlerFactory(const css::uno::Reference< css::uno::XComponentContext >& rxContext)
30 : m_xContext(rxContext)
31{
32 BaseContainer::init("com.sun.star.comp.filter.config.ContentHandlerFactory" ,
33 { "com.sun.star.frame.ContentHandlerFactory" },
35}
36
37
39{
40}
41
42
43css::uno::Reference< css::uno::XInterface > SAL_CALL ContentHandlerFactory::createInstance(const OUString& sHandler)
44{
45 return createInstanceWithArguments(sHandler, css::uno::Sequence< css::uno::Any >());
46}
47
48
49css::uno::Reference< css::uno::XInterface > SAL_CALL ContentHandlerFactory::createInstanceWithArguments(const OUString& sHandler ,
50 const css::uno::Sequence< css::uno::Any >& lArguments)
51{
52 css::uno::Reference< css::uno::XInterface > xHandler;
53
54 // SAFE ->
55 std::unique_lock aLock(m_aMutex);
56
57 auto & cache = GetTheFilterCache();
58
59 // search handler on cache
60 CacheItem aHandler = cache.getItem(FilterCache::E_CONTENTHANDLER, sHandler);
61
62 // create service instance
63 xHandler = m_xContext->getServiceManager()->createInstanceWithContext(sHandler, m_xContext);
64
65 // initialize filter
66 css::uno::Reference< css::lang::XInitialization > xInit(xHandler, css::uno::UNO_QUERY);
67 if (xInit.is())
68 {
69 // format: lInitData[0] = seq<PropertyValue>, which contains all configuration properties of this handler
70 // lInitData[1] = lArguments[0]
71 // ...
72 // lInitData[n] = lArguments[n-1]
73 css::uno::Sequence< css::beans::PropertyValue > lConfig;
74 aHandler >> lConfig;
75
76 ::std::vector< css::uno::Any > stlArguments(comphelper::sequenceToContainer< ::std::vector< css::uno::Any > >(lArguments));
77 stlArguments.insert(stlArguments.begin(), css::uno::Any(lConfig));
78
79 xInit->initialize(comphelper::containerToSequence(stlArguments));
80 }
81
82 return xHandler;
83 // <- SAFE
84}
85
86
87css::uno::Sequence< OUString > SAL_CALL ContentHandlerFactory::getAvailableServiceNames()
88{
89 // must be the same list as ((XNameAccess*)this)->getElementNames() return!
91}
92
93} // namespace filter::config
94
95extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
97 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&)
98{
99 return cppu::acquire(new filter::config::ContentHandlerFactory(context));
100}
101
102
103/* 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">ContentHandlerFactory</type>.
virtual css::uno::Sequence< OUString > SAL_CALL getAvailableServiceNames() override
ContentHandlerFactory(const css::uno::Reference< css::uno::XComponentContext > &rxContext)
standard ctor to connect this interface wrapper to the global filter cache instance ....
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstanceWithArguments(const OUString &sHandler, const css::uno::Sequence< css::uno::Any > &lArguments) override
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstance(const OUString &sHandler) override
css::uno::Reference< css::uno::XComponentContext > m_xContext
virtual ~ContentHandlerFactory() override
standard dtor.
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * filter_ContentHandlerFactory_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()