1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_dbaccess.hxx"
26 
27 #include "DriverSettings.hxx"
28 #include "dsmeta.hxx"
29 
30 #include <com/sun/star/uno/Sequence.hxx>
31 #include <com/sun/star/beans/NamedValue.hpp>
32 
33 #include <connectivity/DriversConfig.hxx>
34 
35 using ::com::sun::star::uno::Sequence;
36 using ::com::sun::star::beans::NamedValue;
37 
38 using namespace dbaui;
getSupportedIndirectSettings(const::rtl::OUString & _sURLPrefix,const::com::sun::star::uno::Reference<::com::sun::star::lang::XMultiServiceFactory> & _xFactory,::std::vector<sal_Int32> & _out_rDetailsIds)39 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 )
40 {
41     // for a number of settings, we do not need to use hard-coded here, but can ask a
42     // central DataSourceUI instance.
43     DataSourceMetaData aMeta( _sURLPrefix );
44     const FeatureSet& rFeatures( aMeta.getFeatureSet() );
45     for (   FeatureSet::const_iterator feature = rFeatures.begin();
46             feature != rFeatures.end();
47             ++feature
48         )
49     {
50         _out_rDetailsIds.push_back( *feature );
51     }
52 
53     // the rest is configuration-based
54     // TODO: that's not really true: *everything* is configuration-based nowadays, even the FeatureSet obtained
55     // from the DataSourceMetaData has been initialized from the configuration. So in fact, we could consolidate
56     // the two blocks.
57     // The best approach would be to extend the FeatureSet to contain *all* known data source features, not only
58     // the ones from the "Advanced settings" UI.
59 
60     ::connectivity::DriversConfig aDriverConfig(_xFactory);
61     const ::comphelper::NamedValueCollection& aProperties = aDriverConfig.getProperties(_sURLPrefix);
62 #if OSL_DEBUG_LEVEL > 0
63     {
64         Sequence< NamedValue > aNamedValues;
65         aProperties >>= aNamedValues;
66         for (   const NamedValue* loop = aNamedValues.getConstArray();
67                 loop != aNamedValues.getConstArray() + aNamedValues.getLength();
68                 ++loop
69             )
70         {
71             int dummy = 0;
72             (void)dummy;
73         }
74     }
75 #endif
76     typedef ::std::pair<sal_uInt16, ::rtl::OUString> TProperties;
77     TProperties aProps[] = { TProperties(DSID_SHOWDELETEDROWS,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ShowDeleted")))
78                             ,TProperties(DSID_CHARSET,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CharSet")))
79                             ,TProperties(DSID_FIELDDELIMITER,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FieldDelimiter")))
80                             ,TProperties(DSID_TEXTDELIMITER,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("StringDelimiter")))
81                             ,TProperties(DSID_DECIMALDELIMITER,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DecimalDelimiter")))
82                             ,TProperties(DSID_THOUSANDSDELIMITER,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ThousandDelimiter")))
83                             ,TProperties(DSID_TEXTFILEEXTENSION,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Extension")))
84                             ,TProperties(DSID_TEXTFILEHEADER,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HeaderLine")))
85                             ,TProperties(DSID_ADDITIONALOPTIONS,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SystemDriverSettings")))
86                             ,TProperties(DSID_CONN_SHUTSERVICE,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ShutdownDatabase")))
87                             ,TProperties(DSID_CONN_DATAINC,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DataCacheSizeIncrement")))
88                             ,TProperties(DSID_CONN_CACHESIZE,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DataCacheSize")))
89                             ,TProperties(DSID_CONN_CTRLUSER,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ControlUser")))
90                             ,TProperties(DSID_CONN_CTRLPWD,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ControlPassword")))
91                             ,TProperties(DSID_USECATALOG,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("UseCatalog")))
92                             ,TProperties(DSID_CONN_SOCKET,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("LocalSocket")))
93                             ,TProperties(DSID_NAMED_PIPE,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("NamedPipe")))
94                             ,TProperties(DSID_JDBCDRIVERCLASS,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JavaDriverClass")))
95                             ,TProperties(DSID_CONN_LDAP_BASEDN,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("BaseDN")))
96                             ,TProperties(DSID_CONN_LDAP_ROWCOUNT,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MaxRowCount")))
97                             ,TProperties(DSID_CONN_LDAP_USESSL,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("UseSSL")))
98                             ,TProperties(DSID_IGNORECURRENCY,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IgnoreCurrency")))
99                             ,TProperties(0,::rtl::OUString())
100     };
101     // TODO: This mapping between IDs and property names already exists - in ODbDataSourceAdministrationHelper::ODbDataSourceAdministrationHelper.
102     // Another mapping (which is also duplicated in ODbDataSourceAdministrationHelper) exists in dsmeta.cxx. We should
103     // consolidate those three places into one.
104     // However, care has to be taken: We need to distinguish between "features" and "properties" of a data source (resp. driver).
105     // That is, a driver can support a certain property, but not allow to change it in the UI, which means it would
106     // not have the respective "feature".
107     for ( TProperties* pProps = aProps; pProps->first; ++pProps )
108     {
109         if ( aProperties.has(pProps->second) )
110             _out_rDetailsIds.push_back(pProps->first);
111     }
112 }
113