1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_dbaxml.hxx"
26 #ifndef DBA_XMLDATASOURCE_HXX
27 #include "xmlDataSource.hxx"
28 #endif
29 #ifndef DBA_XMLLOGIN_HXX
30 #include "xmlLogin.hxx"
31 #endif
32 #ifndef DBA_XMLTABLEFILTERLIST_HXX
33 #include "xmlTableFilterList.hxx"
34 #endif
35 #ifndef DBA_XMLDATASOURCEINFO_HXX
36 #include "xmlDataSourceInfo.hxx"
37 #endif
38 #ifndef DBA_XMLDATASOURCESETTINGS_HXX
39 #include "xmlDataSourceSettings.hxx"
40 #endif
41 #ifndef DBA_XMLDATASOURCESETTING_HXX
42 #include "xmlDataSourceSetting.hxx"
43 #endif
44 #ifndef DBA_XMLFILTER_HXX
45 #include "xmlfilter.hxx"
46 #endif
47 #ifndef _XMLOFF_XMLTOKEN_HXX
48 #include <xmloff/xmltoken.hxx>
49 #endif
50 #ifndef _XMLOFF_XMLNMSPE_HXX
51 #include <xmloff/xmlnmspe.hxx>
52 #endif
53 #ifndef _XMLOFF_NMSPMAP_HXX
54 #include <xmloff/nmspmap.hxx>
55 #endif
56 #ifndef DBA_XMLENUMS_HXX
57 #include "xmlEnums.hxx"
58 #endif
59 #ifndef DBACCESS_SHARED_XMLSTRINGS_HRC
60 #include "xmlstrings.hrc"
61 #endif
62 #ifndef _TOOLS_DEBUG_HXX
63 #include <tools/debug.hxx>
64 #endif
65 #ifndef TOOLS_DIAGNOSE_EX_H
66 #include <tools/diagnose_ex.h>
67 #endif
68 #include "xmlConnectionData.hxx"
69 
70 namespace dbaxml
71 {
72 	using namespace ::com::sun::star::uno;
73 	using namespace ::com::sun::star::xml::sax;
DBG_NAME(OXMLDataSource)74 DBG_NAME(OXMLDataSource)
75 
76 OXMLDataSource::OXMLDataSource( ODBFilter& rImport,
77 				sal_uInt16 nPrfx, const ::rtl::OUString& _sLocalName,
78 				const Reference< XAttributeList > & _xAttrList, const UsedFor _eUsedFor ) :
79 	SvXMLImportContext( rImport, nPrfx, _sLocalName )
80 {
81     DBG_CTOR(OXMLDataSource,NULL);
82 
83 	OSL_ENSURE(_xAttrList.is(),"Attribute list is NULL!");
84 	const SvXMLNamespaceMap& rMap = rImport.GetNamespaceMap();
85 	const SvXMLTokenMap& rTokenMap = rImport.GetDataSourceElemTokenMap();
86 
87 	Reference<XPropertySet> xDataSource = rImport.getDataSource();
88 
89 	PropertyValue aProperty;
90     bool bFoundParamNameSubstitution = false;
91     bool bFoundTableNameLengthLimited = false;
92     bool bFoundAppendTableAliasName = false;
93     bool bFoundSuppressVersionColumns = false;
94 
95 	const sal_Int16 nLength = (xDataSource.is() && _xAttrList.is()) ? _xAttrList->getLength() : 0;
96 	static const ::rtl::OUString s_sTRUE = ::xmloff::token::GetXMLToken(XML_TRUE);
97 	for(sal_Int16 i = 0; i < nLength; ++i)
98 	{
99 		::rtl::OUString sLocalName;
100 		rtl::OUString sAttrName = _xAttrList->getNameByIndex( i );
101 		sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName );
102 		rtl::OUString sValue = _xAttrList->getValueByIndex( i );
103 
104 		aProperty.Name = ::rtl::OUString();
105 		aProperty.Value = Any();
106 
107 		switch( rTokenMap.Get( nPrefix, sLocalName ) )
108 		{
109 			case XML_TOK_CONNECTION_RESOURCE:
110 				try
111 				{
112 					xDataSource->setPropertyValue(PROPERTY_URL,makeAny(sValue));
113 				}
114 				catch(Exception)
115 				{
116                     DBG_UNHANDLED_EXCEPTION();
117 				}
118 				break;
119 			case XML_TOK_SUPPRESS_VERSION_COLUMNS:
120 				try
121 				{
122 					xDataSource->setPropertyValue(PROPERTY_SUPPRESSVERSIONCL,makeAny(sValue == s_sTRUE ? sal_True : sal_False));
123                     bFoundSuppressVersionColumns = true;
124 				}
125 				catch(Exception)
126 				{
127                     DBG_UNHANDLED_EXCEPTION();
128 				}
129 				break;
130 			case XML_TOK_JAVA_DRIVER_CLASS:
131 				aProperty.Name = INFO_JDBCDRIVERCLASS;
132 				break;
133 			case XML_TOK_EXTENSION:
134 				aProperty.Name = INFO_TEXTFILEEXTENSION;
135 				break;
136 			case XML_TOK_IS_FIRST_ROW_HEADER_LINE:
137 				aProperty.Name = INFO_TEXTFILEHEADER;
138 				aProperty.Value <<= (sValue == s_sTRUE ? sal_True : sal_False);
139 				break;
140 			case XML_TOK_SHOW_DELETED:
141 				aProperty.Name = INFO_SHOWDELETEDROWS;
142 				aProperty.Value <<= (sValue == s_sTRUE ? sal_True : sal_False);
143 				break;
144 			case XML_TOK_IS_TABLE_NAME_LENGTH_LIMITED:
145 				aProperty.Name = INFO_ALLOWLONGTABLENAMES;
146 				aProperty.Value <<= (sValue == s_sTRUE ? sal_True : sal_False);
147                 bFoundTableNameLengthLimited = true;
148 				break;
149 			case XML_TOK_SYSTEM_DRIVER_SETTINGS:
150 				aProperty.Name = INFO_ADDITIONALOPTIONS;
151 				break;
152 			case XML_TOK_ENABLE_SQL92_CHECK:
153 				aProperty.Name = PROPERTY_ENABLESQL92CHECK;
154 				aProperty.Value <<= (sValue == s_sTRUE ? sal_True : sal_False);
155 				break;
156 			case XML_TOK_APPEND_TABLE_ALIAS_NAME:
157 				aProperty.Name = INFO_APPEND_TABLE_ALIAS;
158 				aProperty.Value <<= (sValue == s_sTRUE ? sal_True : sal_False);
159                 bFoundAppendTableAliasName = true;
160 				break;
161 			case XML_TOK_PARAMETER_NAME_SUBSTITUTION:
162 				aProperty.Name = INFO_PARAMETERNAMESUBST;
163 				aProperty.Value <<= (sValue == s_sTRUE ? sal_True : sal_False);
164                 bFoundParamNameSubstitution = true;
165 				break;
166 			case XML_TOK_IGNORE_DRIVER_PRIVILEGES:
167 				aProperty.Name = INFO_IGNOREDRIVER_PRIV;
168 				aProperty.Value <<= (sValue == s_sTRUE ? sal_True : sal_False);
169 				break;
170 			case XML_TOK_BOOLEAN_COMPARISON_MODE:
171 				aProperty.Name = PROPERTY_BOOLEANCOMPARISONMODE;
172 				if ( sValue.equalsAscii("equal-integer") )
173 					aProperty.Value <<= sal_Int32(0);
174 				else if ( sValue.equalsAscii("is-boolean") )
175 					aProperty.Value <<= sal_Int32(1);
176 				else if ( sValue.equalsAscii("equal-boolean") )
177 					aProperty.Value <<= sal_Int32(2);
178 				else if ( sValue.equalsAscii("equal-use-only-zero") )
179 					aProperty.Value <<= sal_Int32(3);
180 				break;
181 			case XML_TOK_USE_CATALOG:
182 				aProperty.Name = INFO_USECATALOG;
183 				aProperty.Value <<= (sValue == s_sTRUE ? sal_True : sal_False);
184 				break;
185 			case XML_TOK_BASE_DN:
186 				aProperty.Name = INFO_CONN_LDAP_BASEDN;
187 				break;
188 			case XML_TOK_MAX_ROW_COUNT:
189 				aProperty.Name = INFO_CONN_LDAP_ROWCOUNT;
190 				aProperty.Value <<= sValue.toInt32();
191 				break;
192             case XML_TOK_JAVA_CLASSPATH:
193                 aProperty.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JavaDriverClassPath"));
194                 break;
195 		}
196 		if ( aProperty.Name.getLength() )
197 		{
198 			if ( !aProperty.Value.hasValue() )
199 				aProperty.Value <<= sValue;
200 			rImport.addInfo(aProperty);
201 		}
202 	}
203     if ( rImport.isNewFormat() )
204     {
205         if ( !bFoundTableNameLengthLimited && ( _eUsedFor == eAppSettings ) )
206         {
207             aProperty.Name = INFO_ALLOWLONGTABLENAMES;
208             aProperty.Value <<= sal_True;
209 		    rImport.addInfo(aProperty);
210         }
211         if ( !bFoundParamNameSubstitution && ( _eUsedFor == eDriverSettings ) )
212         {
213             aProperty.Name = INFO_PARAMETERNAMESUBST;
214             aProperty.Value <<= sal_True;
215 		    rImport.addInfo(aProperty);
216         }
217         if ( !bFoundAppendTableAliasName && ( _eUsedFor == eAppSettings ) )
218         {
219             aProperty.Name = INFO_APPEND_TABLE_ALIAS;
220             aProperty.Value <<= sal_True;
221 		    rImport.addInfo(aProperty);
222         }
223         if ( !bFoundSuppressVersionColumns && ( _eUsedFor == eAppSettings ) )
224         {
225             try
226 			{
227 				xDataSource->setPropertyValue(PROPERTY_SUPPRESSVERSIONCL,makeAny(sal_True));
228 			}
229 			catch(Exception)
230 			{
231                 DBG_UNHANDLED_EXCEPTION();
232 			}
233         }
234     }
235 }
236 // -----------------------------------------------------------------------------
237 
~OXMLDataSource()238 OXMLDataSource::~OXMLDataSource()
239 {
240 
241     DBG_DTOR(OXMLDataSource,NULL);
242 }
243 // -----------------------------------------------------------------------------
244 
CreateChildContext(sal_uInt16 nPrefix,const::rtl::OUString & rLocalName,const Reference<XAttributeList> & xAttrList)245 SvXMLImportContext* OXMLDataSource::CreateChildContext(
246 		sal_uInt16 nPrefix,
247 		const ::rtl::OUString& rLocalName,
248 		const Reference< XAttributeList > & xAttrList )
249 {
250 	SvXMLImportContext *pContext = 0;
251 	const SvXMLTokenMap&	rTokenMap	= GetOwnImport().GetDataSourceElemTokenMap();
252     const sal_uInt16 nToken = rTokenMap.Get( nPrefix, rLocalName );
253 
254 	switch( nToken )
255 	{
256 		case XML_TOK_LOGIN:
257 			GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
258 			pContext = new OXMLLogin( GetOwnImport(), nPrefix, rLocalName,xAttrList );
259 			break;
260 
261 		case XML_TOK_TABLE_FILTER:
262 		case XML_TOK_TABLE_TYPE_FILTER:
263 			GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
264 			pContext = new OXMLTableFilterList( GetImport(), nPrefix, rLocalName );
265 			break;
266 		case XML_TOK_AUTO_INCREMENT:
267 		case XML_TOK_DELIMITER:
268 		case XML_TOK_FONT_CHARSET:
269         case XML_TOK_CHARACTER_SET:
270 			GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
271 			pContext = new OXMLDataSourceInfo( GetOwnImport(), nPrefix, rLocalName,xAttrList,nToken);
272 			break;
273 		case XML_TOK_DATA_SOURCE_SETTINGS:
274 			GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
275 			pContext = new OXMLDataSourceSettings( GetOwnImport(), nPrefix, rLocalName);
276 			break;
277         case XML_TOK_CONNECTION_DATA:
278             GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
279 			pContext = new OXMLConnectionData( GetOwnImport(), nPrefix, rLocalName);
280             break;
281         case XML_TOK_DRIVER_SETTINGS:
282             GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
283             pContext = new OXMLDataSource( GetOwnImport(), nPrefix, rLocalName, xAttrList, OXMLDataSource::eDriverSettings );
284             break;
285         case XML_TOK_APPLICATION_CONNECTION_SETTINGS:
286             GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
287 			pContext = new OXMLDataSource( GetOwnImport(), nPrefix, rLocalName, xAttrList, OXMLDataSource::eAppSettings );
288             break;
289 	}
290 
291 	if( !pContext )
292 		pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
293 
294 	return pContext;
295 }
296 // -----------------------------------------------------------------------------
GetOwnImport()297 ODBFilter& OXMLDataSource::GetOwnImport()
298 {
299 	return static_cast<ODBFilter&>(GetImport());
300 }
301 // -----------------------------------------------------------------------------
302 
303 //----------------------------------------------------------------------------
304 } // namespace dbaxml
305 // -----------------------------------------------------------------------------
306