Line data Source code
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"
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"
35 :
36 : namespace dbaxml
37 : {
38 : using namespace ::com::sun::star::uno;
39 : using namespace ::com::sun::star::xml::sax;
40 : DBG_NAME(OXMLDataSource)
41 :
42 0 : OXMLDataSource::OXMLDataSource( ODBFilter& rImport,
43 : sal_uInt16 nPrfx, const ::rtl::OUString& _sLocalName,
44 : const Reference< XAttributeList > & _xAttrList, const UsedFor _eUsedFor ) :
45 0 : SvXMLImportContext( rImport, nPrfx, _sLocalName )
46 : {
47 : DBG_CTOR(OXMLDataSource,NULL);
48 :
49 : OSL_ENSURE(_xAttrList.is(),"Attribute list is NULL!");
50 0 : const SvXMLNamespaceMap& rMap = rImport.GetNamespaceMap();
51 0 : const SvXMLTokenMap& rTokenMap = rImport.GetDataSourceElemTokenMap();
52 :
53 0 : Reference<XPropertySet> xDataSource = rImport.getDataSource();
54 :
55 0 : PropertyValue aProperty;
56 0 : bool bFoundParamNameSubstitution = false;
57 0 : bool bFoundTableNameLengthLimited = false;
58 0 : bool bFoundAppendTableAliasName = false;
59 0 : bool bFoundSuppressVersionColumns = false;
60 :
61 0 : const sal_Int16 nLength = (xDataSource.is() && _xAttrList.is()) ? _xAttrList->getLength() : 0;
62 0 : static const ::rtl::OUString s_sTRUE = ::xmloff::token::GetXMLToken(XML_TRUE);
63 0 : for(sal_Int16 i = 0; i < nLength; ++i)
64 : {
65 0 : ::rtl::OUString sLocalName;
66 0 : rtl::OUString sAttrName = _xAttrList->getNameByIndex( i );
67 0 : sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName );
68 0 : rtl::OUString sValue = _xAttrList->getValueByIndex( i );
69 :
70 0 : aProperty.Name = ::rtl::OUString();
71 0 : aProperty.Value = Any();
72 :
73 0 : switch( rTokenMap.Get( nPrefix, sLocalName ) )
74 : {
75 : case XML_TOK_CONNECTION_RESOURCE:
76 : try
77 : {
78 0 : xDataSource->setPropertyValue(PROPERTY_URL,makeAny(sValue));
79 : }
80 0 : catch(const Exception&)
81 : {
82 : DBG_UNHANDLED_EXCEPTION();
83 : }
84 0 : break;
85 : case XML_TOK_SUPPRESS_VERSION_COLUMNS:
86 : try
87 : {
88 0 : xDataSource->setPropertyValue(PROPERTY_SUPPRESSVERSIONCL,makeAny(sValue == s_sTRUE ? sal_True : sal_False));
89 0 : bFoundSuppressVersionColumns = true;
90 : }
91 0 : catch(const Exception&)
92 : {
93 : DBG_UNHANDLED_EXCEPTION();
94 : }
95 0 : break;
96 : case XML_TOK_JAVA_DRIVER_CLASS:
97 0 : aProperty.Name = INFO_JDBCDRIVERCLASS;
98 0 : break;
99 : case XML_TOK_EXTENSION:
100 0 : aProperty.Name = INFO_TEXTFILEEXTENSION;
101 0 : break;
102 : case XML_TOK_IS_FIRST_ROW_HEADER_LINE:
103 0 : aProperty.Name = INFO_TEXTFILEHEADER;
104 0 : aProperty.Value <<= (sValue == s_sTRUE ? sal_True : sal_False);
105 0 : break;
106 : case XML_TOK_SHOW_DELETED:
107 0 : aProperty.Name = INFO_SHOWDELETEDROWS;
108 0 : aProperty.Value <<= (sValue == s_sTRUE ? sal_True : sal_False);
109 0 : break;
110 : case XML_TOK_IS_TABLE_NAME_LENGTH_LIMITED:
111 0 : aProperty.Name = INFO_ALLOWLONGTABLENAMES;
112 0 : aProperty.Value <<= (sValue == s_sTRUE ? sal_True : sal_False);
113 0 : bFoundTableNameLengthLimited = true;
114 0 : break;
115 : case XML_TOK_SYSTEM_DRIVER_SETTINGS:
116 0 : aProperty.Name = INFO_ADDITIONALOPTIONS;
117 0 : break;
118 : case XML_TOK_ENABLE_SQL92_CHECK:
119 0 : aProperty.Name = PROPERTY_ENABLESQL92CHECK;
120 0 : aProperty.Value <<= (sValue == s_sTRUE ? sal_True : sal_False);
121 0 : break;
122 : case XML_TOK_APPEND_TABLE_ALIAS_NAME:
123 0 : aProperty.Name = INFO_APPEND_TABLE_ALIAS;
124 0 : aProperty.Value <<= (sValue == s_sTRUE ? sal_True : sal_False);
125 0 : bFoundAppendTableAliasName = true;
126 0 : break;
127 : case XML_TOK_PARAMETER_NAME_SUBSTITUTION:
128 0 : aProperty.Name = INFO_PARAMETERNAMESUBST;
129 0 : aProperty.Value <<= (sValue == s_sTRUE ? sal_True : sal_False);
130 0 : bFoundParamNameSubstitution = true;
131 0 : break;
132 : case XML_TOK_IGNORE_DRIVER_PRIVILEGES:
133 0 : aProperty.Name = INFO_IGNOREDRIVER_PRIV;
134 0 : aProperty.Value <<= (sValue == s_sTRUE ? sal_True : sal_False);
135 0 : break;
136 : case XML_TOK_BOOLEAN_COMPARISON_MODE:
137 0 : aProperty.Name = PROPERTY_BOOLEANCOMPARISONMODE;
138 0 : if ( sValue == "equal-integer" )
139 0 : aProperty.Value <<= sal_Int32(0);
140 0 : else if ( sValue == "is-boolean" )
141 0 : aProperty.Value <<= sal_Int32(1);
142 0 : else if ( sValue == "equal-boolean" )
143 0 : aProperty.Value <<= sal_Int32(2);
144 0 : else if ( sValue == "equal-use-only-zero" )
145 0 : aProperty.Value <<= sal_Int32(3);
146 0 : break;
147 : case XML_TOK_USE_CATALOG:
148 0 : aProperty.Name = INFO_USECATALOG;
149 0 : aProperty.Value <<= (sValue == s_sTRUE ? sal_True : sal_False);
150 0 : break;
151 : case XML_TOK_BASE_DN:
152 0 : aProperty.Name = INFO_CONN_LDAP_BASEDN;
153 0 : break;
154 : case XML_TOK_MAX_ROW_COUNT:
155 0 : aProperty.Name = INFO_CONN_LDAP_ROWCOUNT;
156 0 : aProperty.Value <<= sValue.toInt32();
157 0 : break;
158 : case XML_TOK_JAVA_CLASSPATH:
159 0 : aProperty.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JavaDriverClassPath"));
160 0 : break;
161 : }
162 0 : if ( !aProperty.Name.isEmpty() )
163 : {
164 0 : if ( !aProperty.Value.hasValue() )
165 0 : aProperty.Value <<= sValue;
166 0 : rImport.addInfo(aProperty);
167 : }
168 0 : }
169 0 : if ( rImport.isNewFormat() )
170 : {
171 0 : if ( !bFoundTableNameLengthLimited && ( _eUsedFor == eAppSettings ) )
172 : {
173 0 : aProperty.Name = INFO_ALLOWLONGTABLENAMES;
174 0 : aProperty.Value <<= sal_True;
175 0 : rImport.addInfo(aProperty);
176 : }
177 0 : if ( !bFoundParamNameSubstitution && ( _eUsedFor == eDriverSettings ) )
178 : {
179 0 : aProperty.Name = INFO_PARAMETERNAMESUBST;
180 0 : aProperty.Value <<= sal_True;
181 0 : rImport.addInfo(aProperty);
182 : }
183 0 : if ( !bFoundAppendTableAliasName && ( _eUsedFor == eAppSettings ) )
184 : {
185 0 : aProperty.Name = INFO_APPEND_TABLE_ALIAS;
186 0 : aProperty.Value <<= sal_True;
187 0 : rImport.addInfo(aProperty);
188 : }
189 0 : if ( !bFoundSuppressVersionColumns && ( _eUsedFor == eAppSettings ) )
190 : {
191 : try
192 : {
193 0 : xDataSource->setPropertyValue(PROPERTY_SUPPRESSVERSIONCL,makeAny(sal_True));
194 : }
195 0 : catch(const Exception&)
196 : {
197 : DBG_UNHANDLED_EXCEPTION();
198 : }
199 : }
200 0 : }
201 0 : }
202 : // -----------------------------------------------------------------------------
203 :
204 0 : OXMLDataSource::~OXMLDataSource()
205 : {
206 :
207 : DBG_DTOR(OXMLDataSource,NULL);
208 0 : }
209 : // -----------------------------------------------------------------------------
210 :
211 0 : SvXMLImportContext* OXMLDataSource::CreateChildContext(
212 : sal_uInt16 nPrefix,
213 : const ::rtl::OUString& rLocalName,
214 : const Reference< XAttributeList > & xAttrList )
215 : {
216 0 : SvXMLImportContext *pContext = 0;
217 0 : const SvXMLTokenMap& rTokenMap = GetOwnImport().GetDataSourceElemTokenMap();
218 0 : const sal_uInt16 nToken = rTokenMap.Get( nPrefix, rLocalName );
219 :
220 0 : switch( nToken )
221 : {
222 : case XML_TOK_LOGIN:
223 0 : GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
224 0 : pContext = new OXMLLogin( GetOwnImport(), nPrefix, rLocalName,xAttrList );
225 0 : break;
226 :
227 : case XML_TOK_TABLE_FILTER:
228 : case XML_TOK_TABLE_TYPE_FILTER:
229 0 : GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
230 0 : pContext = new OXMLTableFilterList( GetImport(), nPrefix, rLocalName );
231 0 : break;
232 : case XML_TOK_AUTO_INCREMENT:
233 : case XML_TOK_DELIMITER:
234 : case XML_TOK_FONT_CHARSET:
235 : case XML_TOK_CHARACTER_SET:
236 0 : GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
237 0 : pContext = new OXMLDataSourceInfo( GetOwnImport(), nPrefix, rLocalName,xAttrList,nToken);
238 0 : break;
239 : case XML_TOK_DATA_SOURCE_SETTINGS:
240 0 : GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
241 0 : pContext = new OXMLDataSourceSettings( GetOwnImport(), nPrefix, rLocalName);
242 0 : break;
243 : case XML_TOK_CONNECTION_DATA:
244 0 : GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
245 0 : pContext = new OXMLConnectionData( GetOwnImport(), nPrefix, rLocalName);
246 0 : break;
247 : case XML_TOK_DRIVER_SETTINGS:
248 0 : GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
249 0 : pContext = new OXMLDataSource( GetOwnImport(), nPrefix, rLocalName, xAttrList, OXMLDataSource::eDriverSettings );
250 0 : break;
251 : case XML_TOK_APPLICATION_CONNECTION_SETTINGS:
252 0 : GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
253 0 : pContext = new OXMLDataSource( GetOwnImport(), nPrefix, rLocalName, xAttrList, OXMLDataSource::eAppSettings );
254 0 : break;
255 : }
256 :
257 0 : if( !pContext )
258 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
259 :
260 0 : return pContext;
261 : }
262 : // -----------------------------------------------------------------------------
263 0 : ODBFilter& OXMLDataSource::GetOwnImport()
264 : {
265 0 : return static_cast<ODBFilter&>(GetImport());
266 : }
267 : // -----------------------------------------------------------------------------
268 :
269 : //----------------------------------------------------------------------------
270 : } // namespace dbaxml
271 : // -----------------------------------------------------------------------------
272 :
273 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|