Update ooo320-m1
[ooovba.git] / dbaccess / source / filter / xml / xmlDataSourceInfo.cxx
blobf4303bf7bd1f2e8430683ea8021c8ac58f5055b5
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xmlDataSourceInfo.cxx,v $
10 * $Revision: 1.11 $
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"
35 #endif
36 #ifndef DBA_XMLDATASOURCE_HXX
37 #include "xmlDataSource.hxx"
38 #endif
39 #ifndef DBA_XMLFILTER_HXX
40 #include "xmlfilter.hxx"
41 #endif
42 #ifndef _XMLOFF_XMLTOKEN_HXX
43 #include <xmloff/xmltoken.hxx>
44 #endif
45 #ifndef _XMLOFF_XMLNMSPE_HXX
46 #include <xmloff/xmlnmspe.hxx>
47 #endif
48 #ifndef _XMLOFF_NMSPMAP_HXX
49 #include <xmloff/nmspmap.hxx>
50 #endif
51 #ifndef DBA_XMLENUMS_HXX
52 #include "xmlEnums.hxx"
53 #endif
54 #ifndef DBACCESS_SHARED_XMLSTRINGS_HRC
55 #include "xmlstrings.hrc"
56 #endif
57 #ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP_
58 #include <com/sun/star/beans/PropertyValue.hpp>
59 #endif
60 #ifndef _TOOLS_DEBUG_HXX
61 #include <tools/debug.hxx>
62 #endif
63 #include <vector>
65 namespace dbaxml
67 using namespace ::com::sun::star::uno;
68 using namespace ::com::sun::star::xml::sax;
69 DBG_NAME(OXMLDataSourceInfo)
71 OXMLDataSourceInfo::OXMLDataSourceInfo( ODBFilter& rImport
72 ,sal_uInt16 nPrfx
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);
100 switch( nToken )
102 case XML_TOK_ADDITIONAL_COLUMN_STATEMENT:
103 aProperty.Name = PROPERTY_AUTOINCREMENTCREATION;
104 bAutoEnabled = true;
105 break;
106 case XML_TOK_ROW_RETRIEVING_STATEMENT:
107 aProperty.Name = INFO_AUTORETRIEVEVALUE;
108 bAutoEnabled = true;
109 break;
110 case XML_TOK_STRING:
111 aProperty.Name = INFO_TEXTDELIMITER;
112 break;
113 case XML_TOK_FIELD:
114 aProperty.Name = INFO_FIELDDELIMITER;
115 bFoundField = true;
116 break;
117 case XML_TOK_DECIMAL:
118 aProperty.Name = INFO_DECIMALDELIMITER;
119 break;
120 case XML_TOK_THOUSAND:
121 aProperty.Name = INFO_THOUSANDSDELIMITER;
122 bFoundThousand = true;
123 break;
124 case XML_TOK_ENCODING:
125 aProperty.Name = INFO_CHARSET;
126 bFoundCharset = true;
127 break;
129 if ( aProperty.Name.getLength() )
131 aProperty.Value <<= sValue;
132 rImport.addInfo(aProperty);
135 if ( bAutoEnabled )
137 aProperty.Name = INFO_AUTORETRIEVEENABLED;
138 aProperty.Value <<= sal_True;
139 rImport.addInfo(aProperty);
141 if ( rImport.isNewFormat() )
143 if ( XML_TOK_DELIMITER == _nToken )
145 if ( !bFoundField )
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 // -----------------------------------------------------------------------------