Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include "contenthandlerfactory.hxx"
31 : : #include "querytokenizer.hxx"
32 : : #include "macros.hxx"
33 : : #include "constant.hxx"
34 : : #include "versions.hxx"
35 : :
36 : : #include <com/sun/star/lang/XInitialization.hpp>
37 : : #include <comphelper/enumhelper.hxx>
38 : :
39 : :
40 : : namespace filter{
41 : : namespace config{
42 : :
43 : : namespace css = ::com::sun::star;
44 : :
45 : :
46 : :
47 : :
48 : 153 : ContentHandlerFactory::ContentHandlerFactory(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR)
49 : : {
50 : : BaseContainer::init(xSMGR ,
51 : : ContentHandlerFactory::impl_getImplementationName() ,
52 : : ContentHandlerFactory::impl_getSupportedServiceNames(),
53 [ + - ][ + - ]: 153 : FilterCache::E_CONTENTHANDLER );
[ + - ][ + - ]
54 : 153 : }
55 : :
56 : :
57 : :
58 : 153 : ContentHandlerFactory::~ContentHandlerFactory()
59 : : {
60 [ - + ]: 306 : }
61 : :
62 : :
63 : :
64 : 4 : css::uno::Reference< css::uno::XInterface > SAL_CALL ContentHandlerFactory::createInstance(const ::rtl::OUString& sHandler)
65 : : throw(css::uno::Exception ,
66 : : css::uno::RuntimeException)
67 : : {
68 [ + - ]: 4 : return createInstanceWithArguments(sHandler, css::uno::Sequence< css::uno::Any >());
69 : : }
70 : :
71 : :
72 : :
73 : 4 : css::uno::Reference< css::uno::XInterface > SAL_CALL ContentHandlerFactory::createInstanceWithArguments(const ::rtl::OUString& sHandler ,
74 : : const css::uno::Sequence< css::uno::Any >& lArguments)
75 : : throw(css::uno::Exception ,
76 : : css::uno::RuntimeException)
77 : : {
78 : 4 : css::uno::Reference< css::uno::XInterface > xHandler;
79 : :
80 : : // SAFE ->
81 [ + - ]: 4 : ::osl::ResettableMutexGuard aLock(m_aLock);
82 : :
83 : 4 : ::rtl::OUString sRealHandler = sHandler;
84 : :
85 : : #ifdef _FILTER_CONFIG_MIGRATION_Q_
86 : :
87 : : /* -> TODO - HACK
88 : : check if the given handler name realy exist ...
89 : : Because our old implementation worked with an internal
90 : : type name instead of a handler name. For a small migration time
91 : : we must simulate this old feature :-( */
92 : :
93 [ + - ][ - + ]: 4 : if (!m_rCache->hasItem(FilterCache::E_CONTENTHANDLER, sHandler) && m_rCache->hasItem(FilterCache::E_TYPE, sHandler))
[ # # ][ # # ]
[ # # ][ - + ]
[ + - ]
94 : : {
95 : : _FILTER_CONFIG_LOG_("ContentHandlerFactory::createInstanceWithArguments() ... simulate old type search functionality!\n");
96 : :
97 [ # # ]: 0 : css::uno::Sequence< ::rtl::OUString > lTypes(1);
98 [ # # ]: 0 : lTypes[0] = sHandler;
99 : :
100 [ # # ]: 0 : css::uno::Sequence< css::beans::NamedValue > lQuery(1);
101 [ # # ]: 0 : lQuery[0].Name = PROPNAME_TYPES;
102 [ # # ][ # # ]: 0 : lQuery[0].Value <<= lTypes;
103 : :
104 [ # # ]: 0 : css::uno::Reference< css::container::XEnumeration > xSet = createSubSetEnumerationByProperties(lQuery);
105 [ # # ][ # # ]: 0 : while(xSet->hasMoreElements())
[ # # ]
106 : : {
107 [ # # ][ # # ]: 0 : ::comphelper::SequenceAsHashMap lHandlerProps(xSet->nextElement());
[ # # ]
108 [ # # ][ # # ]: 0 : if (!(lHandlerProps[PROPNAME_NAME] >>= sRealHandler))
109 : 0 : continue;
110 [ # # ][ # # ]: 0 : }
111 : :
112 : : // prevent outside code against NoSuchElementException!
113 : : // But dont implement such defensive strategy for our new create handling :-)
114 [ # # ][ # # ]: 0 : if (!m_rCache->hasItem(FilterCache::E_CONTENTHANDLER, sRealHandler))
[ # # ]
115 [ # # ][ # # ]: 0 : return css::uno::Reference< css::uno::XInterface>();
[ # # ][ # # ]
[ # # ]
116 : : }
117 : :
118 : : /* <- HACK */
119 : :
120 : : #endif // _FILTER_CONFIG_MIGRATION_Q_
121 : :
122 : : // search handler on cache
123 [ + - ][ + - ]: 4 : CacheItem aHandler = m_rCache->getItem(FilterCache::E_CONTENTHANDLER, sRealHandler);
124 : :
125 : : // create service instance
126 [ + - ][ + - ]: 4 : xHandler = m_xSMGR->createInstance(sRealHandler);
[ + - ]
127 : :
128 : : // initialize filter
129 [ + - ]: 4 : css::uno::Reference< css::lang::XInitialization > xInit(xHandler, css::uno::UNO_QUERY);
130 [ - + ]: 4 : if (xInit.is())
131 : : {
132 : : // format: lInitData[0] = seq<PropertyValue>, which contains all configuration properties of this handler
133 : : // lInitData[1] = lArguments[0]
134 : : // ...
135 : : // lInitData[n] = lArguments[n-1]
136 [ # # ]: 0 : css::uno::Sequence< css::beans::PropertyValue > lConfig;
137 [ # # ]: 0 : aHandler >> lConfig;
138 : :
139 [ # # ]: 0 : ::comphelper::SequenceAsVector< css::uno::Any > stlArguments(lArguments);
140 [ # # ][ # # ]: 0 : stlArguments.insert(stlArguments.begin(), css::uno::makeAny(lConfig));
141 : :
142 [ # # ]: 0 : css::uno::Sequence< css::uno::Any > lInitData;
143 [ # # ]: 0 : stlArguments >> lInitData;
144 : :
145 [ # # ][ # # ]: 0 : xInit->initialize(lInitData);
[ # # ][ # # ]
146 : : }
147 : :
148 [ + - ][ + - ]: 4 : return xHandler;
149 : : // <- SAFE
150 : : }
151 : :
152 : :
153 : :
154 : 2 : css::uno::Sequence< ::rtl::OUString > SAL_CALL ContentHandlerFactory::getAvailableServiceNames()
155 : : throw(css::uno::RuntimeException)
156 : : {
157 : : // must be the same list as ((XNameAccess*)this)->getElementNames() return!
158 : 2 : return getElementNames();
159 : : }
160 : :
161 : :
162 : :
163 : 683 : ::rtl::OUString ContentHandlerFactory::impl_getImplementationName()
164 : : {
165 : 683 : return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.filter.config.ContentHandlerFactory" ));
166 : : }
167 : :
168 : :
169 : :
170 : 171 : css::uno::Sequence< ::rtl::OUString > ContentHandlerFactory::impl_getSupportedServiceNames()
171 : : {
172 : 171 : css::uno::Sequence< ::rtl::OUString > lServiceNames(1);
173 [ + - ][ + - ]: 171 : lServiceNames[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.ContentHandlerFactory" ));
174 : 171 : return lServiceNames;
175 : : }
176 : :
177 : :
178 : :
179 : 153 : css::uno::Reference< css::uno::XInterface > SAL_CALL ContentHandlerFactory::impl_createInstance(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR)
180 : : {
181 [ + - ]: 153 : ContentHandlerFactory* pNew = new ContentHandlerFactory(xSMGR);
182 [ + - ]: 153 : return css::uno::Reference< css::uno::XInterface >(static_cast< css::lang::XMultiServiceFactory* >(pNew), css::uno::UNO_QUERY);
183 : : }
184 : :
185 : : } // namespace config
186 : : } // namespace filter
187 : :
188 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|