tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / dbaccess / source / filter / xml / xmlDataSource.cxx
blob9939a197b1aa61c2c827a886963e456d44e2a30e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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"
33 namespace dbaxml
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 if (xDataSource.is())
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:
62 try
64 xDataSource->setPropertyValue(PROPERTY_URL,Any(aIter.toString()));
66 catch(const Exception&)
68 DBG_UNHANDLED_EXCEPTION("dbaccess");
70 break;
71 case XML_SUPPRESS_VERSION_COLUMNS:
72 try
74 xDataSource->setPropertyValue(PROPERTY_SUPPRESSVERSIONCL,Any(IsXMLToken(aIter, XML_TRUE)));
75 bFoundSuppressVersionColumns = true;
77 catch(const Exception&)
79 DBG_UNHANDLED_EXCEPTION("dbaccess");
81 break;
82 case XML_JAVA_DRIVER_CLASS:
83 aProperty.Name = INFO_JDBCDRIVERCLASS;
84 break;
85 case XML_EXTENSION:
86 aProperty.Name = INFO_TEXTFILEEXTENSION;
87 break;
88 case XML_IS_FIRST_ROW_HEADER_LINE:
89 aProperty.Name = INFO_TEXTFILEHEADER;
90 aProperty.Value <<= IsXMLToken(aIter, XML_TRUE);
91 break;
92 case XML_SHOW_DELETED:
93 aProperty.Name = INFO_SHOWDELETEDROWS;
94 aProperty.Value <<= IsXMLToken(aIter, XML_TRUE);
95 break;
96 case XML_IS_TABLE_NAME_LENGTH_LIMITED:
97 aProperty.Name = INFO_ALLOWLONGTABLENAMES;
98 aProperty.Value <<= IsXMLToken(aIter, XML_TRUE);
99 bFoundTableNameLengthLimited = true;
100 break;
101 case XML_SYSTEM_DRIVER_SETTINGS:
102 aProperty.Name = INFO_ADDITIONALOPTIONS;
103 break;
104 case XML_ENABLE_SQL92_CHECK:
105 aProperty.Name = PROPERTY_ENABLESQL92CHECK;
106 aProperty.Value <<= IsXMLToken(aIter, XML_TRUE);
107 break;
108 case XML_APPEND_TABLE_ALIAS_NAME:
109 aProperty.Name = INFO_APPEND_TABLE_ALIAS;
110 aProperty.Value <<= IsXMLToken(aIter, XML_TRUE);
111 bFoundAppendTableAliasName = true;
112 break;
113 case XML_PARAMETER_NAME_SUBSTITUTION:
114 aProperty.Name = INFO_PARAMETERNAMESUBST;
115 aProperty.Value <<= IsXMLToken(aIter, XML_TRUE);
116 bFoundParamNameSubstitution = true;
117 break;
118 case XML_IGNORE_DRIVER_PRIVILEGES:
119 aProperty.Name = INFO_IGNOREDRIVER_PRIV;
120 aProperty.Value <<= IsXMLToken(aIter, XML_TRUE);
121 break;
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);
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;
140 case XML_MAX_ROW_COUNT:
141 aProperty.Name = INFO_CONN_LDAP_ROWCOUNT;
142 aProperty.Value <<= aIter.toInt32();
143 break;
144 case XML_JAVA_CLASSPATH:
145 aProperty.Name = "JavaDriverClassPath";
146 break;
147 default:
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() )
159 return;
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 )
204 case XML_LOGIN:
205 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
206 pContext = new OXMLLogin( GetOwnImport(), xAttrList );
207 break;
209 case XML_TABLE_FILTER:
210 case XML_TABLE_TYPE_FILTER:
211 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
212 pContext = new OXMLTableFilterList( GetImport() );
213 break;
214 case XML_AUTO_INCREMENT:
215 case XML_DELIMITER:
216 case XML_FONT_CHARSET:
217 case XML_CHARACTER_SET:
218 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
219 pContext = new OXMLDataSourceInfo( GetOwnImport(), nElement, xAttrList );
220 break;
221 case XML_DATA_SOURCE_SETTINGS:
222 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
223 pContext = new OXMLDataSourceSettings( GetOwnImport() );
224 break;
225 case XML_CONNECTION_DATA:
226 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
227 pContext = new OXMLConnectionData( GetOwnImport() );
228 break;
229 case XML_DRIVER_SETTINGS:
230 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
231 pContext = new OXMLDataSource( GetOwnImport(), xAttrList, OXMLDataSource::eDriverSettings );
232 break;
233 case XML_APPLICATION_CONNECTION_SETTINGS:
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);
241 return pContext;
244 ODBFilter& OXMLDataSource::GetOwnImport()
246 return static_cast<ODBFilter&>(GetImport());
249 } // namespace dbaxml
251 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */