Line data Source code
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 :
21 : #include "contenthandlerfactory.hxx"
22 : #include "querytokenizer.hxx"
23 : #include "macros.hxx"
24 : #include "constant.hxx"
25 : #include "versions.hxx"
26 :
27 : #include <com/sun/star/lang/XInitialization.hpp>
28 : #include <comphelper/enumhelper.hxx>
29 : #include <comphelper/processfactory.hxx>
30 : #include <comphelper/sequence.hxx>
31 :
32 :
33 : namespace filter{
34 : namespace config{
35 :
36 21314 : ContentHandlerFactory::ContentHandlerFactory(const css::uno::Reference< css::uno::XComponentContext >& rxContext)
37 21314 : : m_xContext(rxContext)
38 : {
39 : BaseContainer::init(rxContext ,
40 : ContentHandlerFactory::impl_getImplementationName() ,
41 : ContentHandlerFactory::impl_getSupportedServiceNames(),
42 21314 : FilterCache::E_CONTENTHANDLER );
43 21314 : }
44 :
45 :
46 :
47 42628 : ContentHandlerFactory::~ContentHandlerFactory()
48 : {
49 42628 : }
50 :
51 :
52 :
53 2 : css::uno::Reference< css::uno::XInterface > SAL_CALL ContentHandlerFactory::createInstance(const OUString& sHandler)
54 : throw(css::uno::Exception ,
55 : css::uno::RuntimeException, std::exception)
56 : {
57 2 : return createInstanceWithArguments(sHandler, css::uno::Sequence< css::uno::Any >());
58 : }
59 :
60 :
61 :
62 2 : css::uno::Reference< css::uno::XInterface > SAL_CALL ContentHandlerFactory::createInstanceWithArguments(const OUString& sHandler ,
63 : const css::uno::Sequence< css::uno::Any >& lArguments)
64 : throw(css::uno::Exception ,
65 : css::uno::RuntimeException, std::exception)
66 : {
67 2 : css::uno::Reference< css::uno::XInterface > xHandler;
68 :
69 : // SAFE ->
70 4 : ::osl::ResettableMutexGuard aLock(m_aLock);
71 :
72 4 : OUString sRealHandler = sHandler;
73 :
74 : #ifdef _FILTER_CONFIG_MIGRATION_Q_
75 :
76 : /* -> TODO - HACK
77 : check if the given handler name really exists ...
78 : Because our old implementation worked with an internal
79 : type name instead of a handler name. For a small migration time
80 : we must simulate this old feature :-( */
81 :
82 2 : if (!m_rCache->hasItem(FilterCache::E_CONTENTHANDLER, sHandler) && m_rCache->hasItem(FilterCache::E_TYPE, sHandler))
83 : {
84 : _FILTER_CONFIG_LOG_("ContentHandlerFactory::createInstanceWithArguments() ... simulate old type search functionality!\n");
85 :
86 0 : css::uno::Sequence< OUString > lTypes(1);
87 0 : lTypes[0] = sHandler;
88 :
89 0 : css::uno::Sequence< css::beans::NamedValue > lQuery(1);
90 0 : lQuery[0].Name = PROPNAME_TYPES;
91 0 : lQuery[0].Value <<= lTypes;
92 :
93 0 : css::uno::Reference< css::container::XEnumeration > xSet = BaseContainer::createSubSetEnumerationByProperties(lQuery);
94 0 : while(xSet->hasMoreElements())
95 : {
96 0 : ::comphelper::SequenceAsHashMap lHandlerProps(xSet->nextElement());
97 0 : if (!(lHandlerProps[PROPNAME_NAME] >>= sRealHandler))
98 0 : continue;
99 0 : }
100 :
101 : // prevent outside code against NoSuchElementException!
102 : // But dont implement such defensive strategy for our new create handling :-)
103 0 : if (!m_rCache->hasItem(FilterCache::E_CONTENTHANDLER, sRealHandler))
104 0 : return css::uno::Reference< css::uno::XInterface>();
105 : }
106 :
107 : /* <- HACK */
108 :
109 : #endif // _FILTER_CONFIG_MIGRATION_Q_
110 :
111 : // search handler on cache
112 4 : CacheItem aHandler = m_rCache->getItem(FilterCache::E_CONTENTHANDLER, sRealHandler);
113 :
114 : // create service instance
115 2 : xHandler = m_xContext->getServiceManager()->createInstanceWithContext(sRealHandler, m_xContext);
116 :
117 : // initialize filter
118 4 : css::uno::Reference< css::lang::XInitialization > xInit(xHandler, css::uno::UNO_QUERY);
119 2 : if (xInit.is())
120 : {
121 : // format: lInitData[0] = seq<PropertyValue>, which contains all configuration properties of this handler
122 : // lInitData[1] = lArguments[0]
123 : // ...
124 : // lInitData[n] = lArguments[n-1]
125 0 : css::uno::Sequence< css::beans::PropertyValue > lConfig;
126 0 : aHandler >> lConfig;
127 :
128 0 : ::std::vector< css::uno::Any > stlArguments(comphelper::sequenceToContainer< ::std::vector< css::uno::Any > >(lArguments));
129 0 : stlArguments.insert(stlArguments.begin(), css::uno::makeAny(lConfig));
130 :
131 0 : xInit->initialize(comphelper::containerToSequence(stlArguments));
132 : }
133 :
134 4 : return xHandler;
135 : // <- SAFE
136 : }
137 :
138 :
139 :
140 1 : css::uno::Sequence< OUString > SAL_CALL ContentHandlerFactory::getAvailableServiceNames()
141 : throw(css::uno::RuntimeException, std::exception)
142 : {
143 : // must be the same list as ((XNameAccess*)this)->getElementNames() return!
144 1 : return BaseContainer::getElementNames();
145 : }
146 :
147 :
148 :
149 21843 : OUString ContentHandlerFactory::impl_getImplementationName()
150 : {
151 21843 : return OUString( "com.sun.star.comp.filter.config.ContentHandlerFactory" );
152 : }
153 :
154 :
155 :
156 21346 : css::uno::Sequence< OUString > ContentHandlerFactory::impl_getSupportedServiceNames()
157 : {
158 21346 : css::uno::Sequence< OUString > lServiceNames(1);
159 21346 : lServiceNames[0] = "com.sun.star.frame.ContentHandlerFactory";
160 21346 : return lServiceNames;
161 : }
162 :
163 :
164 :
165 21314 : css::uno::Reference< css::uno::XInterface > SAL_CALL ContentHandlerFactory::impl_createInstance(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR)
166 : {
167 21314 : ContentHandlerFactory* pNew = new ContentHandlerFactory( comphelper::getComponentContext(xSMGR) );
168 21314 : return css::uno::Reference< css::uno::XInterface >(static_cast< css::lang::XMultiServiceFactory* >(pNew), css::uno::UNO_QUERY);
169 : }
170 :
171 : } // namespace config
172 : } // namespace filter
173 :
174 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|