1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xmlDataSource.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
33 #ifndef DBA_XMLDATASOURCE_HXX
34 #include "xmlDataSource.hxx"
36 #ifndef DBA_XMLLOGIN_HXX
37 #include "xmlLogin.hxx"
39 #ifndef DBA_XMLTABLEFILTERLIST_HXX
40 #include "xmlTableFilterList.hxx"
42 #ifndef DBA_XMLDATASOURCEINFO_HXX
43 #include "xmlDataSourceInfo.hxx"
45 #ifndef DBA_XMLDATASOURCESETTINGS_HXX
46 #include "xmlDataSourceSettings.hxx"
48 #ifndef DBA_XMLDATASOURCESETTING_HXX
49 #include "xmlDataSourceSetting.hxx"
51 #ifndef DBA_XMLFILTER_HXX
52 #include "xmlfilter.hxx"
54 #ifndef _XMLOFF_XMLTOKEN_HXX
55 #include <xmloff/xmltoken.hxx>
57 #ifndef _XMLOFF_XMLNMSPE_HXX
58 #include <xmloff/xmlnmspe.hxx>
60 #ifndef _XMLOFF_NMSPMAP_HXX
61 #include <xmloff/nmspmap.hxx>
63 #ifndef DBA_XMLENUMS_HXX
64 #include "xmlEnums.hxx"
66 #ifndef DBACCESS_SHARED_XMLSTRINGS_HRC
67 #include "xmlstrings.hrc"
69 #ifndef _TOOLS_DEBUG_HXX
70 #include <tools/debug.hxx>
72 #ifndef TOOLS_DIAGNOSE_EX_H
73 #include <tools/diagnose_ex.h>
75 #include "xmlConnectionData.hxx"
76 #include "xmlJavaClassPath.hxx"
79 using namespace ::com::sun::star::uno
;
80 using namespace ::com::sun::star::xml::sax
;
81 DBG_NAME(OXMLDataSource
)
83 OXMLDataSource::OXMLDataSource( ODBFilter
& rImport
,
84 sal_uInt16 nPrfx
, const ::rtl::OUString
& _sLocalName
,
85 const Reference
< XAttributeList
> & _xAttrList
, const UsedFor _eUsedFor
) :
86 SvXMLImportContext( rImport
, nPrfx
, _sLocalName
)
88 DBG_CTOR(OXMLDataSource
,NULL
);
90 OSL_ENSURE(_xAttrList
.is(),"Attribute list is NULL!");
91 const SvXMLNamespaceMap
& rMap
= rImport
.GetNamespaceMap();
92 const SvXMLTokenMap
& rTokenMap
= rImport
.GetDataSourceElemTokenMap();
94 Reference
<XPropertySet
> xDataSource
= rImport
.getDataSource();
96 PropertyValue aProperty
;
97 bool bFoundParamNameSubstitution
= false;
98 bool bFoundTableNameLengthLimited
= false;
99 bool bFoundAppendTableAliasName
= false;
100 bool bFoundSuppressVersionColumns
= false;
102 const sal_Int16 nLength
= (xDataSource
.is() && _xAttrList
.is()) ? _xAttrList
->getLength() : 0;
103 static const ::rtl::OUString s_sTRUE
= ::xmloff::token::GetXMLToken(XML_TRUE
);
104 for(sal_Int16 i
= 0; i
< nLength
; ++i
)
106 ::rtl::OUString sLocalName
;
107 rtl::OUString sAttrName
= _xAttrList
->getNameByIndex( i
);
108 sal_uInt16 nPrefix
= rMap
.GetKeyByAttrName( sAttrName
,&sLocalName
);
109 rtl::OUString sValue
= _xAttrList
->getValueByIndex( i
);
111 aProperty
.Name
= ::rtl::OUString();
112 aProperty
.Value
= Any();
114 switch( rTokenMap
.Get( nPrefix
, sLocalName
) )
116 case XML_TOK_CONNECTION_RESOURCE
:
119 xDataSource
->setPropertyValue(PROPERTY_URL
,makeAny(sValue
));
123 DBG_UNHANDLED_EXCEPTION();
126 case XML_TOK_SUPPRESS_VERSION_COLUMNS
:
129 xDataSource
->setPropertyValue(PROPERTY_SUPPRESSVERSIONCL
,makeAny(sValue
== s_sTRUE
? sal_True
: sal_False
));
130 bFoundSuppressVersionColumns
= true;
134 DBG_UNHANDLED_EXCEPTION();
137 case XML_TOK_JAVA_DRIVER_CLASS
:
138 aProperty
.Name
= INFO_JDBCDRIVERCLASS
;
140 case XML_TOK_EXTENSION
:
141 aProperty
.Name
= INFO_TEXTFILEEXTENSION
;
143 case XML_TOK_IS_FIRST_ROW_HEADER_LINE
:
144 aProperty
.Name
= INFO_TEXTFILEHEADER
;
145 aProperty
.Value
<<= (sValue
== s_sTRUE
? sal_True
: sal_False
);
147 case XML_TOK_SHOW_DELETED
:
148 aProperty
.Name
= INFO_SHOWDELETEDROWS
;
149 aProperty
.Value
<<= (sValue
== s_sTRUE
? sal_True
: sal_False
);
151 case XML_TOK_IS_TABLE_NAME_LENGTH_LIMITED
:
152 aProperty
.Name
= INFO_ALLOWLONGTABLENAMES
;
153 aProperty
.Value
<<= (sValue
== s_sTRUE
? sal_True
: sal_False
);
154 bFoundTableNameLengthLimited
= true;
156 case XML_TOK_SYSTEM_DRIVER_SETTINGS
:
157 aProperty
.Name
= INFO_ADDITIONALOPTIONS
;
159 case XML_TOK_ENABLE_SQL92_CHECK
:
160 aProperty
.Name
= PROPERTY_ENABLESQL92CHECK
;
161 aProperty
.Value
<<= (sValue
== s_sTRUE
? sal_True
: sal_False
);
163 case XML_TOK_APPEND_TABLE_ALIAS_NAME
:
164 aProperty
.Name
= INFO_APPEND_TABLE_ALIAS
;
165 aProperty
.Value
<<= (sValue
== s_sTRUE
? sal_True
: sal_False
);
166 bFoundAppendTableAliasName
= true;
168 case XML_TOK_PARAMETER_NAME_SUBSTITUTION
:
169 aProperty
.Name
= INFO_PARAMETERNAMESUBST
;
170 aProperty
.Value
<<= (sValue
== s_sTRUE
? sal_True
: sal_False
);
171 bFoundParamNameSubstitution
= true;
173 case XML_TOK_IGNORE_DRIVER_PRIVILEGES
:
174 aProperty
.Name
= INFO_IGNOREDRIVER_PRIV
;
175 aProperty
.Value
<<= (sValue
== s_sTRUE
? sal_True
: sal_False
);
177 case XML_TOK_BOOLEAN_COMPARISON_MODE
:
178 aProperty
.Name
= PROPERTY_BOOLEANCOMPARISONMODE
;
179 if ( sValue
.equalsAscii("equal-integer") )
180 aProperty
.Value
<<= sal_Int32(0);
181 else if ( sValue
.equalsAscii("is-boolean") )
182 aProperty
.Value
<<= sal_Int32(1);
183 else if ( sValue
.equalsAscii("equal-boolean") )
184 aProperty
.Value
<<= sal_Int32(2);
185 else if ( sValue
.equalsAscii("equal-use-only-zero") )
186 aProperty
.Value
<<= sal_Int32(3);
188 case XML_TOK_USE_CATALOG
:
189 aProperty
.Name
= INFO_USECATALOG
;
190 aProperty
.Value
<<= (sValue
== s_sTRUE
? sal_True
: sal_False
);
192 case XML_TOK_BASE_DN
:
193 aProperty
.Name
= INFO_CONN_LDAP_BASEDN
;
195 case XML_TOK_MAX_ROW_COUNT
:
196 aProperty
.Name
= INFO_CONN_LDAP_ROWCOUNT
;
197 aProperty
.Value
<<= sValue
.toInt32();
200 if ( aProperty
.Name
.getLength() )
202 if ( !aProperty
.Value
.hasValue() )
203 aProperty
.Value
<<= sValue
;
204 rImport
.addInfo(aProperty
);
207 if ( rImport
.isNewFormat() )
209 if ( !bFoundTableNameLengthLimited
&& ( _eUsedFor
== eAppSettings
) )
211 aProperty
.Name
= INFO_ALLOWLONGTABLENAMES
;
212 aProperty
.Value
<<= sal_True
;
213 rImport
.addInfo(aProperty
);
215 if ( !bFoundParamNameSubstitution
&& ( _eUsedFor
== eDriverSettings
) )
217 aProperty
.Name
= INFO_PARAMETERNAMESUBST
;
218 aProperty
.Value
<<= sal_True
;
219 rImport
.addInfo(aProperty
);
221 if ( !bFoundAppendTableAliasName
&& ( _eUsedFor
== eAppSettings
) )
223 aProperty
.Name
= INFO_APPEND_TABLE_ALIAS
;
224 aProperty
.Value
<<= sal_True
;
225 rImport
.addInfo(aProperty
);
227 if ( !bFoundSuppressVersionColumns
&& ( _eUsedFor
== eAppSettings
) )
231 xDataSource
->setPropertyValue(PROPERTY_SUPPRESSVERSIONCL
,makeAny(sal_True
));
235 DBG_UNHANDLED_EXCEPTION();
240 // -----------------------------------------------------------------------------
242 OXMLDataSource::~OXMLDataSource()
245 DBG_DTOR(OXMLDataSource
,NULL
);
247 // -----------------------------------------------------------------------------
249 SvXMLImportContext
* OXMLDataSource::CreateChildContext(
251 const ::rtl::OUString
& rLocalName
,
252 const Reference
< XAttributeList
> & xAttrList
)
254 SvXMLImportContext
*pContext
= 0;
255 const SvXMLTokenMap
& rTokenMap
= GetOwnImport().GetDataSourceElemTokenMap();
256 const sal_uInt16 nToken
= rTokenMap
.Get( nPrefix
, rLocalName
);
261 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP
);
262 pContext
= new OXMLLogin( GetOwnImport(), nPrefix
, rLocalName
,xAttrList
);
265 case XML_TOK_TABLE_FILTER
:
266 case XML_TOK_TABLE_TYPE_FILTER
:
267 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP
);
268 pContext
= new OXMLTableFilterList( GetImport(), nPrefix
, rLocalName
);
270 case XML_TOK_AUTO_INCREMENT
:
271 case XML_TOK_DELIMITER
:
272 case XML_TOK_FONT_CHARSET
:
273 case XML_TOK_CHARACTER_SET
:
274 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP
);
275 pContext
= new OXMLDataSourceInfo( GetOwnImport(), nPrefix
, rLocalName
,xAttrList
,nToken
);
277 case XML_TOK_DATA_SOURCE_SETTINGS
:
278 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP
);
279 pContext
= new OXMLDataSourceSettings( GetOwnImport(), nPrefix
, rLocalName
);
281 case XML_TOK_CONNECTION_DATA
:
282 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP
);
283 pContext
= new OXMLConnectionData( GetOwnImport(), nPrefix
, rLocalName
);
285 case XML_TOK_DRIVER_SETTINGS
:
286 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP
);
287 pContext
= new OXMLDataSource( GetOwnImport(), nPrefix
, rLocalName
, xAttrList
, OXMLDataSource::eDriverSettings
);
289 case XML_TOK_JAVA_CLASSPATH
:
290 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP
);
291 pContext
= new OXMLJavaClassPath( GetOwnImport(), nPrefix
, rLocalName
,xAttrList
);
293 case XML_TOK_APPLICATION_CONNECTION_SETTINGS
:
294 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP
);
295 pContext
= new OXMLDataSource( GetOwnImport(), nPrefix
, rLocalName
, xAttrList
, OXMLDataSource::eAppSettings
);
300 pContext
= new SvXMLImportContext( GetImport(), nPrefix
, rLocalName
);
304 // -----------------------------------------------------------------------------
305 ODBFilter
& OXMLDataSource::GetOwnImport()
307 return static_cast<ODBFilter
&>(GetImport());
309 // -----------------------------------------------------------------------------
311 //----------------------------------------------------------------------------
312 } // namespace dbaxml
313 // -----------------------------------------------------------------------------