1 /*************************************************************************
3 * OpenOffice.org - a multi-platform office productivity suite
5 * $RCSfile: makefile,v $
9 * last change: $Author: st $ $Date: 2000/11/22 02:32:00 $
11 * The Contents of this file are made available subject to
12 * the terms of GNU Lesser General Public License Version 2.1.
15 * GNU Lesser General Public License Version 2.1
16 * =============================================
17 * Copyright 2005 by Sun Microsystems, Inc.
18 * 901 San Antonio Road, Palo Alto, CA 94303, USA
20 * This library is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Lesser General Public
22 * License version 2.1, as published by the Free Software Foundation.
24 * This library is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 * Lesser General Public License for more details.
29 * You should have received a copy of the GNU Lesser General Public
30 * License along with this library; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
34 ************************************************************************/
35 #include "connectivity/DriversConfig.hxx"
36 #include <tools/wldcrd.hxx>
38 using namespace connectivity
;
40 using namespace ::com::sun::star
;
44 void lcl_convert(const uno::Sequence
< ::rtl::OUString
>& _aSource
,uno::Any
& _rDest
)
46 uno::Sequence
<uno::Any
> aRet(_aSource
.getLength());
47 uno::Any
* pAny
= aRet
.getArray();
48 const ::rtl::OUString
* pIter
= _aSource
.getConstArray();
49 const ::rtl::OUString
* pEnd
= pIter
+ _aSource
.getLength();
50 for (;pIter
!= pEnd
; ++pIter
,++pAny
)
56 void lcl_fillValues(const ::utl::OConfigurationNode
& _aURLPatternNode
,const ::rtl::OUString
& _sNode
,::comphelper::NamedValueCollection
& _rValues
)
58 const ::utl::OConfigurationNode aPropertiesNode
= _aURLPatternNode
.openNode(_sNode
);
59 if ( aPropertiesNode
.isValid() )
61 uno::Sequence
< ::rtl::OUString
> aStringSeq
;
62 static const ::rtl::OUString
s_sValue(RTL_CONSTASCII_USTRINGPARAM("/Value"));
63 const uno::Sequence
< ::rtl::OUString
> aProperties
= aPropertiesNode
.getNodeNames();
64 const ::rtl::OUString
* pPropertiesIter
= aProperties
.getConstArray();
65 const ::rtl::OUString
* pPropertiesEnd
= pPropertiesIter
+ aProperties
.getLength();
66 for (;pPropertiesIter
!= pPropertiesEnd
; ++pPropertiesIter
)
68 uno::Any aValue
= aPropertiesNode
.getNodeValue(*pPropertiesIter
+ s_sValue
);
69 if ( aValue
>>= aStringSeq
)
71 lcl_convert(aStringSeq
,aValue
);
73 _rValues
.put(*pPropertiesIter
,aValue
);
74 } // for (;pPropertiesIter != pPropertiesEnd ; ++pPropertiesIter,++pNamedIter)
75 } // if ( aPropertiesNode.isValid() )
77 void lcl_readURLPatternNode(const ::utl::OConfigurationTreeRoot
& _aInstalled
,const ::rtl::OUString
& _sEntry
,TInstalledDriver
& _rInstalledDriver
)
79 const ::utl::OConfigurationNode aURLPatternNode
= _aInstalled
.openNode(_sEntry
);
80 if ( aURLPatternNode
.isValid() )
82 static const ::rtl::OUString
s_sParentURLPattern(RTL_CONSTASCII_USTRINGPARAM("ParentURLPattern"));
83 static const ::rtl::OUString
s_sDriver(RTL_CONSTASCII_USTRINGPARAM("Driver"));
84 static const ::rtl::OUString
s_sDriverTypeDisplayName(RTL_CONSTASCII_USTRINGPARAM("DriverTypeDisplayName"));
85 static const ::rtl::OUString
s_sProperties(RTL_CONSTASCII_USTRINGPARAM("Properties"));
86 static const ::rtl::OUString
s_sFeatures(RTL_CONSTASCII_USTRINGPARAM("Features"));
87 static const ::rtl::OUString
s_sMetaData(RTL_CONSTASCII_USTRINGPARAM("MetaData"));
88 ::rtl::OUString sParentURLPattern
;
89 aURLPatternNode
.getNodeValue(s_sParentURLPattern
) >>= sParentURLPattern
;
90 if ( sParentURLPattern
.getLength() )
91 lcl_readURLPatternNode(_aInstalled
,sParentURLPattern
,_rInstalledDriver
);
93 ::rtl::OUString sDriverFactory
;
94 aURLPatternNode
.getNodeValue(s_sDriver
) >>= sDriverFactory
;
95 if ( sDriverFactory
.getLength() )
96 _rInstalledDriver
.sDriverFactory
= sDriverFactory
;
98 ::rtl::OUString sDriverTypeDisplayName
;
99 aURLPatternNode
.getNodeValue(s_sDriverTypeDisplayName
) >>= sDriverTypeDisplayName
;
100 OSL_ENSURE(sDriverTypeDisplayName
.getLength(),"No valid DriverTypeDisplayName property!");
101 if ( sDriverTypeDisplayName
.getLength() )
102 _rInstalledDriver
.sDriverTypeDisplayName
= sDriverTypeDisplayName
;
104 lcl_fillValues(aURLPatternNode
,s_sProperties
,_rInstalledDriver
.aProperties
);
105 lcl_fillValues(aURLPatternNode
,s_sFeatures
,_rInstalledDriver
.aFeatures
);
106 lcl_fillValues(aURLPatternNode
,s_sMetaData
,_rInstalledDriver
.aMetaData
);
110 // -----------------------------------------------------------------------------
111 DriversConfigImpl::DriversConfigImpl()
114 // -----------------------------------------------------------------------------
115 void DriversConfigImpl::Load(const uno::Reference
< lang::XMultiServiceFactory
>& _rxORB
,TInstalledDrivers
& _rDrivers
)
117 if ( !m_aInstalled
.isValid() )
119 static const ::rtl::OUString
s_sNodeName(RTL_CONSTASCII_USTRINGPARAM("org.openoffice.Office.DataAccess.Drivers/Installed")); ///Installed
120 m_aInstalled
= ::utl::OConfigurationTreeRoot::createWithServiceFactory(_rxORB
, s_sNodeName
, -1, ::utl::OConfigurationTreeRoot::CM_READONLY
);
123 if ( m_aInstalled
.isValid() )
125 const uno::Sequence
< ::rtl::OUString
> aURLPatterns
= m_aInstalled
.getNodeNames();
126 const ::rtl::OUString
* pPatternIter
= aURLPatterns
.getConstArray();
127 const ::rtl::OUString
* pPatternEnd
= pPatternIter
+ aURLPatterns
.getLength();
128 for (;pPatternIter
!= pPatternEnd
; ++pPatternIter
)
130 TInstalledDriver aInstalledDriver
;
131 lcl_readURLPatternNode(m_aInstalled
,*pPatternIter
,aInstalledDriver
);
132 if ( aInstalledDriver
.sDriverFactory
.getLength() )
133 _rDrivers
.insert(TInstalledDrivers::value_type(*pPatternIter
,aInstalledDriver
));
137 // -----------------------------------------------------------------------------
138 DriversConfig::DriversConfig(const uno::Reference
< lang::XMultiServiceFactory
>& _rxORB
)
140 m_aNode
->Load(_rxORB
,m_aDrivers
);
143 // -----------------------------------------------------------------------------
144 DriversConfig::~DriversConfig()
148 // -----------------------------------------------------------------------------
149 DriversConfig::DriversConfig( const DriversConfig
& _rhs
)
154 // -----------------------------------------------------------------------------
155 DriversConfig
& DriversConfig::operator=( const DriversConfig
& _rhs
)
159 m_aDrivers
= _rhs
.m_aDrivers
;
160 m_aNode
= _rhs
.m_aNode
;
165 // -----------------------------------------------------------------------------
166 ::rtl::OUString
DriversConfig::getDriverFactoryName(const ::rtl::OUString
& _sURL
) const
168 ::rtl::OUString sRet
;
169 ::rtl::OUString sOldPattern
;
170 TInstalledDrivers::const_iterator aIter
= m_aDrivers
.begin();
171 TInstalledDrivers::const_iterator aEnd
= m_aDrivers
.end();
172 for(;aIter
!= aEnd
;++aIter
)
174 WildCard
aWildCard(aIter
->first
);
175 if ( sOldPattern
.getLength() < aIter
->first
.getLength() && aWildCard
.Matches(_sURL
) )
177 sRet
= aIter
->second
.sDriverFactory
;
178 sOldPattern
= aIter
->first
;
184 // -----------------------------------------------------------------------------
185 ::rtl::OUString
DriversConfig::getDriverTypeDisplayName(const ::rtl::OUString
& _sURL
) const
187 ::rtl::OUString sRet
;
188 ::rtl::OUString sOldPattern
;
189 TInstalledDrivers::const_iterator aIter
= m_aDrivers
.begin();
190 TInstalledDrivers::const_iterator aEnd
= m_aDrivers
.end();
191 for(;aIter
!= aEnd
;++aIter
)
193 WildCard
aWildCard(aIter
->first
);
194 if ( sOldPattern
.getLength() < aIter
->first
.getLength() && aWildCard
.Matches(_sURL
) )
196 sRet
= aIter
->second
.sDriverTypeDisplayName
;
197 sOldPattern
= aIter
->first
;
203 // -----------------------------------------------------------------------------
204 const ::comphelper::NamedValueCollection
& DriversConfig::getProperties(const ::rtl::OUString
& _sURL
) const
206 return impl_get(_sURL
,1);
208 // -----------------------------------------------------------------------------
209 const ::comphelper::NamedValueCollection
& DriversConfig::getFeatures(const ::rtl::OUString
& _sURL
) const
211 return impl_get(_sURL
,0);
213 // -----------------------------------------------------------------------------
214 const ::comphelper::NamedValueCollection
& DriversConfig::getMetaData(const ::rtl::OUString
& _sURL
) const
216 return impl_get(_sURL
,2);
218 // -----------------------------------------------------------------------------
219 const ::comphelper::NamedValueCollection
& DriversConfig::impl_get(const ::rtl::OUString
& _sURL
,sal_Int32 _nProps
) const
221 const ::comphelper::NamedValueCollection
* pRet
= NULL
;
222 ::rtl::OUString sOldPattern
;
223 TInstalledDrivers::const_iterator aIter
= m_aDrivers
.begin();
224 TInstalledDrivers::const_iterator aEnd
= m_aDrivers
.end();
225 for(;aIter
!= aEnd
;++aIter
)
227 WildCard
aWildCard(aIter
->first
);
228 if ( sOldPattern
.getLength() < aIter
->first
.getLength() && aWildCard
.Matches(_sURL
) )
233 pRet
= &aIter
->second
.aFeatures
;
236 pRet
= &aIter
->second
.aProperties
;
239 pRet
= &aIter
->second
.aMetaData
;
242 sOldPattern
= aIter
->first
;
244 } // for(;aIter != aEnd;++aIter)
247 static const ::comphelper::NamedValueCollection s_sEmpty
;
252 // -----------------------------------------------------------------------------
253 uno::Sequence
< ::rtl::OUString
> DriversConfig::getURLs() const
255 uno::Sequence
< ::rtl::OUString
> aRet(m_aDrivers
.size());
256 ::rtl::OUString
* pIter
= aRet
.getArray();
257 TInstalledDrivers::const_iterator aIter
= m_aDrivers
.begin();
258 TInstalledDrivers::const_iterator aEnd
= m_aDrivers
.end();
259 for(;aIter
!= aEnd
;++aIter
,++pIter
)
261 *pIter
= aIter
->first
;