1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "xmlDataSource.hxx"
21 #include "xmlLogin.hxx"
22 #include "xmlTableFilterList.hxx"
23 #include "xmlDataSourceInfo.hxx"
24 #include "xmlDataSourceSettings.hxx"
25 #include "xmlDataSourceSetting.hxx"
26 #include "xmlfilter.hxx"
27 #include <xmloff/xmltoken.hxx>
28 #include <xmloff/xmlnmspe.hxx>
29 #include <xmloff/nmspmap.hxx>
30 #include "xmlEnums.hxx"
31 #include "xmlstrings.hrc"
32 #include <tools/debug.hxx>
33 #include <tools/diagnose_ex.h>
34 #include "xmlConnectionData.hxx"
38 using namespace ::com::sun::star::uno
;
39 using namespace ::com::sun::star::xml::sax
;
41 OXMLDataSource::OXMLDataSource( ODBFilter
& rImport
,
42 sal_uInt16 nPrfx
, const OUString
& _sLocalName
,
43 const Reference
< XAttributeList
> & _xAttrList
, const UsedFor _eUsedFor
) :
44 SvXMLImportContext( rImport
, nPrfx
, _sLocalName
)
47 OSL_ENSURE(_xAttrList
.is(),"Attribute list is NULL!");
48 const SvXMLNamespaceMap
& rMap
= rImport
.GetNamespaceMap();
49 const SvXMLTokenMap
& rTokenMap
= rImport
.GetDataSourceElemTokenMap();
51 Reference
<XPropertySet
> xDataSource
= rImport
.getDataSource();
53 PropertyValue aProperty
;
54 bool bFoundParamNameSubstitution
= false;
55 bool bFoundTableNameLengthLimited
= false;
56 bool bFoundAppendTableAliasName
= false;
57 bool bFoundSuppressVersionColumns
= false;
59 const sal_Int16 nLength
= (xDataSource
.is() && _xAttrList
.is()) ? _xAttrList
->getLength() : 0;
60 static const OUString s_sTRUE
= ::xmloff::token::GetXMLToken(XML_TRUE
);
61 for(sal_Int16 i
= 0; i
< nLength
; ++i
)
64 OUString sAttrName
= _xAttrList
->getNameByIndex( i
);
65 sal_uInt16 nPrefix
= rMap
.GetKeyByAttrName( sAttrName
,&sLocalName
);
66 OUString sValue
= _xAttrList
->getValueByIndex( i
);
68 aProperty
.Name
.clear();
69 aProperty
.Value
= Any();
71 switch( rTokenMap
.Get( nPrefix
, sLocalName
) )
73 case XML_TOK_CONNECTION_RESOURCE
:
76 xDataSource
->setPropertyValue(PROPERTY_URL
,makeAny(sValue
));
78 catch(const Exception
&)
80 DBG_UNHANDLED_EXCEPTION();
83 case XML_TOK_SUPPRESS_VERSION_COLUMNS
:
86 xDataSource
->setPropertyValue(PROPERTY_SUPPRESSVERSIONCL
,makeAny(sValue
== s_sTRUE
? sal_True
: sal_False
));
87 bFoundSuppressVersionColumns
= true;
89 catch(const Exception
&)
91 DBG_UNHANDLED_EXCEPTION();
94 case XML_TOK_JAVA_DRIVER_CLASS
:
95 aProperty
.Name
= INFO_JDBCDRIVERCLASS
;
97 case XML_TOK_EXTENSION
:
98 aProperty
.Name
= INFO_TEXTFILEEXTENSION
;
100 case XML_TOK_IS_FIRST_ROW_HEADER_LINE
:
101 aProperty
.Name
= INFO_TEXTFILEHEADER
;
102 aProperty
.Value
<<= (sValue
== s_sTRUE
? sal_True
: sal_False
);
104 case XML_TOK_SHOW_DELETED
:
105 aProperty
.Name
= INFO_SHOWDELETEDROWS
;
106 aProperty
.Value
<<= (sValue
== s_sTRUE
? sal_True
: sal_False
);
108 case XML_TOK_IS_TABLE_NAME_LENGTH_LIMITED
:
109 aProperty
.Name
= INFO_ALLOWLONGTABLENAMES
;
110 aProperty
.Value
<<= (sValue
== s_sTRUE
? sal_True
: sal_False
);
111 bFoundTableNameLengthLimited
= true;
113 case XML_TOK_SYSTEM_DRIVER_SETTINGS
:
114 aProperty
.Name
= INFO_ADDITIONALOPTIONS
;
116 case XML_TOK_ENABLE_SQL92_CHECK
:
117 aProperty
.Name
= PROPERTY_ENABLESQL92CHECK
;
118 aProperty
.Value
<<= (sValue
== s_sTRUE
? sal_True
: sal_False
);
120 case XML_TOK_APPEND_TABLE_ALIAS_NAME
:
121 aProperty
.Name
= INFO_APPEND_TABLE_ALIAS
;
122 aProperty
.Value
<<= (sValue
== s_sTRUE
? sal_True
: sal_False
);
123 bFoundAppendTableAliasName
= true;
125 case XML_TOK_PARAMETER_NAME_SUBSTITUTION
:
126 aProperty
.Name
= INFO_PARAMETERNAMESUBST
;
127 aProperty
.Value
<<= (sValue
== s_sTRUE
? sal_True
: sal_False
);
128 bFoundParamNameSubstitution
= true;
130 case XML_TOK_IGNORE_DRIVER_PRIVILEGES
:
131 aProperty
.Name
= INFO_IGNOREDRIVER_PRIV
;
132 aProperty
.Value
<<= (sValue
== s_sTRUE
? sal_True
: sal_False
);
134 case XML_TOK_BOOLEAN_COMPARISON_MODE
:
135 aProperty
.Name
= PROPERTY_BOOLEANCOMPARISONMODE
;
136 if ( sValue
== "equal-integer" )
137 aProperty
.Value
<<= sal_Int32(0);
138 else if ( sValue
== "is-boolean" )
139 aProperty
.Value
<<= sal_Int32(1);
140 else if ( sValue
== "equal-boolean" )
141 aProperty
.Value
<<= sal_Int32(2);
142 else if ( sValue
== "equal-use-only-zero" )
143 aProperty
.Value
<<= sal_Int32(3);
145 case XML_TOK_USE_CATALOG
:
146 aProperty
.Name
= INFO_USECATALOG
;
147 aProperty
.Value
<<= (sValue
== s_sTRUE
? sal_True
: sal_False
);
149 case XML_TOK_BASE_DN
:
150 aProperty
.Name
= INFO_CONN_LDAP_BASEDN
;
152 case XML_TOK_MAX_ROW_COUNT
:
153 aProperty
.Name
= INFO_CONN_LDAP_ROWCOUNT
;
154 aProperty
.Value
<<= sValue
.toInt32();
156 case XML_TOK_JAVA_CLASSPATH
:
157 aProperty
.Name
= "JavaDriverClassPath";
160 if ( !aProperty
.Name
.isEmpty() )
162 if ( !aProperty
.Value
.hasValue() )
163 aProperty
.Value
<<= sValue
;
164 rImport
.addInfo(aProperty
);
167 if ( rImport
.isNewFormat() )
169 if ( !bFoundTableNameLengthLimited
&& ( _eUsedFor
== eAppSettings
) )
171 aProperty
.Name
= INFO_ALLOWLONGTABLENAMES
;
172 aProperty
.Value
<<= sal_True
;
173 rImport
.addInfo(aProperty
);
175 if ( !bFoundParamNameSubstitution
&& ( _eUsedFor
== eDriverSettings
) )
177 aProperty
.Name
= INFO_PARAMETERNAMESUBST
;
178 aProperty
.Value
<<= sal_True
;
179 rImport
.addInfo(aProperty
);
181 if ( !bFoundAppendTableAliasName
&& ( _eUsedFor
== eAppSettings
) )
183 aProperty
.Name
= INFO_APPEND_TABLE_ALIAS
;
184 aProperty
.Value
<<= sal_True
;
185 rImport
.addInfo(aProperty
);
187 if ( !bFoundSuppressVersionColumns
&& ( _eUsedFor
== eAppSettings
) )
191 xDataSource
->setPropertyValue(PROPERTY_SUPPRESSVERSIONCL
,makeAny(sal_True
));
193 catch(const Exception
&)
195 DBG_UNHANDLED_EXCEPTION();
201 OXMLDataSource::~OXMLDataSource()
206 SvXMLImportContext
* OXMLDataSource::CreateChildContext(
208 const OUString
& rLocalName
,
209 const Reference
< XAttributeList
> & xAttrList
)
211 SvXMLImportContext
*pContext
= 0;
212 const SvXMLTokenMap
& rTokenMap
= GetOwnImport().GetDataSourceElemTokenMap();
213 const sal_uInt16 nToken
= rTokenMap
.Get( nPrefix
, rLocalName
);
218 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP
);
219 pContext
= new OXMLLogin( GetOwnImport(), nPrefix
, rLocalName
,xAttrList
);
222 case XML_TOK_TABLE_FILTER
:
223 case XML_TOK_TABLE_TYPE_FILTER
:
224 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP
);
225 pContext
= new OXMLTableFilterList( GetImport(), nPrefix
, rLocalName
);
227 case XML_TOK_AUTO_INCREMENT
:
228 case XML_TOK_DELIMITER
:
229 case XML_TOK_FONT_CHARSET
:
230 case XML_TOK_CHARACTER_SET
:
231 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP
);
232 pContext
= new OXMLDataSourceInfo( GetOwnImport(), nPrefix
, rLocalName
,xAttrList
,nToken
);
234 case XML_TOK_DATA_SOURCE_SETTINGS
:
235 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP
);
236 pContext
= new OXMLDataSourceSettings( GetOwnImport(), nPrefix
, rLocalName
);
238 case XML_TOK_CONNECTION_DATA
:
239 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP
);
240 pContext
= new OXMLConnectionData( GetOwnImport(), nPrefix
, rLocalName
);
242 case XML_TOK_DRIVER_SETTINGS
:
243 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP
);
244 pContext
= new OXMLDataSource( GetOwnImport(), nPrefix
, rLocalName
, xAttrList
, OXMLDataSource::eDriverSettings
);
246 case XML_TOK_APPLICATION_CONNECTION_SETTINGS
:
247 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP
);
248 pContext
= new OXMLDataSource( GetOwnImport(), nPrefix
, rLocalName
, xAttrList
, OXMLDataSource::eAppSettings
);
253 pContext
= new SvXMLImportContext( GetImport(), nPrefix
, rLocalName
);
258 ODBFilter
& OXMLDataSource::GetOwnImport()
260 return static_cast<ODBFilter
&>(GetImport());
263 } // namespace dbaxml
265 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */