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