Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / dbaccess / source / filter / xml / xmlDataSourceInfo.cxx
blob5cf4ee184ed5ab7ef53a6e79e76f5ae74c2ddb18
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 <stringconstants.hxx>
28 #include <strings.hxx>
29 #include <com/sun/star/beans/PropertyValue.hpp>
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 for(sal_Int16 i = 0; i < nLength; ++i)
55 OUString sLocalName;
56 OUString sAttrName = _xAttrList->getNameByIndex( i );
57 sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName );
58 OUString sValue = _xAttrList->getValueByIndex( i );
60 aProperty.Name.clear();
62 sal_uInt16 nToken = rTokenMap.Get( nPrefix, sLocalName );
63 switch( nToken )
65 case XML_TOK_ADDITIONAL_COLUMN_STATEMENT:
66 aProperty.Name = PROPERTY_AUTOINCREMENTCREATION;
67 bAutoEnabled = true;
68 break;
69 case XML_TOK_ROW_RETRIEVING_STATEMENT:
70 aProperty.Name = INFO_AUTORETRIEVEVALUE;
71 bAutoEnabled = true;
72 break;
73 case XML_TOK_STRING:
74 aProperty.Name = INFO_TEXTDELIMITER;
75 break;
76 case XML_TOK_FIELD:
77 aProperty.Name = INFO_FIELDDELIMITER;
78 bFoundField = true;
79 break;
80 case XML_TOK_DECIMAL:
81 aProperty.Name = INFO_DECIMALDELIMITER;
82 break;
83 case XML_TOK_THOUSAND:
84 aProperty.Name = INFO_THOUSANDSDELIMITER;
85 bFoundThousand = true;
86 break;
87 case XML_TOK_ENCODING:
88 aProperty.Name = INFO_CHARSET;
89 bFoundCharset = true;
90 break;
92 if ( !aProperty.Name.isEmpty() )
94 aProperty.Value <<= sValue;
95 rImport.addInfo(aProperty);
98 if ( bAutoEnabled )
100 aProperty.Name = INFO_AUTORETRIEVEENABLED;
101 aProperty.Value <<= true;
102 rImport.addInfo(aProperty);
104 if ( rImport.isNewFormat() )
106 if ( XML_TOK_DELIMITER == _nToken )
108 if ( !bFoundField )
110 aProperty.Name = INFO_FIELDDELIMITER;
111 aProperty.Value <<= OUString(";");
112 rImport.addInfo(aProperty);
114 if ( !bFoundThousand )
116 aProperty.Name = INFO_THOUSANDSDELIMITER;
117 aProperty.Value <<= OUString(",");
118 rImport.addInfo(aProperty);
121 if ( XML_TOK_FONT_CHARSET == _nToken && !bFoundCharset )
123 aProperty.Name = INFO_CHARSET;
124 aProperty.Value <<= OUString("utf8");
125 rImport.addInfo(aProperty);
130 OXMLDataSourceInfo::~OXMLDataSourceInfo()
135 } // namespace dbaxml
137 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */