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 "xmlfilter.hxx"
26 #include <xmloff/xmltoken.hxx>
27 #include <xmloff/ProgressBarHelper.hxx>
28 #include "xmlEnums.hxx"
29 #include <strings.hxx>
30 #include <tools/diagnose_ex.h>
31 #include "xmlConnectionData.hxx"
35 using namespace ::com::sun::star::uno
;
36 using namespace ::com::sun::star::xml::sax
;
38 OXMLDataSource::OXMLDataSource( ODBFilter
& rImport
,
39 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& _xAttrList
,
40 const UsedFor _eUsedFor
) :
41 SvXMLImportContext( rImport
)
44 Reference
<XPropertySet
> xDataSource
= rImport
.getDataSource();
46 PropertyValue aProperty
;
47 bool bFoundParamNameSubstitution
= false;
48 bool bFoundTableNameLengthLimited
= false;
49 bool bFoundAppendTableAliasName
= false;
50 bool bFoundSuppressVersionColumns
= false;
52 static const OUString s_sTRUE
= ::xmloff::token::GetXMLToken(XML_TRUE
);
55 for (auto &aIter
: sax_fastparser::castToFastAttributeList( _xAttrList
))
57 OUString sValue
= aIter
.toString();
59 aProperty
.Name
.clear();
60 aProperty
.Value
= Any();
62 switch( aIter
.getToken() & TOKEN_MASK
)
64 case XML_CONNECTION_RESOURCE
:
67 xDataSource
->setPropertyValue(PROPERTY_URL
,makeAny(sValue
));
69 catch(const Exception
&)
71 DBG_UNHANDLED_EXCEPTION("dbaccess");
74 case XML_SUPPRESS_VERSION_COLUMNS
:
77 xDataSource
->setPropertyValue(PROPERTY_SUPPRESSVERSIONCL
,makeAny(sValue
== s_sTRUE
));
78 bFoundSuppressVersionColumns
= true;
80 catch(const Exception
&)
82 DBG_UNHANDLED_EXCEPTION("dbaccess");
85 case XML_JAVA_DRIVER_CLASS
:
86 aProperty
.Name
= INFO_JDBCDRIVERCLASS
;
89 aProperty
.Name
= INFO_TEXTFILEEXTENSION
;
91 case XML_IS_FIRST_ROW_HEADER_LINE
:
92 aProperty
.Name
= INFO_TEXTFILEHEADER
;
93 aProperty
.Value
<<= (sValue
== s_sTRUE
);
95 case XML_SHOW_DELETED
:
96 aProperty
.Name
= INFO_SHOWDELETEDROWS
;
97 aProperty
.Value
<<= (sValue
== s_sTRUE
);
99 case XML_IS_TABLE_NAME_LENGTH_LIMITED
:
100 aProperty
.Name
= INFO_ALLOWLONGTABLENAMES
;
101 aProperty
.Value
<<= (sValue
== s_sTRUE
);
102 bFoundTableNameLengthLimited
= true;
104 case XML_SYSTEM_DRIVER_SETTINGS
:
105 aProperty
.Name
= INFO_ADDITIONALOPTIONS
;
107 case XML_ENABLE_SQL92_CHECK
:
108 aProperty
.Name
= PROPERTY_ENABLESQL92CHECK
;
109 aProperty
.Value
<<= (sValue
== s_sTRUE
);
111 case XML_APPEND_TABLE_ALIAS_NAME
:
112 aProperty
.Name
= INFO_APPEND_TABLE_ALIAS
;
113 aProperty
.Value
<<= (sValue
== s_sTRUE
);
114 bFoundAppendTableAliasName
= true;
116 case XML_PARAMETER_NAME_SUBSTITUTION
:
117 aProperty
.Name
= INFO_PARAMETERNAMESUBST
;
118 aProperty
.Value
<<= (sValue
== s_sTRUE
);
119 bFoundParamNameSubstitution
= true;
121 case XML_IGNORE_DRIVER_PRIVILEGES
:
122 aProperty
.Name
= INFO_IGNOREDRIVER_PRIV
;
123 aProperty
.Value
<<= (sValue
== s_sTRUE
);
125 case XML_BOOLEAN_COMPARISON_MODE
:
126 aProperty
.Name
= PROPERTY_BOOLEANCOMPARISONMODE
;
127 if ( sValue
== "equal-integer" )
128 aProperty
.Value
<<= sal_Int32(0);
129 else if ( sValue
== "is-boolean" )
130 aProperty
.Value
<<= sal_Int32(1);
131 else if ( sValue
== "equal-boolean" )
132 aProperty
.Value
<<= sal_Int32(2);
133 else if ( sValue
== "equal-use-only-zero" )
134 aProperty
.Value
<<= sal_Int32(3);
136 case XML_USE_CATALOG
:
137 aProperty
.Name
= INFO_USECATALOG
;
138 aProperty
.Value
<<= (sValue
== s_sTRUE
);
141 aProperty
.Name
= INFO_CONN_LDAP_BASEDN
;
143 case XML_MAX_ROW_COUNT
:
144 aProperty
.Name
= INFO_CONN_LDAP_ROWCOUNT
;
145 aProperty
.Value
<<= sValue
.toInt32();
147 case XML_JAVA_CLASSPATH
:
148 aProperty
.Name
= "JavaDriverClassPath";
151 XMLOFF_WARN_UNKNOWN_ATTR("dbaccess", aIter
.getToken(), aIter
.toString());
153 if ( !aProperty
.Name
.isEmpty() )
155 if ( !aProperty
.Value
.hasValue() )
156 aProperty
.Value
<<= sValue
;
157 rImport
.addInfo(aProperty
);
161 if ( !rImport
.isNewFormat() )
164 if ( !bFoundTableNameLengthLimited
&& ( _eUsedFor
== eAppSettings
) )
166 aProperty
.Name
= INFO_ALLOWLONGTABLENAMES
;
167 aProperty
.Value
<<= true;
168 rImport
.addInfo(aProperty
);
170 if ( !bFoundParamNameSubstitution
&& ( _eUsedFor
== eDriverSettings
) )
172 aProperty
.Name
= INFO_PARAMETERNAMESUBST
;
173 aProperty
.Value
<<= true;
174 rImport
.addInfo(aProperty
);
176 if ( !bFoundAppendTableAliasName
&& ( _eUsedFor
== eAppSettings
) )
178 aProperty
.Name
= INFO_APPEND_TABLE_ALIAS
;
179 aProperty
.Value
<<= true;
180 rImport
.addInfo(aProperty
);
182 if ( !bFoundSuppressVersionColumns
&& ( _eUsedFor
== eAppSettings
) )
186 xDataSource
->setPropertyValue(PROPERTY_SUPPRESSVERSIONCL
,makeAny(true));
188 catch(const Exception
&)
190 DBG_UNHANDLED_EXCEPTION("dbaccess");
195 OXMLDataSource::~OXMLDataSource()
200 css::uno::Reference
< css::xml::sax::XFastContextHandler
> OXMLDataSource::createFastChildContext(
201 sal_Int32 nElement
, const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
)
203 SvXMLImportContext
*pContext
= nullptr;
205 switch( nElement
& TOKEN_MASK
)
208 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP
);
209 pContext
= new OXMLLogin( GetOwnImport(), xAttrList
);
212 case XML_TABLE_FILTER
:
213 case XML_TABLE_TYPE_FILTER
:
214 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP
);
215 pContext
= new OXMLTableFilterList( GetImport() );
217 case XML_AUTO_INCREMENT
:
219 case XML_FONT_CHARSET
:
220 case XML_CHARACTER_SET
:
221 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP
);
222 pContext
= new OXMLDataSourceInfo( GetOwnImport(), nElement
, xAttrList
);
224 case XML_DATA_SOURCE_SETTINGS
:
225 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP
);
226 pContext
= new OXMLDataSourceSettings( GetOwnImport() );
228 case XML_CONNECTION_DATA
:
229 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP
);
230 pContext
= new OXMLConnectionData( GetOwnImport() );
232 case XML_DRIVER_SETTINGS
:
233 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP
);
234 pContext
= new OXMLDataSource( GetOwnImport(), xAttrList
, OXMLDataSource::eDriverSettings
);
236 case XML_APPLICATION_CONNECTION_SETTINGS
:
237 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP
);
238 pContext
= new OXMLDataSource( GetOwnImport(), xAttrList
, OXMLDataSource::eAppSettings
);
241 SAL_WARN("dbaccess", "unknown element " << nElement
);
247 ODBFilter
& OXMLDataSource::GetOwnImport()
249 return static_cast<ODBFilter
&>(GetImport());
252 } // namespace dbaxml
254 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */