1*9b5730f6SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*9b5730f6SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*9b5730f6SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*9b5730f6SAndrew Rist * distributed with this work for additional information
6*9b5730f6SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*9b5730f6SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*9b5730f6SAndrew Rist * "License"); you may not use this file except in compliance
9*9b5730f6SAndrew Rist * with the License. You may obtain a copy of the License at
10*9b5730f6SAndrew Rist *
11*9b5730f6SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*9b5730f6SAndrew Rist *
13*9b5730f6SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*9b5730f6SAndrew Rist * software distributed under the License is distributed on an
15*9b5730f6SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9b5730f6SAndrew Rist * KIND, either express or implied. See the License for the
17*9b5730f6SAndrew Rist * specific language governing permissions and limitations
18*9b5730f6SAndrew Rist * under the License.
19*9b5730f6SAndrew Rist *
20*9b5730f6SAndrew Rist *************************************************************/
21*9b5730f6SAndrew Rist
22*9b5730f6SAndrew Rist
23cdf0e10cSrcweir #include "connectivity/DriversConfig.hxx"
24cdf0e10cSrcweir #include <tools/wldcrd.hxx>
25cdf0e10cSrcweir
26cdf0e10cSrcweir using namespace connectivity;
27cdf0e10cSrcweir using namespace utl;
28cdf0e10cSrcweir using namespace ::com::sun::star;
29cdf0e10cSrcweir
30cdf0e10cSrcweir namespace
31cdf0e10cSrcweir {
lcl_convert(const uno::Sequence<::rtl::OUString> & _aSource,uno::Any & _rDest)32cdf0e10cSrcweir void lcl_convert(const uno::Sequence< ::rtl::OUString >& _aSource,uno::Any& _rDest)
33cdf0e10cSrcweir {
34cdf0e10cSrcweir uno::Sequence<uno::Any> aRet(_aSource.getLength());
35cdf0e10cSrcweir uno::Any* pAny = aRet.getArray();
36cdf0e10cSrcweir const ::rtl::OUString* pIter = _aSource.getConstArray();
37cdf0e10cSrcweir const ::rtl::OUString* pEnd = pIter + _aSource.getLength();
38cdf0e10cSrcweir for (;pIter != pEnd ; ++pIter,++pAny)
39cdf0e10cSrcweir {
40cdf0e10cSrcweir *pAny <<= *pIter;
41cdf0e10cSrcweir }
42cdf0e10cSrcweir _rDest <<= aRet;
43cdf0e10cSrcweir }
lcl_fillValues(const::utl::OConfigurationNode & _aURLPatternNode,const::rtl::OUString & _sNode,::comphelper::NamedValueCollection & _rValues)44cdf0e10cSrcweir void lcl_fillValues(const ::utl::OConfigurationNode& _aURLPatternNode,const ::rtl::OUString& _sNode,::comphelper::NamedValueCollection& _rValues)
45cdf0e10cSrcweir {
46cdf0e10cSrcweir const ::utl::OConfigurationNode aPropertiesNode = _aURLPatternNode.openNode(_sNode);
47cdf0e10cSrcweir if ( aPropertiesNode.isValid() )
48cdf0e10cSrcweir {
49cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > aStringSeq;
50cdf0e10cSrcweir static const ::rtl::OUString s_sValue(RTL_CONSTASCII_USTRINGPARAM("/Value"));
51cdf0e10cSrcweir const uno::Sequence< ::rtl::OUString > aProperties = aPropertiesNode.getNodeNames();
52cdf0e10cSrcweir const ::rtl::OUString* pPropertiesIter = aProperties.getConstArray();
53cdf0e10cSrcweir const ::rtl::OUString* pPropertiesEnd = pPropertiesIter + aProperties.getLength();
54cdf0e10cSrcweir for (;pPropertiesIter != pPropertiesEnd ; ++pPropertiesIter)
55cdf0e10cSrcweir {
56cdf0e10cSrcweir uno::Any aValue = aPropertiesNode.getNodeValue(*pPropertiesIter + s_sValue);
57cdf0e10cSrcweir if ( aValue >>= aStringSeq )
58cdf0e10cSrcweir {
59cdf0e10cSrcweir lcl_convert(aStringSeq,aValue);
60cdf0e10cSrcweir }
61cdf0e10cSrcweir _rValues.put(*pPropertiesIter,aValue);
62cdf0e10cSrcweir } // for (;pPropertiesIter != pPropertiesEnd ; ++pPropertiesIter,++pNamedIter)
63cdf0e10cSrcweir } // if ( aPropertiesNode.isValid() )
64cdf0e10cSrcweir }
lcl_readURLPatternNode(const::utl::OConfigurationTreeRoot & _aInstalled,const::rtl::OUString & _sEntry,TInstalledDriver & _rInstalledDriver)65cdf0e10cSrcweir void lcl_readURLPatternNode(const ::utl::OConfigurationTreeRoot& _aInstalled,const ::rtl::OUString& _sEntry,TInstalledDriver& _rInstalledDriver)
66cdf0e10cSrcweir {
67cdf0e10cSrcweir const ::utl::OConfigurationNode aURLPatternNode = _aInstalled.openNode(_sEntry);
68cdf0e10cSrcweir if ( aURLPatternNode.isValid() )
69cdf0e10cSrcweir {
70cdf0e10cSrcweir static const ::rtl::OUString s_sParentURLPattern(RTL_CONSTASCII_USTRINGPARAM("ParentURLPattern"));
71cdf0e10cSrcweir static const ::rtl::OUString s_sDriver(RTL_CONSTASCII_USTRINGPARAM("Driver"));
72cdf0e10cSrcweir static const ::rtl::OUString s_sDriverTypeDisplayName(RTL_CONSTASCII_USTRINGPARAM("DriverTypeDisplayName"));
73cdf0e10cSrcweir static const ::rtl::OUString s_sProperties(RTL_CONSTASCII_USTRINGPARAM("Properties"));
74cdf0e10cSrcweir static const ::rtl::OUString s_sFeatures(RTL_CONSTASCII_USTRINGPARAM("Features"));
75cdf0e10cSrcweir static const ::rtl::OUString s_sMetaData(RTL_CONSTASCII_USTRINGPARAM("MetaData"));
76cdf0e10cSrcweir ::rtl::OUString sParentURLPattern;
77cdf0e10cSrcweir aURLPatternNode.getNodeValue(s_sParentURLPattern) >>= sParentURLPattern;
78cdf0e10cSrcweir if ( sParentURLPattern.getLength() )
79cdf0e10cSrcweir lcl_readURLPatternNode(_aInstalled,sParentURLPattern,_rInstalledDriver);
80cdf0e10cSrcweir
81cdf0e10cSrcweir ::rtl::OUString sDriverFactory;
82cdf0e10cSrcweir aURLPatternNode.getNodeValue(s_sDriver) >>= sDriverFactory;
83cdf0e10cSrcweir if ( sDriverFactory.getLength() )
84cdf0e10cSrcweir _rInstalledDriver.sDriverFactory = sDriverFactory;
85cdf0e10cSrcweir
86cdf0e10cSrcweir ::rtl::OUString sDriverTypeDisplayName;
87cdf0e10cSrcweir aURLPatternNode.getNodeValue(s_sDriverTypeDisplayName) >>= sDriverTypeDisplayName;
88cdf0e10cSrcweir OSL_ENSURE(sDriverTypeDisplayName.getLength(),"No valid DriverTypeDisplayName property!");
89cdf0e10cSrcweir if ( sDriverTypeDisplayName.getLength() )
90cdf0e10cSrcweir _rInstalledDriver.sDriverTypeDisplayName = sDriverTypeDisplayName;
91cdf0e10cSrcweir
92cdf0e10cSrcweir lcl_fillValues(aURLPatternNode,s_sProperties,_rInstalledDriver.aProperties);
93cdf0e10cSrcweir lcl_fillValues(aURLPatternNode,s_sFeatures,_rInstalledDriver.aFeatures);
94cdf0e10cSrcweir lcl_fillValues(aURLPatternNode,s_sMetaData,_rInstalledDriver.aMetaData);
95cdf0e10cSrcweir }
96cdf0e10cSrcweir }
97cdf0e10cSrcweir }
98cdf0e10cSrcweir // -----------------------------------------------------------------------------
DriversConfigImpl()99cdf0e10cSrcweir DriversConfigImpl::DriversConfigImpl()
100cdf0e10cSrcweir {
101cdf0e10cSrcweir }
102cdf0e10cSrcweir // -----------------------------------------------------------------------------
Load(const uno::Reference<lang::XMultiServiceFactory> & _rxORB) const103cdf0e10cSrcweir void DriversConfigImpl::Load(const uno::Reference< lang::XMultiServiceFactory >& _rxORB) const
104cdf0e10cSrcweir {
105cdf0e10cSrcweir if ( m_aDrivers.empty() )
106cdf0e10cSrcweir {
107cdf0e10cSrcweir if ( !m_aInstalled.isValid() )
108cdf0e10cSrcweir {
109cdf0e10cSrcweir static const ::rtl::OUString s_sNodeName(RTL_CONSTASCII_USTRINGPARAM("org.openoffice.Office.DataAccess.Drivers/Installed")); ///Installed
110cdf0e10cSrcweir m_aInstalled = ::utl::OConfigurationTreeRoot::createWithServiceFactory(_rxORB, s_sNodeName, -1, ::utl::OConfigurationTreeRoot::CM_READONLY);
111cdf0e10cSrcweir }
112cdf0e10cSrcweir
113cdf0e10cSrcweir if ( m_aInstalled.isValid() )
114cdf0e10cSrcweir {
115cdf0e10cSrcweir const uno::Sequence< ::rtl::OUString > aURLPatterns = m_aInstalled.getNodeNames();
116cdf0e10cSrcweir const ::rtl::OUString* pPatternIter = aURLPatterns.getConstArray();
117cdf0e10cSrcweir const ::rtl::OUString* pPatternEnd = pPatternIter + aURLPatterns.getLength();
118cdf0e10cSrcweir for (;pPatternIter != pPatternEnd ; ++pPatternIter)
119cdf0e10cSrcweir {
120cdf0e10cSrcweir TInstalledDriver aInstalledDriver;
121cdf0e10cSrcweir lcl_readURLPatternNode(m_aInstalled,*pPatternIter,aInstalledDriver);
122cdf0e10cSrcweir if ( aInstalledDriver.sDriverFactory.getLength() )
123cdf0e10cSrcweir m_aDrivers.insert(TInstalledDrivers::value_type(*pPatternIter,aInstalledDriver));
124cdf0e10cSrcweir }
125cdf0e10cSrcweir } // if ( m_aInstalled.isValid() )
126cdf0e10cSrcweir }
127cdf0e10cSrcweir }
128cdf0e10cSrcweir // -----------------------------------------------------------------------------
DriversConfig(const uno::Reference<lang::XMultiServiceFactory> & _rxORB)129cdf0e10cSrcweir DriversConfig::DriversConfig(const uno::Reference< lang::XMultiServiceFactory >& _rxORB)
130cdf0e10cSrcweir :m_xORB(_rxORB)
131cdf0e10cSrcweir {
132cdf0e10cSrcweir }
133cdf0e10cSrcweir
134cdf0e10cSrcweir // -----------------------------------------------------------------------------
~DriversConfig()135cdf0e10cSrcweir DriversConfig::~DriversConfig()
136cdf0e10cSrcweir {
137cdf0e10cSrcweir }
138cdf0e10cSrcweir
139cdf0e10cSrcweir // -----------------------------------------------------------------------------
DriversConfig(const DriversConfig & _rhs)140cdf0e10cSrcweir DriversConfig::DriversConfig( const DriversConfig& _rhs )
141cdf0e10cSrcweir {
142cdf0e10cSrcweir *this = _rhs;
143cdf0e10cSrcweir }
144cdf0e10cSrcweir
145cdf0e10cSrcweir // -----------------------------------------------------------------------------
operator =(const DriversConfig & _rhs)146cdf0e10cSrcweir DriversConfig& DriversConfig::operator=( const DriversConfig& _rhs )
147cdf0e10cSrcweir {
148cdf0e10cSrcweir if ( this != &_rhs )
149cdf0e10cSrcweir {
150cdf0e10cSrcweir m_aNode = _rhs.m_aNode;
151cdf0e10cSrcweir }
152cdf0e10cSrcweir return *this;
153cdf0e10cSrcweir }
154cdf0e10cSrcweir
155cdf0e10cSrcweir // -----------------------------------------------------------------------------
getDriverFactoryName(const::rtl::OUString & _sURL) const156cdf0e10cSrcweir ::rtl::OUString DriversConfig::getDriverFactoryName(const ::rtl::OUString& _sURL) const
157cdf0e10cSrcweir {
158cdf0e10cSrcweir const TInstalledDrivers& rDrivers = m_aNode->getInstalledDrivers(m_xORB);
159cdf0e10cSrcweir ::rtl::OUString sRet;
160cdf0e10cSrcweir ::rtl::OUString sOldPattern;
161cdf0e10cSrcweir TInstalledDrivers::const_iterator aIter = rDrivers.begin();
162cdf0e10cSrcweir TInstalledDrivers::const_iterator aEnd = rDrivers.end();
163cdf0e10cSrcweir for(;aIter != aEnd;++aIter)
164cdf0e10cSrcweir {
165cdf0e10cSrcweir WildCard aWildCard(aIter->first);
166cdf0e10cSrcweir if ( sOldPattern.getLength() < aIter->first.getLength() && aWildCard.Matches(_sURL) )
167cdf0e10cSrcweir {
168cdf0e10cSrcweir sRet = aIter->second.sDriverFactory;
169cdf0e10cSrcweir sOldPattern = aIter->first;
170cdf0e10cSrcweir }
171cdf0e10cSrcweir }
172cdf0e10cSrcweir
173cdf0e10cSrcweir return sRet;
174cdf0e10cSrcweir }
175cdf0e10cSrcweir // -----------------------------------------------------------------------------
getDriverTypeDisplayName(const::rtl::OUString & _sURL) const176cdf0e10cSrcweir ::rtl::OUString DriversConfig::getDriverTypeDisplayName(const ::rtl::OUString& _sURL) const
177cdf0e10cSrcweir {
178cdf0e10cSrcweir const TInstalledDrivers& rDrivers = m_aNode->getInstalledDrivers(m_xORB);
179cdf0e10cSrcweir ::rtl::OUString sRet;
180cdf0e10cSrcweir ::rtl::OUString sOldPattern;
181cdf0e10cSrcweir TInstalledDrivers::const_iterator aIter = rDrivers.begin();
182cdf0e10cSrcweir TInstalledDrivers::const_iterator aEnd = rDrivers.end();
183cdf0e10cSrcweir for(;aIter != aEnd;++aIter)
184cdf0e10cSrcweir {
185cdf0e10cSrcweir WildCard aWildCard(aIter->first);
186cdf0e10cSrcweir if ( sOldPattern.getLength() < aIter->first.getLength() && aWildCard.Matches(_sURL) )
187cdf0e10cSrcweir {
188cdf0e10cSrcweir sRet = aIter->second.sDriverTypeDisplayName;
189cdf0e10cSrcweir sOldPattern = aIter->first;
190cdf0e10cSrcweir }
191cdf0e10cSrcweir }
192cdf0e10cSrcweir
193cdf0e10cSrcweir return sRet;
194cdf0e10cSrcweir }
195cdf0e10cSrcweir // -----------------------------------------------------------------------------
getProperties(const::rtl::OUString & _sURL) const196cdf0e10cSrcweir const ::comphelper::NamedValueCollection& DriversConfig::getProperties(const ::rtl::OUString& _sURL) const
197cdf0e10cSrcweir {
198cdf0e10cSrcweir return impl_get(_sURL,1);
199cdf0e10cSrcweir }
200cdf0e10cSrcweir // -----------------------------------------------------------------------------
getFeatures(const::rtl::OUString & _sURL) const201cdf0e10cSrcweir const ::comphelper::NamedValueCollection& DriversConfig::getFeatures(const ::rtl::OUString& _sURL) const
202cdf0e10cSrcweir {
203cdf0e10cSrcweir return impl_get(_sURL,0);
204cdf0e10cSrcweir }
205cdf0e10cSrcweir // -----------------------------------------------------------------------------
getMetaData(const::rtl::OUString & _sURL) const206cdf0e10cSrcweir const ::comphelper::NamedValueCollection& DriversConfig::getMetaData(const ::rtl::OUString& _sURL) const
207cdf0e10cSrcweir {
208cdf0e10cSrcweir return impl_get(_sURL,2);
209cdf0e10cSrcweir }
210cdf0e10cSrcweir // -----------------------------------------------------------------------------
impl_get(const::rtl::OUString & _sURL,sal_Int32 _nProps) const211cdf0e10cSrcweir const ::comphelper::NamedValueCollection& DriversConfig::impl_get(const ::rtl::OUString& _sURL,sal_Int32 _nProps) const
212cdf0e10cSrcweir {
213cdf0e10cSrcweir const TInstalledDrivers& rDrivers = m_aNode->getInstalledDrivers(m_xORB);
214cdf0e10cSrcweir const ::comphelper::NamedValueCollection* pRet = NULL;
215cdf0e10cSrcweir ::rtl::OUString sOldPattern;
216cdf0e10cSrcweir TInstalledDrivers::const_iterator aIter = rDrivers.begin();
217cdf0e10cSrcweir TInstalledDrivers::const_iterator aEnd = rDrivers.end();
218cdf0e10cSrcweir for(;aIter != aEnd;++aIter)
219cdf0e10cSrcweir {
220cdf0e10cSrcweir WildCard aWildCard(aIter->first);
221cdf0e10cSrcweir if ( sOldPattern.getLength() < aIter->first.getLength() && aWildCard.Matches(_sURL) )
222cdf0e10cSrcweir {
223cdf0e10cSrcweir switch(_nProps)
224cdf0e10cSrcweir {
225cdf0e10cSrcweir case 0:
226cdf0e10cSrcweir pRet = &aIter->second.aFeatures;
227cdf0e10cSrcweir break;
228cdf0e10cSrcweir case 1:
229cdf0e10cSrcweir pRet = &aIter->second.aProperties;
230cdf0e10cSrcweir break;
231cdf0e10cSrcweir case 2:
232cdf0e10cSrcweir pRet = &aIter->second.aMetaData;
233cdf0e10cSrcweir break;
234cdf0e10cSrcweir }
235cdf0e10cSrcweir sOldPattern = aIter->first;
236cdf0e10cSrcweir }
237cdf0e10cSrcweir } // for(;aIter != aEnd;++aIter)
238cdf0e10cSrcweir if ( pRet == NULL )
239cdf0e10cSrcweir {
240cdf0e10cSrcweir static const ::comphelper::NamedValueCollection s_sEmpty;
241cdf0e10cSrcweir pRet = &s_sEmpty;
242cdf0e10cSrcweir }
243cdf0e10cSrcweir return *pRet;
244cdf0e10cSrcweir }
245cdf0e10cSrcweir // -----------------------------------------------------------------------------
getURLs() const246cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > DriversConfig::getURLs() const
247cdf0e10cSrcweir {
248cdf0e10cSrcweir const TInstalledDrivers& rDrivers = m_aNode->getInstalledDrivers(m_xORB);
249cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > aRet(rDrivers.size());
250cdf0e10cSrcweir ::rtl::OUString* pIter = aRet.getArray();
251cdf0e10cSrcweir TInstalledDrivers::const_iterator aIter = rDrivers.begin();
252cdf0e10cSrcweir TInstalledDrivers::const_iterator aEnd = rDrivers.end();
253cdf0e10cSrcweir for(;aIter != aEnd;++aIter,++pIter)
254cdf0e10cSrcweir {
255cdf0e10cSrcweir *pIter = aIter->first;
256cdf0e10cSrcweir }
257cdf0e10cSrcweir return aRet;
258cdf0e10cSrcweir }
259