update dev300-m58
[ooovba.git] / connectivity / source / commontools / DriversConfig.cxx
blobdae6b9136f6a089c0196cc9c9c1b7c50281bda3e
1 /*************************************************************************
3 * OpenOffice.org - a multi-platform office productivity suite
5 * $RCSfile: makefile,v $
7 * $Revision: 1.1 $
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,
32 * MA 02111-1307 USA
34 ************************************************************************/
35 #include "connectivity/DriversConfig.hxx"
36 #include <tools/wldcrd.hxx>
38 using namespace connectivity;
39 using namespace utl;
40 using namespace ::com::sun::star;
42 namespace
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)
52 *pAny <<= *pIter;
54 _rDest <<= aRet;
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);
142 // -----------------------------------------------------------------------------
143 ::rtl::OUString DriversConfig::getDriverFactoryName(const ::rtl::OUString& _sURL) const
145 ::rtl::OUString sRet;
146 ::rtl::OUString sOldPattern;
147 TInstalledDrivers::const_iterator aIter = m_aDrivers.begin();
148 TInstalledDrivers::const_iterator aEnd = m_aDrivers.end();
149 for(;aIter != aEnd;++aIter)
151 WildCard aWildCard(aIter->first);
152 if ( sOldPattern.getLength() < aIter->first.getLength() && aWildCard.Matches(_sURL) )
154 sRet = aIter->second.sDriverFactory;
155 sOldPattern = aIter->first;
159 return sRet;
161 // -----------------------------------------------------------------------------
162 ::rtl::OUString DriversConfig::getDriverTypeDisplayName(const ::rtl::OUString& _sURL) const
164 ::rtl::OUString sRet;
165 ::rtl::OUString sOldPattern;
166 TInstalledDrivers::const_iterator aIter = m_aDrivers.begin();
167 TInstalledDrivers::const_iterator aEnd = m_aDrivers.end();
168 for(;aIter != aEnd;++aIter)
170 WildCard aWildCard(aIter->first);
171 if ( sOldPattern.getLength() < aIter->first.getLength() && aWildCard.Matches(_sURL) )
173 sRet = aIter->second.sDriverTypeDisplayName;
174 sOldPattern = aIter->first;
178 return sRet;
180 // -----------------------------------------------------------------------------
181 const ::comphelper::NamedValueCollection& DriversConfig::getProperties(const ::rtl::OUString& _sURL) const
183 return impl_get(_sURL,1);
185 // -----------------------------------------------------------------------------
186 const ::comphelper::NamedValueCollection& DriversConfig::getFeatures(const ::rtl::OUString& _sURL) const
188 return impl_get(_sURL,0);
190 // -----------------------------------------------------------------------------
191 const ::comphelper::NamedValueCollection& DriversConfig::getMetaData(const ::rtl::OUString& _sURL) const
193 return impl_get(_sURL,2);
195 // -----------------------------------------------------------------------------
196 const ::comphelper::NamedValueCollection& DriversConfig::impl_get(const ::rtl::OUString& _sURL,sal_Int32 _nProps) const
198 const ::comphelper::NamedValueCollection* pRet = NULL;
199 ::rtl::OUString sOldPattern;
200 TInstalledDrivers::const_iterator aIter = m_aDrivers.begin();
201 TInstalledDrivers::const_iterator aEnd = m_aDrivers.end();
202 for(;aIter != aEnd;++aIter)
204 WildCard aWildCard(aIter->first);
205 if ( sOldPattern.getLength() < aIter->first.getLength() && aWildCard.Matches(_sURL) )
207 switch(_nProps)
209 case 0:
210 pRet = &aIter->second.aFeatures;
211 break;
212 case 1:
213 pRet = &aIter->second.aProperties;
214 break;
215 case 2:
216 pRet = &aIter->second.aMetaData;
217 break;
219 sOldPattern = aIter->first;
221 } // for(;aIter != aEnd;++aIter)
222 if ( pRet == NULL )
224 static const ::comphelper::NamedValueCollection s_sEmpty;
225 pRet = &s_sEmpty;
227 return *pRet;
229 // -----------------------------------------------------------------------------
230 uno::Sequence< ::rtl::OUString > DriversConfig::getURLs() const
232 uno::Sequence< ::rtl::OUString > aRet(m_aDrivers.size());
233 ::rtl::OUString* pIter = aRet.getArray();
234 TInstalledDrivers::const_iterator aIter = m_aDrivers.begin();
235 TInstalledDrivers::const_iterator aEnd = m_aDrivers.end();
236 for(;aIter != aEnd;++aIter,++pIter)
238 *pIter = aIter->first;
240 return aRet;