bump product version to 5.0.4.1
[LibreOffice.git] / dbaccess / source / filter / xml / xmlDataSourceInfo.cxx
blobc32d74c9984efc1603681171bdff85dc42d5518e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "xmlDataSourceInfo.hxx"
21 #include "xmlDataSource.hxx"
22 #include "xmlfilter.hxx"
23 #include <xmloff/xmltoken.hxx>
24 #include <xmloff/xmlnmspe.hxx>
25 #include <xmloff/nmspmap.hxx>
26 #include "xmlEnums.hxx"
27 #include "xmlstrings.hrc"
28 #include <com/sun/star/beans/PropertyValue.hpp>
29 #include <tools/debug.hxx>
30 #include <vector>
32 namespace dbaxml
34 using namespace ::com::sun::star::uno;
35 using namespace ::com::sun::star::xml::sax;
37 OXMLDataSourceInfo::OXMLDataSourceInfo( ODBFilter& rImport
38 ,sal_uInt16 nPrfx
39 ,const OUString& _sLocalName
40 ,const Reference< XAttributeList > & _xAttrList
41 ,const sal_uInt16 _nToken) :
42 SvXMLImportContext( rImport, nPrfx, _sLocalName )
45 OSL_ENSURE(_xAttrList.is(),"Attribute list is NULL!");
46 const SvXMLNamespaceMap& rMap = rImport.GetNamespaceMap();
47 const SvXMLTokenMap& rTokenMap = rImport.GetDataSourceInfoElemTokenMap();
49 PropertyValue aProperty;
50 sal_Int16 nLength = (_xAttrList.is()) ? _xAttrList->getLength() : 0;
51 bool bAutoEnabled = false;
52 bool bFoundField = false,bFoundThousand = false, bFoundCharset = false;
53 ::std::vector< sal_uInt16 > aTokens;
54 for(sal_Int16 i = 0; i < nLength; ++i)
56 OUString sLocalName;
57 OUString sAttrName = _xAttrList->getNameByIndex( i );
58 sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName );
59 OUString sValue = _xAttrList->getValueByIndex( i );
61 aProperty.Name.clear();
63 sal_uInt16 nToken = rTokenMap.Get( nPrefix, sLocalName );
64 aTokens.push_back(nToken);
65 switch( nToken )
67 case XML_TOK_ADDITIONAL_COLUMN_STATEMENT:
68 aProperty.Name = PROPERTY_AUTOINCREMENTCREATION;
69 bAutoEnabled = true;
70 break;
71 case XML_TOK_ROW_RETRIEVING_STATEMENT:
72 aProperty.Name = INFO_AUTORETRIEVEVALUE;
73 bAutoEnabled = true;
74 break;
75 case XML_TOK_STRING:
76 aProperty.Name = INFO_TEXTDELIMITER;
77 break;
78 case XML_TOK_FIELD:
79 aProperty.Name = INFO_FIELDDELIMITER;
80 bFoundField = true;
81 break;
82 case XML_TOK_DECIMAL:
83 aProperty.Name = INFO_DECIMALDELIMITER;
84 break;
85 case XML_TOK_THOUSAND:
86 aProperty.Name = INFO_THOUSANDSDELIMITER;
87 bFoundThousand = true;
88 break;
89 case XML_TOK_ENCODING:
90 aProperty.Name = INFO_CHARSET;
91 bFoundCharset = true;
92 break;
94 if ( !aProperty.Name.isEmpty() )
96 aProperty.Value <<= sValue;
97 rImport.addInfo(aProperty);
100 if ( bAutoEnabled )
102 aProperty.Name = INFO_AUTORETRIEVEENABLED;
103 aProperty.Value <<= sal_True;
104 rImport.addInfo(aProperty);
106 if ( rImport.isNewFormat() )
108 if ( XML_TOK_DELIMITER == _nToken )
110 if ( !bFoundField )
112 aProperty.Name = INFO_FIELDDELIMITER;
113 aProperty.Value <<= OUString(";");
114 rImport.addInfo(aProperty);
116 if ( !bFoundThousand )
118 aProperty.Name = INFO_THOUSANDSDELIMITER;
119 aProperty.Value <<= OUString(",");
120 rImport.addInfo(aProperty);
123 if ( XML_TOK_FONT_CHARSET == _nToken && !bFoundCharset )
125 aProperty.Name = INFO_CHARSET;
126 aProperty.Value <<= OUString("utf8");
127 rImport.addInfo(aProperty);
132 OXMLDataSourceInfo::~OXMLDataSourceInfo()
137 } // namespace dbaxml
139 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */