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: xmlDataSourceInfo.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_XMLDATASOURCEINFO_HXX
34 #include "xmlDataSourceInfo.hxx"
36 #ifndef DBA_XMLDATASOURCE_HXX
37 #include "xmlDataSource.hxx"
39 #ifndef DBA_XMLFILTER_HXX
40 #include "xmlfilter.hxx"
42 #ifndef _XMLOFF_XMLTOKEN_HXX
43 #include <xmloff/xmltoken.hxx>
45 #ifndef _XMLOFF_XMLNMSPE_HXX
46 #include <xmloff/xmlnmspe.hxx>
48 #ifndef _XMLOFF_NMSPMAP_HXX
49 #include <xmloff/nmspmap.hxx>
51 #ifndef DBA_XMLENUMS_HXX
52 #include "xmlEnums.hxx"
54 #ifndef DBACCESS_SHARED_XMLSTRINGS_HRC
55 #include "xmlstrings.hrc"
57 #ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP_
58 #include <com/sun/star/beans/PropertyValue.hpp>
60 #ifndef _TOOLS_DEBUG_HXX
61 #include <tools/debug.hxx>
67 using namespace ::com::sun::star::uno
;
68 using namespace ::com::sun::star::xml::sax
;
69 DBG_NAME(OXMLDataSourceInfo
)
71 OXMLDataSourceInfo::OXMLDataSourceInfo( ODBFilter
& rImport
73 ,const ::rtl::OUString
& _sLocalName
74 ,const Reference
< XAttributeList
> & _xAttrList
75 ,const sal_uInt16 _nToken
) :
76 SvXMLImportContext( rImport
, nPrfx
, _sLocalName
)
78 DBG_CTOR(OXMLDataSourceInfo
,NULL
);
80 OSL_ENSURE(_xAttrList
.is(),"Attribute list is NULL!");
81 const SvXMLNamespaceMap
& rMap
= rImport
.GetNamespaceMap();
82 const SvXMLTokenMap
& rTokenMap
= rImport
.GetDataSourceInfoElemTokenMap();
84 PropertyValue aProperty
;
85 sal_Int16 nLength
= (_xAttrList
.is()) ? _xAttrList
->getLength() : 0;
86 bool bAutoEnabled
= false;
87 bool bFoundField
= false,bFoundThousand
= false, bFoundCharset
= false;
88 ::std::vector
< sal_uInt16
> aTokens
;
89 for(sal_Int16 i
= 0; i
< nLength
; ++i
)
91 ::rtl::OUString sLocalName
;
92 rtl::OUString sAttrName
= _xAttrList
->getNameByIndex( i
);
93 sal_uInt16 nPrefix
= rMap
.GetKeyByAttrName( sAttrName
,&sLocalName
);
94 rtl::OUString sValue
= _xAttrList
->getValueByIndex( i
);
96 aProperty
.Name
= ::rtl::OUString();
98 sal_uInt16 nToken
= rTokenMap
.Get( nPrefix
, sLocalName
);
99 aTokens
.push_back(nToken
);
102 case XML_TOK_ADDITIONAL_COLUMN_STATEMENT
:
103 aProperty
.Name
= PROPERTY_AUTOINCREMENTCREATION
;
106 case XML_TOK_ROW_RETRIEVING_STATEMENT
:
107 aProperty
.Name
= INFO_AUTORETRIEVEVALUE
;
111 aProperty
.Name
= INFO_TEXTDELIMITER
;
114 aProperty
.Name
= INFO_FIELDDELIMITER
;
117 case XML_TOK_DECIMAL
:
118 aProperty
.Name
= INFO_DECIMALDELIMITER
;
120 case XML_TOK_THOUSAND
:
121 aProperty
.Name
= INFO_THOUSANDSDELIMITER
;
122 bFoundThousand
= true;
124 case XML_TOK_ENCODING
:
125 aProperty
.Name
= INFO_CHARSET
;
126 bFoundCharset
= true;
129 if ( aProperty
.Name
.getLength() )
131 aProperty
.Value
<<= sValue
;
132 rImport
.addInfo(aProperty
);
137 aProperty
.Name
= INFO_AUTORETRIEVEENABLED
;
138 aProperty
.Value
<<= sal_True
;
139 rImport
.addInfo(aProperty
);
141 if ( rImport
.isNewFormat() )
143 if ( XML_TOK_DELIMITER
== _nToken
)
147 aProperty
.Name
= INFO_FIELDDELIMITER
;
148 aProperty
.Value
<<= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(";"));
149 rImport
.addInfo(aProperty
);
151 if ( !bFoundThousand
)
153 aProperty
.Name
= INFO_THOUSANDSDELIMITER
;
154 aProperty
.Value
<<= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(","));
155 rImport
.addInfo(aProperty
);
156 } // if ( !bFoundThousand )
158 if ( XML_TOK_FONT_CHARSET
== _nToken
&& !bFoundCharset
)
160 aProperty
.Name
= INFO_CHARSET
;
161 aProperty
.Value
<<= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("utf8"));
162 rImport
.addInfo(aProperty
);
166 // -----------------------------------------------------------------------------
168 OXMLDataSourceInfo::~OXMLDataSourceInfo()
171 DBG_DTOR(OXMLDataSourceInfo
,NULL
);
173 // -----------------------------------------------------------------------------
174 //----------------------------------------------------------------------------
175 } // namespace dbaxml
176 // -----------------------------------------------------------------------------