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