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 : #include <connectivity/DriversConfig.hxx>
20 : #include <tools/wldcrd.hxx>
21 : #include <svtools/miscopt.hxx>
22 :
23 : using namespace connectivity;
24 : using namespace utl;
25 : using namespace ::com::sun::star;
26 :
27 : namespace
28 : {
29 74 : void lcl_convert(const uno::Sequence< OUString >& _aSource,uno::Any& _rDest)
30 : {
31 74 : uno::Sequence<uno::Any> aRet(_aSource.getLength());
32 74 : uno::Any* pAny = aRet.getArray();
33 74 : const OUString* pIter = _aSource.getConstArray();
34 74 : const OUString* pEnd = pIter + _aSource.getLength();
35 1258 : for (;pIter != pEnd ; ++pIter,++pAny)
36 : {
37 1184 : *pAny <<= *pIter;
38 : }
39 74 : _rDest <<= aRet;
40 74 : }
41 3330 : void lcl_fillValues(const ::utl::OConfigurationNode& _aURLPatternNode,const OUString& _sNode,::comphelper::NamedValueCollection& _rValues)
42 : {
43 3330 : const ::utl::OConfigurationNode aPropertiesNode = _aURLPatternNode.openNode(_sNode);
44 3330 : if ( aPropertiesNode.isValid() )
45 : {
46 3330 : uno::Sequence< OUString > aStringSeq;
47 3330 : static const OUString s_sValue("/Value");
48 6660 : const uno::Sequence< OUString > aProperties = aPropertiesNode.getNodeNames();
49 3330 : const OUString* pPropertiesIter = aProperties.getConstArray();
50 3330 : const OUString* pPropertiesEnd = pPropertiesIter + aProperties.getLength();
51 16058 : for (;pPropertiesIter != pPropertiesEnd ; ++pPropertiesIter)
52 : {
53 12728 : uno::Any aValue = aPropertiesNode.getNodeValue(*pPropertiesIter + s_sValue);
54 12728 : if ( aValue >>= aStringSeq )
55 : {
56 74 : lcl_convert(aStringSeq,aValue);
57 : }
58 12728 : _rValues.put(*pPropertiesIter,aValue);
59 16058 : } // for (;pPropertiesIter != pPropertiesEnd ; ++pPropertiesIter,++pNamedIter)
60 3330 : } // if ( aPropertiesNode.isValid() )
61 3330 : }
62 1110 : void lcl_readURLPatternNode(const ::utl::OConfigurationTreeRoot& _aInstalled,const OUString& _sEntry,TInstalledDriver& _rInstalledDriver)
63 : {
64 1110 : const ::utl::OConfigurationNode aURLPatternNode = _aInstalled.openNode(_sEntry);
65 1110 : if ( aURLPatternNode.isValid() )
66 : {
67 1110 : OUString sParentURLPattern;
68 1110 : aURLPatternNode.getNodeValue("ParentURLPattern") >>= sParentURLPattern;
69 1110 : if ( !sParentURLPattern.isEmpty() )
70 74 : lcl_readURLPatternNode(_aInstalled,sParentURLPattern,_rInstalledDriver);
71 :
72 2220 : OUString sDriverFactory;
73 1110 : aURLPatternNode.getNodeValue("Driver") >>= sDriverFactory;
74 1110 : if ( !sDriverFactory.isEmpty() )
75 1036 : _rInstalledDriver.sDriverFactory = sDriverFactory;
76 :
77 2220 : OUString sDriverTypeDisplayName;
78 1110 : aURLPatternNode.getNodeValue("DriverTypeDisplayName") >>= sDriverTypeDisplayName;
79 : OSL_ENSURE(!sDriverTypeDisplayName.isEmpty(),"No valid DriverTypeDisplayName property!");
80 1110 : if ( !sDriverTypeDisplayName.isEmpty() )
81 1110 : _rInstalledDriver.sDriverTypeDisplayName = sDriverTypeDisplayName;
82 :
83 1110 : lcl_fillValues(aURLPatternNode,"Properties",_rInstalledDriver.aProperties);
84 1110 : lcl_fillValues(aURLPatternNode,"Features",_rInstalledDriver.aFeatures);
85 2220 : lcl_fillValues(aURLPatternNode,"MetaData",_rInstalledDriver.aMetaData);
86 1110 : }
87 1110 : }
88 : }
89 :
90 78 : DriversConfigImpl::DriversConfigImpl()
91 : {
92 78 : }
93 :
94 6806 : void DriversConfigImpl::Load(const uno::Reference< uno::XComponentContext >& _rxORB) const
95 : {
96 6806 : if ( m_aDrivers.empty() )
97 : {
98 74 : if ( !m_aInstalled.isValid() )
99 : {
100 74 : static const OUString s_sNodeName("org.openoffice.Office.DataAccess.Drivers/Installed"); ///Installed
101 74 : m_aInstalled = ::utl::OConfigurationTreeRoot::createWithComponentContext(_rxORB, s_sNodeName, -1, ::utl::OConfigurationTreeRoot::CM_READONLY);
102 : }
103 :
104 74 : if ( m_aInstalled.isValid() )
105 : {
106 74 : SvtMiscOptions aMiscOptions;
107 :
108 148 : const uno::Sequence< OUString > aURLPatterns = m_aInstalled.getNodeNames();
109 74 : const OUString* pPatternIter = aURLPatterns.getConstArray();
110 74 : const OUString* pPatternEnd = pPatternIter + aURLPatterns.getLength();
111 1110 : for (;pPatternIter != pPatternEnd ; ++pPatternIter)
112 : {
113 1036 : TInstalledDriver aInstalledDriver;
114 1036 : lcl_readURLPatternNode(m_aInstalled,*pPatternIter,aInstalledDriver);
115 4060 : if ( !aInstalledDriver.sDriverFactory.isEmpty() &&
116 2996 : ( aMiscOptions.IsExperimentalMode() ||
117 3976 : !aInstalledDriver.sDriverFactory.equals("com.sun.star.comp.sdbc.firebird.Driver") ))
118 896 : m_aDrivers.insert(TInstalledDrivers::value_type(*pPatternIter,aInstalledDriver));
119 1110 : }
120 : } // if ( m_aInstalled.isValid() )
121 : }
122 6806 : }
123 :
124 4595 : DriversConfig::DriversConfig(const uno::Reference< uno::XComponentContext >& _rxORB)
125 4595 : :m_xORB(_rxORB)
126 : {
127 4595 : }
128 :
129 :
130 25190 : DriversConfig::~DriversConfig()
131 : {
132 25190 : }
133 :
134 :
135 20617 : DriversConfig::DriversConfig( const DriversConfig& _rhs )
136 : {
137 20617 : *this = _rhs;
138 20617 : }
139 :
140 :
141 20617 : DriversConfig& DriversConfig::operator=( const DriversConfig& _rhs )
142 : {
143 : if ( this != &_rhs )
144 : {
145 : m_aNode = _rhs.m_aNode;
146 : }
147 20617 : return *this;
148 : }
149 :
150 :
151 216 : OUString DriversConfig::getDriverFactoryName(const OUString& _sURL) const
152 : {
153 216 : const TInstalledDrivers& rDrivers = m_aNode->getInstalledDrivers(m_xORB);
154 216 : OUString sRet;
155 432 : OUString sOldPattern;
156 216 : TInstalledDrivers::const_iterator aIter = rDrivers.begin();
157 216 : TInstalledDrivers::const_iterator aEnd = rDrivers.end();
158 2832 : for(;aIter != aEnd;++aIter)
159 : {
160 2616 : WildCard aWildCard(aIter->first);
161 2616 : if ( sOldPattern.getLength() < aIter->first.getLength() && aWildCard.Matches(_sURL) )
162 : {
163 216 : sRet = aIter->second.sDriverFactory;
164 216 : sOldPattern = aIter->first;
165 : }
166 2616 : }
167 :
168 432 : return sRet;
169 : }
170 :
171 5334 : OUString DriversConfig::getDriverTypeDisplayName(const OUString& _sURL) const
172 : {
173 5334 : const TInstalledDrivers& rDrivers = m_aNode->getInstalledDrivers(m_xORB);
174 5334 : OUString sRet;
175 10668 : OUString sOldPattern;
176 5334 : TInstalledDrivers::const_iterator aIter = rDrivers.begin();
177 5334 : TInstalledDrivers::const_iterator aEnd = rDrivers.end();
178 69566 : for(;aIter != aEnd;++aIter)
179 : {
180 64232 : WildCard aWildCard(aIter->first);
181 64232 : if ( sOldPattern.getLength() < aIter->first.getLength() && aWildCard.Matches(_sURL) )
182 : {
183 5776 : sRet = aIter->second.sDriverTypeDisplayName;
184 5776 : sOldPattern = aIter->first;
185 : }
186 64232 : }
187 :
188 10668 : return sRet;
189 : }
190 :
191 218 : const ::comphelper::NamedValueCollection& DriversConfig::getProperties(const OUString& _sURL) const
192 : {
193 218 : return impl_get(_sURL,1);
194 : }
195 :
196 72 : const ::comphelper::NamedValueCollection& DriversConfig::getFeatures(const OUString& _sURL) const
197 : {
198 72 : return impl_get(_sURL,0);
199 : }
200 :
201 500 : const ::comphelper::NamedValueCollection& DriversConfig::getMetaData(const OUString& _sURL) const
202 : {
203 500 : return impl_get(_sURL,2);
204 : }
205 :
206 790 : const ::comphelper::NamedValueCollection& DriversConfig::impl_get(const OUString& _sURL,sal_Int32 _nProps) const
207 : {
208 790 : const TInstalledDrivers& rDrivers = m_aNode->getInstalledDrivers(m_xORB);
209 790 : const ::comphelper::NamedValueCollection* pRet = NULL;
210 790 : OUString sOldPattern;
211 790 : TInstalledDrivers::const_iterator aIter = rDrivers.begin();
212 790 : TInstalledDrivers::const_iterator aEnd = rDrivers.end();
213 10286 : for(;aIter != aEnd;++aIter)
214 : {
215 9496 : WildCard aWildCard(aIter->first);
216 9496 : if ( sOldPattern.getLength() < aIter->first.getLength() && aWildCard.Matches(_sURL) )
217 : {
218 814 : switch(_nProps)
219 : {
220 : case 0:
221 78 : pRet = &aIter->second.aFeatures;
222 78 : break;
223 : case 1:
224 218 : pRet = &aIter->second.aProperties;
225 218 : break;
226 : case 2:
227 518 : pRet = &aIter->second.aMetaData;
228 518 : break;
229 : }
230 814 : sOldPattern = aIter->first;
231 : }
232 9496 : } // for(;aIter != aEnd;++aIter)
233 790 : if ( pRet == NULL )
234 : {
235 0 : static const ::comphelper::NamedValueCollection s_sEmpty;
236 0 : pRet = &s_sEmpty;
237 : }
238 790 : return *pRet;
239 : }
240 :
241 466 : uno::Sequence< OUString > DriversConfig::getURLs() const
242 : {
243 466 : const TInstalledDrivers& rDrivers = m_aNode->getInstalledDrivers(m_xORB);
244 466 : uno::Sequence< OUString > aRet(rDrivers.size());
245 466 : OUString* pIter = aRet.getArray();
246 466 : TInstalledDrivers::const_iterator aIter = rDrivers.begin();
247 466 : TInstalledDrivers::const_iterator aEnd = rDrivers.end();
248 6074 : for(;aIter != aEnd;++aIter,++pIter)
249 : {
250 5608 : *pIter = aIter->first;
251 : }
252 466 : return aRet;
253 : }
254 :
255 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|