1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_filter.hxx"
26
27 #include "contenthandlerfactory.hxx"
28 #include "querytokenizer.hxx"
29 #include "macros.hxx"
30 #include "constant.hxx"
31 #include "versions.hxx"
32
33 //_______________________________________________
34 // includes
35 #include <com/sun/star/lang/XInitialization.hpp>
36 #include <comphelper/enumhelper.hxx>
37
38 //_______________________________________________
39 // namespace
40
41 namespace filter{
42 namespace config{
43
44 namespace css = ::com::sun::star;
45
46 //_______________________________________________
47 // definitions
48
49 /*-----------------------------------------------
50 09.07.2003 07:43
51 -----------------------------------------------*/
ContentHandlerFactory(const css::uno::Reference<css::lang::XMultiServiceFactory> & xSMGR)52 ContentHandlerFactory::ContentHandlerFactory(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR)
53 {
54 BaseContainer::init(xSMGR ,
55 ContentHandlerFactory::impl_getImplementationName() ,
56 ContentHandlerFactory::impl_getSupportedServiceNames(),
57 FilterCache::E_CONTENTHANDLER );
58 }
59
60 /*-----------------------------------------------
61 09.07.2003 07:43
62 -----------------------------------------------*/
~ContentHandlerFactory()63 ContentHandlerFactory::~ContentHandlerFactory()
64 {
65 }
66
67 /*-----------------------------------------------
68 16.07.2003 13:38
69 -----------------------------------------------*/
createInstance(const::rtl::OUString & sHandler)70 css::uno::Reference< css::uno::XInterface > SAL_CALL ContentHandlerFactory::createInstance(const ::rtl::OUString& sHandler)
71 throw(css::uno::Exception ,
72 css::uno::RuntimeException)
73 {
74 return createInstanceWithArguments(sHandler, css::uno::Sequence< css::uno::Any >());
75 }
76
77 /*-----------------------------------------------
78 16.07.2003 13:40
79 -----------------------------------------------*/
createInstanceWithArguments(const::rtl::OUString & sHandler,const css::uno::Sequence<css::uno::Any> & lArguments)80 css::uno::Reference< css::uno::XInterface > SAL_CALL ContentHandlerFactory::createInstanceWithArguments(const ::rtl::OUString& sHandler ,
81 const css::uno::Sequence< css::uno::Any >& lArguments)
82 throw(css::uno::Exception ,
83 css::uno::RuntimeException)
84 {
85 css::uno::Reference< css::uno::XInterface > xHandler;
86
87 // SAFE ->
88 ::osl::ResettableMutexGuard aLock(m_aLock);
89
90 ::rtl::OUString sRealHandler = sHandler;
91
92 #ifdef _FILTER_CONFIG_MIGRATION_Q_
93
94 /* -> TODO - HACK
95 check if the given handler name realy exist ...
96 Because our old implementation worked with an internal
97 type name instead of a handler name. For a small migration time
98 we must simulate this old feature :-( */
99
100 if (!m_rCache->hasItem(FilterCache::E_CONTENTHANDLER, sHandler) && m_rCache->hasItem(FilterCache::E_TYPE, sHandler))
101 {
102 _FILTER_CONFIG_LOG_("ContentHandlerFactory::createInstanceWithArguments() ... simulate old type search functionality!\n");
103
104 css::uno::Sequence< ::rtl::OUString > lTypes(1);
105 lTypes[0] = sHandler;
106
107 css::uno::Sequence< css::beans::NamedValue > lQuery(1);
108 lQuery[0].Name = PROPNAME_TYPES;
109 lQuery[0].Value <<= lTypes;
110
111 css::uno::Reference< css::container::XEnumeration > xSet = createSubSetEnumerationByProperties(lQuery);
112 while(xSet->hasMoreElements())
113 {
114 ::comphelper::SequenceAsHashMap lHandlerProps(xSet->nextElement());
115 if (!(lHandlerProps[PROPNAME_NAME] >>= sRealHandler))
116 continue;
117 }
118
119 // prevent outside code against NoSuchElementException!
120 // But dont implement such defensive strategy for our new create handling :-)
121 if (!m_rCache->hasItem(FilterCache::E_CONTENTHANDLER, sRealHandler))
122 return css::uno::Reference< css::uno::XInterface>();
123 }
124
125 /* <- HACK */
126
127 #endif // _FILTER_CONFIG_MIGRATION_Q_
128
129 // search handler on cache
130 CacheItem aHandler = m_rCache->getItem(FilterCache::E_CONTENTHANDLER, sRealHandler);
131
132 // create service instance
133 xHandler = m_xSMGR->createInstance(sRealHandler);
134
135 // initialize filter
136 css::uno::Reference< css::lang::XInitialization > xInit(xHandler, css::uno::UNO_QUERY);
137 if (xInit.is())
138 {
139 // format: lInitData[0] = seq<PropertyValue>, which contains all configuration properties of this handler
140 // lInitData[1] = lArguments[0]
141 // ...
142 // lInitData[n] = lArguments[n-1]
143 css::uno::Sequence< css::beans::PropertyValue > lConfig;
144 aHandler >> lConfig;
145
146 ::comphelper::SequenceAsVector< css::uno::Any > stlArguments(lArguments);
147 stlArguments.insert(stlArguments.begin(), css::uno::makeAny(lConfig));
148
149 css::uno::Sequence< css::uno::Any > lInitData;
150 stlArguments >> lInitData;
151
152 xInit->initialize(lInitData);
153 }
154
155 return xHandler;
156 // <- SAFE
157 }
158
159 /*-----------------------------------------------
160 09.07.2003 07:46
161 -----------------------------------------------*/
getAvailableServiceNames()162 css::uno::Sequence< ::rtl::OUString > SAL_CALL ContentHandlerFactory::getAvailableServiceNames()
163 throw(css::uno::RuntimeException)
164 {
165 // must be the same list as ((XNameAccess*)this)->getElementNames() return!
166 return getElementNames();
167 }
168
169 /*-----------------------------------------------
170 09.07.2003 07:43
171 -----------------------------------------------*/
impl_getImplementationName()172 ::rtl::OUString ContentHandlerFactory::impl_getImplementationName()
173 {
174 return ::rtl::OUString::createFromAscii("com.sun.star.comp.filter.config.ContentHandlerFactory");
175 }
176
177 /*-----------------------------------------------
178 09.07.2003 07:43
179 -----------------------------------------------*/
impl_getSupportedServiceNames()180 css::uno::Sequence< ::rtl::OUString > ContentHandlerFactory::impl_getSupportedServiceNames()
181 {
182 css::uno::Sequence< ::rtl::OUString > lServiceNames(1);
183 lServiceNames[0] = ::rtl::OUString::createFromAscii("com.sun.star.frame.ContentHandlerFactory");
184 return lServiceNames;
185 }
186
187 /*-----------------------------------------------
188 09.07.2003 07:43
189 -----------------------------------------------*/
impl_createInstance(const css::uno::Reference<css::lang::XMultiServiceFactory> & xSMGR)190 css::uno::Reference< css::uno::XInterface > SAL_CALL ContentHandlerFactory::impl_createInstance(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR)
191 {
192 ContentHandlerFactory* pNew = new ContentHandlerFactory(xSMGR);
193 return css::uno::Reference< css::uno::XInterface >(static_cast< css::lang::XMultiServiceFactory* >(pNew), css::uno::UNO_QUERY);
194 }
195
196 } // namespace config
197 } // namespace filter
198