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