LibreOffice Module dbaccess (master) 1
xmlDataSource.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include "xmlDataSource.hxx"
21#include "xmlLogin.hxx"
23#include "xmlDataSourceInfo.hxx"
25#include "xmlfilter.hxx"
26#include <xmloff/xmltoken.hxx>
28#include "xmlEnums.hxx"
29#include <strings.hxx>
31#include "xmlConnectionData.hxx"
32
33namespace dbaxml
34{
35 using namespace ::com::sun::star::uno;
36 using namespace ::com::sun::star::xml::sax;
37
39 const css::uno::Reference< css::xml::sax::XFastAttributeList >& _xAttrList,
40 const UsedFor _eUsedFor ) :
41 SvXMLImportContext( rImport )
42{
43
44 Reference<XPropertySet> xDataSource = rImport.getDataSource();
45
46 PropertyValue aProperty;
47 bool bFoundParamNameSubstitution = false;
48 bool bFoundTableNameLengthLimited = false;
49 bool bFoundAppendTableAliasName = false;
50 bool bFoundSuppressVersionColumns = false;
51
52 if (xDataSource.is())
53 {
54 for (auto &aIter : sax_fastparser::castToFastAttributeList( _xAttrList ))
55 {
56 aProperty.Name.clear();
57 aProperty.Value = Any();
58
59 switch( aIter.getToken() & TOKEN_MASK )
60 {
62 try
63 {
64 xDataSource->setPropertyValue(PROPERTY_URL,Any(aIter.toString()));
65 }
66 catch(const Exception&)
67 {
68 DBG_UNHANDLED_EXCEPTION("dbaccess");
69 }
70 break;
72 try
73 {
74 xDataSource->setPropertyValue(PROPERTY_SUPPRESSVERSIONCL,Any(IsXMLToken(aIter, XML_TRUE)));
75 bFoundSuppressVersionColumns = true;
76 }
77 catch(const Exception&)
78 {
79 DBG_UNHANDLED_EXCEPTION("dbaccess");
80 }
81 break;
83 aProperty.Name = INFO_JDBCDRIVERCLASS;
84 break;
85 case XML_EXTENSION:
86 aProperty.Name = INFO_TEXTFILEEXTENSION;
87 break;
89 aProperty.Name = INFO_TEXTFILEHEADER;
90 aProperty.Value <<= IsXMLToken(aIter, XML_TRUE);
91 break;
93 aProperty.Name = INFO_SHOWDELETEDROWS;
94 aProperty.Value <<= IsXMLToken(aIter, XML_TRUE);
95 break;
97 aProperty.Name = INFO_ALLOWLONGTABLENAMES;
98 aProperty.Value <<= IsXMLToken(aIter, XML_TRUE);
99 bFoundTableNameLengthLimited = true;
100 break;
102 aProperty.Name = INFO_ADDITIONALOPTIONS;
103 break;
105 aProperty.Name = PROPERTY_ENABLESQL92CHECK;
106 aProperty.Value <<= IsXMLToken(aIter, XML_TRUE);
107 break;
109 aProperty.Name = INFO_APPEND_TABLE_ALIAS;
110 aProperty.Value <<= IsXMLToken(aIter, XML_TRUE);
111 bFoundAppendTableAliasName = true;
112 break;
114 aProperty.Name = INFO_PARAMETERNAMESUBST;
115 aProperty.Value <<= IsXMLToken(aIter, XML_TRUE);
116 bFoundParamNameSubstitution = true;
117 break;
119 aProperty.Name = INFO_IGNOREDRIVER_PRIV;
120 aProperty.Value <<= IsXMLToken(aIter, XML_TRUE);
121 break;
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);
132 break;
133 case XML_USE_CATALOG:
134 aProperty.Name = INFO_USECATALOG;
135 aProperty.Value <<= IsXMLToken(aIter, XML_TRUE);
136 break;
137 case XML_BASE_DN:
138 aProperty.Name = INFO_CONN_LDAP_BASEDN;
139 break;
141 aProperty.Name = INFO_CONN_LDAP_ROWCOUNT;
142 aProperty.Value <<= aIter.toInt32();
143 break;
145 aProperty.Name = "JavaDriverClassPath";
146 break;
147 default:
148 XMLOFF_WARN_UNKNOWN("dbaccess", aIter);
149 }
150 if ( !aProperty.Name.isEmpty() )
151 {
152 if ( !aProperty.Value.hasValue() )
153 aProperty.Value <<= aIter.toString();
154 rImport.addInfo(aProperty);
155 }
156 }
157 }
158 if ( !rImport.isNewFormat() )
159 return;
160
161 if ( !bFoundTableNameLengthLimited && ( _eUsedFor == eAppSettings ) )
162 {
163 aProperty.Name = INFO_ALLOWLONGTABLENAMES;
164 aProperty.Value <<= true;
165 rImport.addInfo(aProperty);
166 }
167 if ( !bFoundParamNameSubstitution && ( _eUsedFor == eDriverSettings ) )
168 {
169 aProperty.Name = INFO_PARAMETERNAMESUBST;
170 aProperty.Value <<= true;
171 rImport.addInfo(aProperty);
172 }
173 if ( !bFoundAppendTableAliasName && ( _eUsedFor == eAppSettings ) )
174 {
175 aProperty.Name = INFO_APPEND_TABLE_ALIAS;
176 aProperty.Value <<= true;
177 rImport.addInfo(aProperty);
178 }
179 if ( !bFoundSuppressVersionColumns && ( _eUsedFor == eAppSettings ) )
180 {
181 try
182 {
183 xDataSource->setPropertyValue(PROPERTY_SUPPRESSVERSIONCL,Any(true));
184 }
185 catch(const Exception&)
186 {
187 DBG_UNHANDLED_EXCEPTION("dbaccess");
188 }
189 }
190}
191
193{
194
195}
196
197css::uno::Reference< css::xml::sax::XFastContextHandler > OXMLDataSource::createFastChildContext(
198 sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
199{
200 SvXMLImportContext *pContext = nullptr;
201
202 switch( nElement & TOKEN_MASK )
203 {
204 case XML_LOGIN:
205 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
206 pContext = new OXMLLogin( GetOwnImport(), xAttrList );
207 break;
208
209 case XML_TABLE_FILTER:
211 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
212 pContext = new OXMLTableFilterList( GetImport() );
213 break;
215 case XML_DELIMITER:
216 case XML_FONT_CHARSET:
218 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
219 pContext = new OXMLDataSourceInfo( GetOwnImport(), nElement, xAttrList );
220 break;
222 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
223 pContext = new OXMLDataSourceSettings( GetOwnImport() );
224 break;
226 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
227 pContext = new OXMLConnectionData( GetOwnImport() );
228 break;
230 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
231 pContext = new OXMLDataSource( GetOwnImport(), xAttrList, OXMLDataSource::eDriverSettings );
232 break;
234 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
235 pContext = new OXMLDataSource( GetOwnImport(), xAttrList, OXMLDataSource::eAppSettings );
236 break;
237 default:
238 SAL_WARN("dbaccess", "unknown element " << nElement);
239 }
240
241 return pContext;
242}
243
245{
246 return static_cast<ODBFilter&>(GetImport());
247}
248
249} // namespace dbaxml
250
251/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SvXMLImport & GetImport()
bool isNewFormat() const
Definition: xmlfilter.hxx:115
void addInfo(const css::beans::PropertyValue &_rInfo)
add an Info to the sequence which will be appended to the data source
Definition: xmlfilter.hxx:108
const Reference< XPropertySet > & getDataSource() const
Definition: xmlfilter.hxx:97
OXMLDataSource(ODBFilter &rImport, const css::uno::Reference< css::xml::sax::XFastAttributeList > &_xAttrList, const UsedFor _eUsedFor)
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &AttrList) override
virtual ~OXMLDataSource() override
ODBFilter & GetOwnImport()
#define DBG_UNHANDLED_EXCEPTION(...)
#define SAL_WARN(area, stream)
@ Exception
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
XML_DELIMITER
XML_CONNECTION_DATA
XML_DRIVER_SETTINGS
XML_IGNORE_DRIVER_PRIVILEGES
XML_SUPPRESS_VERSION_COLUMNS
XML_JAVA_CLASSPATH
XML_USE_CATALOG
XML_TRUE
XML_AUTO_INCREMENT
XML_IS_TABLE_NAME_LENGTH_LIMITED
XML_BASE_DN
XML_SYSTEM_DRIVER_SETTINGS
XML_LOGIN
XML_DATA_SOURCE_SETTINGS
XML_TABLE_FILTER
XML_MAX_ROW_COUNT
XML_IS_FIRST_ROW_HEADER_LINE
XML_JAVA_DRIVER_CLASS
XML_PARAMETER_NAME_SUBSTITUTION
XML_CONNECTION_RESOURCE
XML_CHARACTER_SET
XML_APPEND_TABLE_ALIAS_NAME
XML_APPLICATION_CONNECTION_SETTINGS
XML_BOOLEAN_COMPARISON_MODE
XML_SHOW_DELETED
XML_EXTENSION
XML_ENABLE_SQL92_CHECK
XML_TABLE_TYPE_FILTER
XML_FONT_CHARSET
bool IsXMLToken(std::u16string_view rString, enum XMLTokenEnum eToken)
constexpr OUStringLiteral INFO_JDBCDRIVERCLASS
Definition: strings.hxx:206
constexpr OUStringLiteral INFO_TEXTFILEEXTENSION
Definition: strings.hxx:207
constexpr OUStringLiteral INFO_SHOWDELETEDROWS
Definition: strings.hxx:214
constexpr OUStringLiteral PROPERTY_URL(u"URL")
constexpr OUStringLiteral PROPERTY_ENABLESQL92CHECK(u"EnableSQL92Check")
constexpr OUStringLiteral INFO_APPEND_TABLE_ALIAS
Definition: strings.hxx:219
constexpr OUStringLiteral INFO_TEXTFILEHEADER
Definition: strings.hxx:209
constexpr OUStringLiteral INFO_CONN_LDAP_ROWCOUNT
Definition: strings.hxx:227
constexpr OUStringLiteral INFO_PARAMETERNAMESUBST
Definition: strings.hxx:223
constexpr OUStringLiteral INFO_IGNOREDRIVER_PRIV
Definition: strings.hxx:224
constexpr OUStringLiteral PROPERTY_BOOLEANCOMPARISONMODE(u"BooleanComparisonMode")
constexpr OUStringLiteral INFO_ADDITIONALOPTIONS
Definition: strings.hxx:216
constexpr OUStringLiteral PROPERTY_SUPPRESSVERSIONCL(u"SuppressVersionColumns")
constexpr OUStringLiteral INFO_ALLOWLONGTABLENAMES
Definition: strings.hxx:215
constexpr OUStringLiteral INFO_CONN_LDAP_BASEDN
Definition: strings.hxx:226
constexpr OUStringLiteral INFO_USECATALOG
Definition: strings.hxx:225
#define PROGRESS_BAR_STEP
Definition: xmlEnums.hxx:21
#define XMLOFF_WARN_UNKNOWN(area, rIter)
constexpr sal_Int32 TOKEN_MASK