1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
34 using namespace ::com::sun::star::uno
;
35 using namespace ::com::sun::star::xml::sax
;
37 OXMLDataSourceInfo::OXMLDataSourceInfo( ODBFilter
& rImport
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
)
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
);
67 case XML_TOK_ADDITIONAL_COLUMN_STATEMENT
:
68 aProperty
.Name
= PROPERTY_AUTOINCREMENTCREATION
;
71 case XML_TOK_ROW_RETRIEVING_STATEMENT
:
72 aProperty
.Name
= INFO_AUTORETRIEVEVALUE
;
76 aProperty
.Name
= INFO_TEXTDELIMITER
;
79 aProperty
.Name
= INFO_FIELDDELIMITER
;
83 aProperty
.Name
= INFO_DECIMALDELIMITER
;
85 case XML_TOK_THOUSAND
:
86 aProperty
.Name
= INFO_THOUSANDSDELIMITER
;
87 bFoundThousand
= true;
89 case XML_TOK_ENCODING
:
90 aProperty
.Name
= INFO_CHARSET
;
94 if ( !aProperty
.Name
.isEmpty() )
96 aProperty
.Value
<<= sValue
;
97 rImport
.addInfo(aProperty
);
102 aProperty
.Name
= INFO_AUTORETRIEVEENABLED
;
103 aProperty
.Value
<<= sal_True
;
104 rImport
.addInfo(aProperty
);
106 if ( rImport
.isNewFormat() )
108 if ( XML_TOK_DELIMITER
== _nToken
)
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: */