1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_dbaccess.hxx"
30 
31 #include "DriverSettings.hxx"
32 #include "dsmeta.hxx"
33 
34 #include <com/sun/star/uno/Sequence.hxx>
35 #include <com/sun/star/beans/NamedValue.hpp>
36 
37 #include <connectivity/DriversConfig.hxx>
38 
39 using ::com::sun::star::uno::Sequence;
40 using ::com::sun::star::beans::NamedValue;
41 
42 using namespace dbaui;
43 void ODriversSettings::getSupportedIndirectSettings( const ::rtl::OUString& _sURLPrefix,const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _xFactory, ::std::vector< sal_Int32>& _out_rDetailsIds )
44 {
45     // for a number of settings, we do not need to use hard-coded here, but can ask a
46     // central DataSourceUI instance.
47     DataSourceMetaData aMeta( _sURLPrefix );
48     const FeatureSet& rFeatures( aMeta.getFeatureSet() );
49     for (   FeatureSet::const_iterator feature = rFeatures.begin();
50             feature != rFeatures.end();
51             ++feature
52         )
53     {
54         _out_rDetailsIds.push_back( *feature );
55     }
56 
57     // the rest is configuration-based
58     // TODO: that's not really true: *everything* is configuration-based nowadays, even the FeatureSet obtained
59     // from the DataSourceMetaData has been initialized from the configuration. So in fact, we could consolidate
60     // the two blocks.
61     // The best approach would be to extend the FeatureSet to contain *all* known data source features, not only
62     // the ones from the "Advanced settings" UI.
63 
64     ::connectivity::DriversConfig aDriverConfig(_xFactory);
65     const ::comphelper::NamedValueCollection& aProperties = aDriverConfig.getProperties(_sURLPrefix);
66 #if OSL_DEBUG_LEVEL > 0
67     {
68         Sequence< NamedValue > aNamedValues;
69         aProperties >>= aNamedValues;
70         for (   const NamedValue* loop = aNamedValues.getConstArray();
71                 loop != aNamedValues.getConstArray() + aNamedValues.getLength();
72                 ++loop
73             )
74         {
75             int dummy = 0;
76             (void)dummy;
77         }
78     }
79 #endif
80     typedef ::std::pair<sal_uInt16, ::rtl::OUString> TProperties;
81     TProperties aProps[] = { TProperties(DSID_SHOWDELETEDROWS,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ShowDeleted")))
82                             ,TProperties(DSID_CHARSET,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CharSet")))
83                             ,TProperties(DSID_FIELDDELIMITER,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FieldDelimiter")))
84                             ,TProperties(DSID_TEXTDELIMITER,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("StringDelimiter")))
85                             ,TProperties(DSID_DECIMALDELIMITER,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DecimalDelimiter")))
86                             ,TProperties(DSID_THOUSANDSDELIMITER,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ThousandDelimiter")))
87                             ,TProperties(DSID_TEXTFILEEXTENSION,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Extension")))
88                             ,TProperties(DSID_TEXTFILEHEADER,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HeaderLine")))
89                             ,TProperties(DSID_ADDITIONALOPTIONS,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SystemDriverSettings")))
90                             ,TProperties(DSID_CONN_SHUTSERVICE,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ShutdownDatabase")))
91                             ,TProperties(DSID_CONN_DATAINC,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DataCacheSizeIncrement")))
92                             ,TProperties(DSID_CONN_CACHESIZE,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DataCacheSize")))
93                             ,TProperties(DSID_CONN_CTRLUSER,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ControlUser")))
94                             ,TProperties(DSID_CONN_CTRLPWD,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ControlPassword")))
95                             ,TProperties(DSID_USECATALOG,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("UseCatalog")))
96                             ,TProperties(DSID_CONN_SOCKET,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("LocalSocket")))
97                             ,TProperties(DSID_NAMED_PIPE,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("NamedPipe")))
98                             ,TProperties(DSID_JDBCDRIVERCLASS,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JavaDriverClass")))
99                             ,TProperties(DSID_CONN_LDAP_BASEDN,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("BaseDN")))
100                             ,TProperties(DSID_CONN_LDAP_ROWCOUNT,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MaxRowCount")))
101                             ,TProperties(DSID_CONN_LDAP_USESSL,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("UseSSL")))
102                             ,TProperties(DSID_IGNORECURRENCY,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IgnoreCurrency")))
103                             ,TProperties(0,::rtl::OUString())
104     };
105     // TODO: This mapping between IDs and property names already exists - in ODbDataSourceAdministrationHelper::ODbDataSourceAdministrationHelper.
106     // Another mapping (which is also duplicated in ODbDataSourceAdministrationHelper) exists in dsmeta.cxx. We should
107     // consolidate those three places into one.
108     // However, care has to be taken: We need to distinguish between "features" and "properties" of a data source (resp. driver).
109     // That is, a driver can support a certain property, but not allow to change it in the UI, which means it would
110     // not have the respective "feature".
111     for ( TProperties* pProps = aProps; pProps->first; ++pProps )
112     {
113         if ( aProperties.has(pProps->second) )
114             _out_rDetailsIds.push_back(pProps->first);
115     }
116 }
117