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 <comphelper/diagnose_ex.hxx>
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;
54 for (auto &aIter
: sax_fastparser::castToFastAttributeList( _xAttrList
))
56 aProperty
.Name
.clear();
57 aProperty
.Value
= Any();
59 switch( aIter
.getToken() & TOKEN_MASK
)
61 case XML_CONNECTION_RESOURCE
:
64 xDataSource
->setPropertyValue(PROPERTY_URL
,Any(aIter
.toString()));
66 catch(const Exception
&)
68 DBG_UNHANDLED_EXCEPTION("dbaccess");
71 case XML_SUPPRESS_VERSION_COLUMNS
:
74 xDataSource
->setPropertyValue(PROPERTY_SUPPRESSVERSIONCL
,Any(IsXMLToken(aIter
, XML_TRUE
)));
75 bFoundSuppressVersionColumns
= true;
77 catch(const Exception
&)
79 DBG_UNHANDLED_EXCEPTION("dbaccess");
82 case XML_JAVA_DRIVER_CLASS
:
83 aProperty
.Name
= INFO_JDBCDRIVERCLASS
;
86 aProperty
.Name
= INFO_TEXTFILEEXTENSION
;
88 case XML_IS_FIRST_ROW_HEADER_LINE
:
89 aProperty
.Name
= INFO_TEXTFILEHEADER
;
90 aProperty
.Value
<<= IsXMLToken(aIter
, XML_TRUE
);
92 case XML_SHOW_DELETED
:
93 aProperty
.Name
= INFO_SHOWDELETEDROWS
;
94 aProperty
.Value
<<= IsXMLToken(aIter
, XML_TRUE
);
96 case XML_IS_TABLE_NAME_LENGTH_LIMITED
:
97 aProperty
.Name
= INFO_ALLOWLONGTABLENAMES
;
98 aProperty
.Value
<<= IsXMLToken(aIter
, XML_TRUE
);
99 bFoundTableNameLengthLimited
= true;
101 case XML_SYSTEM_DRIVER_SETTINGS
:
102 aProperty
.Name
= INFO_ADDITIONALOPTIONS
;
104 case XML_ENABLE_SQL92_CHECK
:
105 aProperty
.Name
= PROPERTY_ENABLESQL92CHECK
;
106 aProperty
.Value
<<= IsXMLToken(aIter
, XML_TRUE
);
108 case XML_APPEND_TABLE_ALIAS_NAME
:
109 aProperty
.Name
= INFO_APPEND_TABLE_ALIAS
;
110 aProperty
.Value
<<= IsXMLToken(aIter
, XML_TRUE
);
111 bFoundAppendTableAliasName
= true;
113 case XML_PARAMETER_NAME_SUBSTITUTION
:
114 aProperty
.Name
= INFO_PARAMETERNAMESUBST
;
115 aProperty
.Value
<<= IsXMLToken(aIter
, XML_TRUE
);
116 bFoundParamNameSubstitution
= true;
118 case XML_IGNORE_DRIVER_PRIVILEGES
:
119 aProperty
.Name
= INFO_IGNOREDRIVER_PRIV
;
120 aProperty
.Value
<<= IsXMLToken(aIter
, XML_TRUE
);
122 case XML_BOOLEAN_COMPARISON_MODE
:
123 aProperty
.Name
= PROPERTY_BOOLEANCOMPARISONMODE
;
124 if ( aIter
.toView() == "equal-integer" )
125 aProperty
.Value
<<= sal_Int32(0);
126 else if ( aIter
.toView() == "is-boolean" )
127 aProperty
.Value
<<= sal_Int32(1);
128 else if ( aIter
.toView() == "equal-boolean" )
129 aProperty
.Value
<<= sal_Int32(2);
130 else if ( aIter
.toView() == "equal-use-only-zero" )
131 aProperty
.Value
<<= sal_Int32(3);
133 case XML_USE_CATALOG
:
134 aProperty
.Name
= INFO_USECATALOG
;
135 aProperty
.Value
<<= IsXMLToken(aIter
, XML_TRUE
);
138 aProperty
.Name
= INFO_CONN_LDAP_BASEDN
;
140 case XML_MAX_ROW_COUNT
:
141 aProperty
.Name
= INFO_CONN_LDAP_ROWCOUNT
;
142 aProperty
.Value
<<= aIter
.toInt32();
144 case XML_JAVA_CLASSPATH
:
145 aProperty
.Name
= "JavaDriverClassPath";
148 XMLOFF_WARN_UNKNOWN("dbaccess", aIter
);
150 if ( !aProperty
.Name
.isEmpty() )
152 if ( !aProperty
.Value
.hasValue() )
153 aProperty
.Value
<<= aIter
.toString();
154 rImport
.addInfo(aProperty
);
158 if ( !rImport
.isNewFormat() )
161 if ( !bFoundTableNameLengthLimited
&& ( _eUsedFor
== eAppSettings
) )
163 aProperty
.Name
= INFO_ALLOWLONGTABLENAMES
;
164 aProperty
.Value
<<= true;
165 rImport
.addInfo(aProperty
);
167 if ( !bFoundParamNameSubstitution
&& ( _eUsedFor
== eDriverSettings
) )
169 aProperty
.Name
= INFO_PARAMETERNAMESUBST
;
170 aProperty
.Value
<<= true;
171 rImport
.addInfo(aProperty
);
173 if ( !bFoundAppendTableAliasName
&& ( _eUsedFor
== eAppSettings
) )
175 aProperty
.Name
= INFO_APPEND_TABLE_ALIAS
;
176 aProperty
.Value
<<= true;
177 rImport
.addInfo(aProperty
);
179 if ( !bFoundSuppressVersionColumns
&& ( _eUsedFor
== eAppSettings
) )
183 xDataSource
->setPropertyValue(PROPERTY_SUPPRESSVERSIONCL
,Any(true));
185 catch(const Exception
&)
187 DBG_UNHANDLED_EXCEPTION("dbaccess");
192 OXMLDataSource::~OXMLDataSource()
197 css::uno::Reference
< css::xml::sax::XFastContextHandler
> OXMLDataSource::createFastChildContext(
198 sal_Int32 nElement
, const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
)
200 SvXMLImportContext
*pContext
= nullptr;
202 switch( nElement
& TOKEN_MASK
)
205 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP
);
206 pContext
= new OXMLLogin( GetOwnImport(), xAttrList
);
209 case XML_TABLE_FILTER
:
210 case XML_TABLE_TYPE_FILTER
:
211 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP
);
212 pContext
= new OXMLTableFilterList( GetImport() );
214 case XML_AUTO_INCREMENT
:
216 case XML_FONT_CHARSET
:
217 case XML_CHARACTER_SET
:
218 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP
);
219 pContext
= new OXMLDataSourceInfo( GetOwnImport(), nElement
, xAttrList
);
221 case XML_DATA_SOURCE_SETTINGS
:
222 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP
);
223 pContext
= new OXMLDataSourceSettings( GetOwnImport() );
225 case XML_CONNECTION_DATA
:
226 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP
);
227 pContext
= new OXMLConnectionData( GetOwnImport() );
229 case XML_DRIVER_SETTINGS
:
230 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP
);
231 pContext
= new OXMLDataSource( GetOwnImport(), xAttrList
, OXMLDataSource::eDriverSettings
);
233 case XML_APPLICATION_CONNECTION_SETTINGS
:
234 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP
);
235 pContext
= new OXMLDataSource( GetOwnImport(), xAttrList
, OXMLDataSource::eAppSettings
);
238 SAL_WARN("dbaccess", "unknown element " << nElement
);
244 ODBFilter
& OXMLDataSource::GetOwnImport()
246 return static_cast<ODBFilter
&>(GetImport());
249 } // namespace dbaxml
251 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */