1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dsmeta.cxx,v $
10 * $Revision: 1.8.8.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 #include <connectivity/DriversConfig.hxx>
33 #include "dsntypes.hxx"
34 #include <comphelper/processfactory.hxx>
35 /** === begin UNO includes === **/
36 /** === end UNO includes === **/
40 //........................................................................
43 //........................................................................
45 /** === begin UNO using === **/
46 using namespace dbaccess
;
47 using namespace ::com::sun::star
;
48 /** === end UNO using === **/
50 struct InitAdvanced
: public AdvancedSettingsSupport
52 enum Special
{ All
, AllButIgnoreCurrency
, None
};
54 InitAdvanced( Special _eType
)
55 :AdvancedSettingsSupport()
57 bGeneratedValues
= ( _eType
== All
) || ( _eType
== AllButIgnoreCurrency
);
58 bUseSQL92NamingConstraints
= ( _eType
== All
) || ( _eType
== AllButIgnoreCurrency
);
59 bAppendTableAliasInSelect
= ( _eType
== All
) || ( _eType
== AllButIgnoreCurrency
);
60 bUseKeywordAsBeforeAlias
= ( _eType
== All
) || ( _eType
== AllButIgnoreCurrency
);
61 bUseBracketedOuterJoinSyntax
= ( _eType
== All
) || ( _eType
== AllButIgnoreCurrency
);
62 bIgnoreDriverPrivileges
= ( _eType
== All
) || ( _eType
== AllButIgnoreCurrency
);
63 bParameterNameSubstitution
= ( _eType
== All
) || ( _eType
== AllButIgnoreCurrency
);
64 bDisplayVersionColumns
= ( _eType
== All
) || ( _eType
== AllButIgnoreCurrency
);
65 bUseCatalogInSelect
= ( _eType
== All
) || ( _eType
== AllButIgnoreCurrency
);
66 bUseSchemaInSelect
= ( _eType
== All
) || ( _eType
== AllButIgnoreCurrency
);
67 bUseIndexDirectionKeyword
= ( _eType
== All
) || ( _eType
== AllButIgnoreCurrency
);
68 bUseDOSLineEnds
= ( _eType
== All
) || ( _eType
== AllButIgnoreCurrency
);
69 bBooleanComparisonMode
= ( _eType
== All
) || ( _eType
== AllButIgnoreCurrency
);
70 bFormsCheckRequiredFields
= ( _eType
== All
) || ( _eType
== AllButIgnoreCurrency
);
71 bIgnoreCurrency
= ( _eType
== All
);
72 bEscapeDateTime
= ( _eType
== All
) || ( _eType
== AllButIgnoreCurrency
);
78 // authentication mode of the data source
79 AuthenticationMode eAuthentication
;
82 :eAuthentication( AuthUserPwd
)
86 FeatureSupport( AuthenticationMode _Auth
)
87 :eAuthentication( _Auth
)
92 //====================================================================
94 //====================================================================
95 //--------------------------------------------------------------------
96 static const AdvancedSettingsSupport
& getAdvancedSettingsSupport( const ::rtl::OUString
& _sURL
)
98 DECLARE_STL_USTRINGACCESS_MAP( AdvancedSettingsSupport
, AdvancedSupport
);
99 static AdvancedSupport s_aSupport
;
100 if ( s_aSupport
.empty() )
102 ::connectivity::DriversConfig
aDriverConfig(::comphelper::getProcessServiceFactory());
103 const uno::Sequence
< ::rtl::OUString
> aURLs
= aDriverConfig
.getURLs();
104 const ::rtl::OUString
* pIter
= aURLs
.getConstArray();
105 const ::rtl::OUString
* pEnd
= pIter
+ aURLs
.getLength();
106 for(;pIter
!= pEnd
;++pIter
)
108 InitAdvanced
aInit(InitAdvanced::None
);
109 const uno::Sequence
< beans::NamedValue
> aProperties
= aDriverConfig
.getFeatures(*pIter
).getNamedValues();
110 const beans::NamedValue
* pPropertiesIter
= aProperties
.getConstArray();
111 const beans::NamedValue
* pPropertiesEnd
= pPropertiesIter
+ aProperties
.getLength();
112 for (;pPropertiesIter
!= pPropertiesEnd
; ++pPropertiesIter
)
114 if ( pPropertiesIter
->Name
.equalsAscii("GeneratedValues") )
116 pPropertiesIter
->Value
>>= aInit
.bGeneratedValues
;
118 else if ( pPropertiesIter
->Name
.equalsAscii("UseSQL92NamingConstraints") )
120 pPropertiesIter
->Value
>>= aInit
.bUseSQL92NamingConstraints
;
122 else if ( pPropertiesIter
->Name
.equalsAscii("AppendTableAliasInSelect") )
124 pPropertiesIter
->Value
>>= aInit
.bAppendTableAliasInSelect
;
126 else if ( pPropertiesIter
->Name
.equalsAscii("UseKeywordAsBeforeAlias") )
128 pPropertiesIter
->Value
>>= aInit
.bUseKeywordAsBeforeAlias
;
130 else if ( pPropertiesIter
->Name
.equalsAscii("UseBracketedOuterJoinSyntax") )
132 pPropertiesIter
->Value
>>= aInit
.bUseBracketedOuterJoinSyntax
;
134 else if ( pPropertiesIter
->Name
.equalsAscii("IgnoreDriverPrivileges") )
136 pPropertiesIter
->Value
>>= aInit
.bIgnoreDriverPrivileges
;
138 else if ( pPropertiesIter
->Name
.equalsAscii("ParameterNameSubstitution") )
140 pPropertiesIter
->Value
>>= aInit
.bParameterNameSubstitution
;
142 else if ( pPropertiesIter
->Name
.equalsAscii("DisplayVersionColumns") )
144 pPropertiesIter
->Value
>>= aInit
.bDisplayVersionColumns
;
146 else if ( pPropertiesIter
->Name
.equalsAscii("UseCatalogInSelect") )
148 pPropertiesIter
->Value
>>= aInit
.bUseCatalogInSelect
;
150 else if ( pPropertiesIter
->Name
.equalsAscii("UseSchemaInSelect") )
152 pPropertiesIter
->Value
>>= aInit
.bUseSchemaInSelect
;
154 else if ( pPropertiesIter
->Name
.equalsAscii("UseIndexDirectionKeyword") )
156 pPropertiesIter
->Value
>>= aInit
.bUseIndexDirectionKeyword
;
158 else if ( pPropertiesIter
->Name
.equalsAscii("UseDOSLineEnds") )
160 pPropertiesIter
->Value
>>= aInit
.bUseDOSLineEnds
;
162 else if ( pPropertiesIter
->Name
.equalsAscii("BooleanComparisonMode") )
164 pPropertiesIter
->Value
>>= aInit
.bBooleanComparisonMode
;
166 else if ( pPropertiesIter
->Name
.equalsAscii("FormsCheckRequiredFields") )
168 pPropertiesIter
->Value
>>= aInit
.bFormsCheckRequiredFields
;
170 else if ( pPropertiesIter
->Name
.equalsAscii("IgnoreCurrency") )
172 pPropertiesIter
->Value
>>= aInit
.bIgnoreCurrency
;
174 else if ( pPropertiesIter
->Name
.equalsAscii("EscapeDateTime") )
176 pPropertiesIter
->Value
>>= aInit
.bEscapeDateTime
;
178 } // for (;pPropertiesIter != pPropertiesEnd ; ++pPropertiesIter)
179 s_aSupport
.insert(AdvancedSupport::value_type(*pIter
,aInit
));
181 } // if ( s_aSupport.empty() )
182 OSL_ENSURE(s_aSupport
.find(_sURL
) != s_aSupport
.end(),"Illegal URL!");
183 return s_aSupport
[ _sURL
];
186 //--------------------------------------------------------------------
187 static AuthenticationMode
getAuthenticationMode( const ::rtl::OUString
& _sURL
)
189 DECLARE_STL_USTRINGACCESS_MAP( FeatureSupport
, Supported
);
190 static Supported s_aSupport
;
191 if ( s_aSupport
.empty() )
193 ::connectivity::DriversConfig
aDriverConfig(::comphelper::getProcessServiceFactory());
194 const uno::Sequence
< ::rtl::OUString
> aURLs
= aDriverConfig
.getURLs();
195 const ::rtl::OUString
* pIter
= aURLs
.getConstArray();
196 const ::rtl::OUString
* pEnd
= pIter
+ aURLs
.getLength();
197 for(;pIter
!= pEnd
;++pIter
)
199 FeatureSupport
aInit( AuthNone
);
200 const ::comphelper::NamedValueCollection
& aMetaData
= aDriverConfig
.getMetaData(*pIter
);
201 if ( aMetaData
.has("Authentication") )
203 ::rtl::OUString sAuth
;
204 aMetaData
.get("Authentication") >>= sAuth
;
205 if ( sAuth
.equalsAscii("UserPassword") )
207 else if ( sAuth
.equalsAscii("Password") )
210 s_aSupport
.insert(Supported::value_type(*pIter
,aInit
));
211 } // for(;pIter != pEnd;++pIter)
212 } // if ( s_aSupport.empty() )
213 OSL_ENSURE(s_aSupport
.find(_sURL
) != s_aSupport
.end(),"Illegal URL!");
214 return s_aSupport
[ _sURL
].eAuthentication
;
217 //====================================================================
218 //= DataSourceMetaData_Impl
219 //====================================================================
220 class DataSourceMetaData_Impl
223 DataSourceMetaData_Impl( const ::rtl::OUString
& _sURL
);
225 inline ::rtl::OUString
getType() const { return m_sURL
; }
228 const ::rtl::OUString m_sURL
;
231 //--------------------------------------------------------------------
232 DataSourceMetaData_Impl::DataSourceMetaData_Impl( const ::rtl::OUString
& _sURL
)
237 //====================================================================
238 //= DataSourceMetaData
239 //====================================================================
240 //--------------------------------------------------------------------
241 DataSourceMetaData::DataSourceMetaData( const ::rtl::OUString
& _sURL
)
242 :m_pImpl( new DataSourceMetaData_Impl( _sURL
) )
246 //--------------------------------------------------------------------
247 DataSourceMetaData::~DataSourceMetaData()
251 //--------------------------------------------------------------------
252 const AdvancedSettingsSupport
& DataSourceMetaData::getAdvancedSettingsSupport() const
254 return ::dbaui::getAdvancedSettingsSupport( m_pImpl
->getType() );
257 //--------------------------------------------------------------------
258 AuthenticationMode
DataSourceMetaData::getAuthentication() const
260 return getAuthenticationMode( m_pImpl
->getType() );
263 //--------------------------------------------------------------------
264 AuthenticationMode
DataSourceMetaData::getAuthentication( const ::rtl::OUString
& _sURL
)
266 return getAuthenticationMode( _sURL
);
269 //........................................................................
271 //........................................................................