1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #include "connectivity/DriversConfig.hxx"
20 #include <tools/wldcrd.hxx>
22 using namespace connectivity
;
24 using namespace ::com::sun::star
;
28 void lcl_convert(const uno::Sequence
< OUString
>& _aSource
,uno::Any
& _rDest
)
30 uno::Sequence
<uno::Any
> aRet(_aSource
.getLength());
31 uno::Any
* pAny
= aRet
.getArray();
32 const OUString
* pIter
= _aSource
.getConstArray();
33 const OUString
* pEnd
= pIter
+ _aSource
.getLength();
34 for (;pIter
!= pEnd
; ++pIter
,++pAny
)
40 void lcl_fillValues(const ::utl::OConfigurationNode
& _aURLPatternNode
,const OUString
& _sNode
,::comphelper::NamedValueCollection
& _rValues
)
42 const ::utl::OConfigurationNode aPropertiesNode
= _aURLPatternNode
.openNode(_sNode
);
43 if ( aPropertiesNode
.isValid() )
45 uno::Sequence
< OUString
> aStringSeq
;
46 static const OUString
s_sValue("/Value");
47 const uno::Sequence
< OUString
> aProperties
= aPropertiesNode
.getNodeNames();
48 const OUString
* pPropertiesIter
= aProperties
.getConstArray();
49 const OUString
* pPropertiesEnd
= pPropertiesIter
+ aProperties
.getLength();
50 for (;pPropertiesIter
!= pPropertiesEnd
; ++pPropertiesIter
)
52 uno::Any aValue
= aPropertiesNode
.getNodeValue(*pPropertiesIter
+ s_sValue
);
53 if ( aValue
>>= aStringSeq
)
55 lcl_convert(aStringSeq
,aValue
);
57 _rValues
.put(*pPropertiesIter
,aValue
);
58 } // for (;pPropertiesIter != pPropertiesEnd ; ++pPropertiesIter,++pNamedIter)
59 } // if ( aPropertiesNode.isValid() )
61 void lcl_readURLPatternNode(const ::utl::OConfigurationTreeRoot
& _aInstalled
,const OUString
& _sEntry
,TInstalledDriver
& _rInstalledDriver
)
63 const ::utl::OConfigurationNode aURLPatternNode
= _aInstalled
.openNode(_sEntry
);
64 if ( aURLPatternNode
.isValid() )
66 OUString sParentURLPattern
;
67 aURLPatternNode
.getNodeValue("ParentURLPattern") >>= sParentURLPattern
;
68 if ( !sParentURLPattern
.isEmpty() )
69 lcl_readURLPatternNode(_aInstalled
,sParentURLPattern
,_rInstalledDriver
);
71 OUString sDriverFactory
;
72 aURLPatternNode
.getNodeValue("Driver") >>= sDriverFactory
;
73 if ( !sDriverFactory
.isEmpty() )
74 _rInstalledDriver
.sDriverFactory
= sDriverFactory
;
76 OUString sDriverTypeDisplayName
;
77 aURLPatternNode
.getNodeValue("DriverTypeDisplayName") >>= sDriverTypeDisplayName
;
78 OSL_ENSURE(!sDriverTypeDisplayName
.isEmpty(),"No valid DriverTypeDisplayName property!");
79 if ( !sDriverTypeDisplayName
.isEmpty() )
80 _rInstalledDriver
.sDriverTypeDisplayName
= sDriverTypeDisplayName
;
82 lcl_fillValues(aURLPatternNode
,"Properties",_rInstalledDriver
.aProperties
);
83 lcl_fillValues(aURLPatternNode
,"Features",_rInstalledDriver
.aFeatures
);
84 lcl_fillValues(aURLPatternNode
,"MetaData",_rInstalledDriver
.aMetaData
);
88 // -----------------------------------------------------------------------------
89 DriversConfigImpl::DriversConfigImpl()
92 // -----------------------------------------------------------------------------
93 void DriversConfigImpl::Load(const uno::Reference
< uno::XComponentContext
>& _rxORB
) const
95 if ( m_aDrivers
.empty() )
97 if ( !m_aInstalled
.isValid() )
99 static const OUString
s_sNodeName("org.openoffice.Office.DataAccess.Drivers/Installed"); ///Installed
100 m_aInstalled
= ::utl::OConfigurationTreeRoot::createWithComponentContext(_rxORB
, s_sNodeName
, -1, ::utl::OConfigurationTreeRoot::CM_READONLY
);
103 if ( m_aInstalled
.isValid() )
105 const uno::Sequence
< OUString
> aURLPatterns
= m_aInstalled
.getNodeNames();
106 const OUString
* pPatternIter
= aURLPatterns
.getConstArray();
107 const OUString
* pPatternEnd
= pPatternIter
+ aURLPatterns
.getLength();
108 for (;pPatternIter
!= pPatternEnd
; ++pPatternIter
)
110 TInstalledDriver aInstalledDriver
;
111 lcl_readURLPatternNode(m_aInstalled
,*pPatternIter
,aInstalledDriver
);
112 if ( !aInstalledDriver
.sDriverFactory
.isEmpty() )
113 m_aDrivers
.insert(TInstalledDrivers::value_type(*pPatternIter
,aInstalledDriver
));
115 } // if ( m_aInstalled.isValid() )
118 // -----------------------------------------------------------------------------
119 DriversConfig::DriversConfig(const uno::Reference
< uno::XComponentContext
>& _rxORB
)
124 // -----------------------------------------------------------------------------
125 DriversConfig::~DriversConfig()
129 // -----------------------------------------------------------------------------
130 DriversConfig::DriversConfig( const DriversConfig
& _rhs
)
135 // -----------------------------------------------------------------------------
136 DriversConfig
& DriversConfig::operator=( const DriversConfig
& _rhs
)
140 m_aNode
= _rhs
.m_aNode
;
145 // -----------------------------------------------------------------------------
146 OUString
DriversConfig::getDriverFactoryName(const OUString
& _sURL
) const
148 const TInstalledDrivers
& rDrivers
= m_aNode
->getInstalledDrivers(m_xORB
);
150 OUString sOldPattern
;
151 TInstalledDrivers::const_iterator aIter
= rDrivers
.begin();
152 TInstalledDrivers::const_iterator aEnd
= rDrivers
.end();
153 for(;aIter
!= aEnd
;++aIter
)
155 WildCard
aWildCard(aIter
->first
);
156 if ( sOldPattern
.getLength() < aIter
->first
.getLength() && aWildCard
.Matches(_sURL
) )
158 sRet
= aIter
->second
.sDriverFactory
;
159 sOldPattern
= aIter
->first
;
165 // -----------------------------------------------------------------------------
166 OUString
DriversConfig::getDriverTypeDisplayName(const OUString
& _sURL
) const
168 const TInstalledDrivers
& rDrivers
= m_aNode
->getInstalledDrivers(m_xORB
);
170 OUString sOldPattern
;
171 TInstalledDrivers::const_iterator aIter
= rDrivers
.begin();
172 TInstalledDrivers::const_iterator aEnd
= rDrivers
.end();
173 for(;aIter
!= aEnd
;++aIter
)
175 WildCard
aWildCard(aIter
->first
);
176 if ( sOldPattern
.getLength() < aIter
->first
.getLength() && aWildCard
.Matches(_sURL
) )
178 sRet
= aIter
->second
.sDriverTypeDisplayName
;
179 sOldPattern
= aIter
->first
;
185 // -----------------------------------------------------------------------------
186 const ::comphelper::NamedValueCollection
& DriversConfig::getProperties(const OUString
& _sURL
) const
188 return impl_get(_sURL
,1);
190 // -----------------------------------------------------------------------------
191 const ::comphelper::NamedValueCollection
& DriversConfig::getFeatures(const OUString
& _sURL
) const
193 return impl_get(_sURL
,0);
195 // -----------------------------------------------------------------------------
196 const ::comphelper::NamedValueCollection
& DriversConfig::getMetaData(const OUString
& _sURL
) const
198 return impl_get(_sURL
,2);
200 // -----------------------------------------------------------------------------
201 const ::comphelper::NamedValueCollection
& DriversConfig::impl_get(const OUString
& _sURL
,sal_Int32 _nProps
) const
203 const TInstalledDrivers
& rDrivers
= m_aNode
->getInstalledDrivers(m_xORB
);
204 const ::comphelper::NamedValueCollection
* pRet
= NULL
;
205 OUString sOldPattern
;
206 TInstalledDrivers::const_iterator aIter
= rDrivers
.begin();
207 TInstalledDrivers::const_iterator aEnd
= rDrivers
.end();
208 for(;aIter
!= aEnd
;++aIter
)
210 WildCard
aWildCard(aIter
->first
);
211 if ( sOldPattern
.getLength() < aIter
->first
.getLength() && aWildCard
.Matches(_sURL
) )
216 pRet
= &aIter
->second
.aFeatures
;
219 pRet
= &aIter
->second
.aProperties
;
222 pRet
= &aIter
->second
.aMetaData
;
225 sOldPattern
= aIter
->first
;
227 } // for(;aIter != aEnd;++aIter)
230 static const ::comphelper::NamedValueCollection s_sEmpty
;
235 // -----------------------------------------------------------------------------
236 uno::Sequence
< OUString
> DriversConfig::getURLs() const
238 const TInstalledDrivers
& rDrivers
= m_aNode
->getInstalledDrivers(m_xORB
);
239 uno::Sequence
< OUString
> aRet(rDrivers
.size());
240 OUString
* pIter
= aRet
.getArray();
241 TInstalledDrivers::const_iterator aIter
= rDrivers
.begin();
242 TInstalledDrivers::const_iterator aEnd
= rDrivers
.end();
243 for(;aIter
!= aEnd
;++aIter
,++pIter
)
245 *pIter
= aIter
->first
;
250 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */