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"
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();
199 case XML_TOK_JAVA_CLASSPATH
:
200 aProperty
.Name
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JavaDriverClassPath"));
203 if ( aProperty
.Name
.getLength() )
205 if ( !aProperty
.Value
.hasValue() )
206 aProperty
.Value
<<= sValue
;
207 rImport
.addInfo(aProperty
);
210 if ( rImport
.isNewFormat() )
212 if ( !bFoundTableNameLengthLimited
&& ( _eUsedFor
== eAppSettings
) )
214 aProperty
.Name
= INFO_ALLOWLONGTABLENAMES
;
215 aProperty
.Value
<<= sal_True
;
216 rImport
.addInfo(aProperty
);
218 if ( !bFoundParamNameSubstitution
&& ( _eUsedFor
== eDriverSettings
) )
220 aProperty
.Name
= INFO_PARAMETERNAMESUBST
;
221 aProperty
.Value
<<= sal_True
;
222 rImport
.addInfo(aProperty
);
224 if ( !bFoundAppendTableAliasName
&& ( _eUsedFor
== eAppSettings
) )
226 aProperty
.Name
= INFO_APPEND_TABLE_ALIAS
;
227 aProperty
.Value
<<= sal_True
;
228 rImport
.addInfo(aProperty
);
230 if ( !bFoundSuppressVersionColumns
&& ( _eUsedFor
== eAppSettings
) )
234 xDataSource
->setPropertyValue(PROPERTY_SUPPRESSVERSIONCL
,makeAny(sal_True
));
238 DBG_UNHANDLED_EXCEPTION();
243 // -----------------------------------------------------------------------------
245 OXMLDataSource::~OXMLDataSource()
248 DBG_DTOR(OXMLDataSource
,NULL
);
250 // -----------------------------------------------------------------------------
252 SvXMLImportContext
* OXMLDataSource::CreateChildContext(
254 const ::rtl::OUString
& rLocalName
,
255 const Reference
< XAttributeList
> & xAttrList
)
257 SvXMLImportContext
*pContext
= 0;
258 const SvXMLTokenMap
& rTokenMap
= GetOwnImport().GetDataSourceElemTokenMap();
259 const sal_uInt16 nToken
= rTokenMap
.Get( nPrefix
, rLocalName
);
264 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP
);
265 pContext
= new OXMLLogin( GetOwnImport(), nPrefix
, rLocalName
,xAttrList
);
268 case XML_TOK_TABLE_FILTER
:
269 case XML_TOK_TABLE_TYPE_FILTER
:
270 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP
);
271 pContext
= new OXMLTableFilterList( GetImport(), nPrefix
, rLocalName
);
273 case XML_TOK_AUTO_INCREMENT
:
274 case XML_TOK_DELIMITER
:
275 case XML_TOK_FONT_CHARSET
:
276 case XML_TOK_CHARACTER_SET
:
277 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP
);
278 pContext
= new OXMLDataSourceInfo( GetOwnImport(), nPrefix
, rLocalName
,xAttrList
,nToken
);
280 case XML_TOK_DATA_SOURCE_SETTINGS
:
281 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP
);
282 pContext
= new OXMLDataSourceSettings( GetOwnImport(), nPrefix
, rLocalName
);
284 case XML_TOK_CONNECTION_DATA
:
285 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP
);
286 pContext
= new OXMLConnectionData( GetOwnImport(), nPrefix
, rLocalName
);
288 case XML_TOK_DRIVER_SETTINGS
:
289 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP
);
290 pContext
= new OXMLDataSource( GetOwnImport(), nPrefix
, rLocalName
, xAttrList
, OXMLDataSource::eDriverSettings
);
292 case XML_TOK_APPLICATION_CONNECTION_SETTINGS
:
293 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP
);
294 pContext
= new OXMLDataSource( GetOwnImport(), nPrefix
, rLocalName
, xAttrList
, OXMLDataSource::eAppSettings
);
299 pContext
= new SvXMLImportContext( GetImport(), nPrefix
, rLocalName
);
303 // -----------------------------------------------------------------------------
304 ODBFilter
& OXMLDataSource::GetOwnImport()
306 return static_cast<ODBFilter
&>(GetImport());
308 // -----------------------------------------------------------------------------
310 //----------------------------------------------------------------------------
311 } // namespace dbaxml
312 // -----------------------------------------------------------------------------