Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
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>
31 :
32 : namespace dbaxml
33 : {
34 : using namespace ::com::sun::star::uno;
35 : using namespace ::com::sun::star::xml::sax;
36 : DBG_NAME(OXMLDataSourceInfo)
37 :
38 0 : OXMLDataSourceInfo::OXMLDataSourceInfo( ODBFilter& rImport
39 : ,sal_uInt16 nPrfx
40 : ,const ::rtl::OUString& _sLocalName
41 : ,const Reference< XAttributeList > & _xAttrList
42 : ,const sal_uInt16 _nToken) :
43 0 : SvXMLImportContext( rImport, nPrfx, _sLocalName )
44 : {
45 : DBG_CTOR(OXMLDataSourceInfo,NULL);
46 :
47 : OSL_ENSURE(_xAttrList.is(),"Attribute list is NULL!");
48 0 : const SvXMLNamespaceMap& rMap = rImport.GetNamespaceMap();
49 0 : const SvXMLTokenMap& rTokenMap = rImport.GetDataSourceInfoElemTokenMap();
50 :
51 0 : PropertyValue aProperty;
52 0 : sal_Int16 nLength = (_xAttrList.is()) ? _xAttrList->getLength() : 0;
53 0 : bool bAutoEnabled = false;
54 0 : bool bFoundField = false,bFoundThousand = false, bFoundCharset = false;
55 0 : ::std::vector< sal_uInt16 > aTokens;
56 0 : for(sal_Int16 i = 0; i < nLength; ++i)
57 : {
58 0 : ::rtl::OUString sLocalName;
59 0 : rtl::OUString sAttrName = _xAttrList->getNameByIndex( i );
60 0 : sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName );
61 0 : rtl::OUString sValue = _xAttrList->getValueByIndex( i );
62 :
63 0 : aProperty.Name = ::rtl::OUString();
64 :
65 0 : sal_uInt16 nToken = rTokenMap.Get( nPrefix, sLocalName );
66 0 : aTokens.push_back(nToken);
67 0 : switch( nToken )
68 : {
69 : case XML_TOK_ADDITIONAL_COLUMN_STATEMENT:
70 0 : aProperty.Name = PROPERTY_AUTOINCREMENTCREATION;
71 0 : bAutoEnabled = true;
72 0 : break;
73 : case XML_TOK_ROW_RETRIEVING_STATEMENT:
74 0 : aProperty.Name = INFO_AUTORETRIEVEVALUE;
75 0 : bAutoEnabled = true;
76 0 : break;
77 : case XML_TOK_STRING:
78 0 : aProperty.Name = INFO_TEXTDELIMITER;
79 0 : break;
80 : case XML_TOK_FIELD:
81 0 : aProperty.Name = INFO_FIELDDELIMITER;
82 0 : bFoundField = true;
83 0 : break;
84 : case XML_TOK_DECIMAL:
85 0 : aProperty.Name = INFO_DECIMALDELIMITER;
86 0 : break;
87 : case XML_TOK_THOUSAND:
88 0 : aProperty.Name = INFO_THOUSANDSDELIMITER;
89 0 : bFoundThousand = true;
90 0 : break;
91 : case XML_TOK_ENCODING:
92 0 : aProperty.Name = INFO_CHARSET;
93 0 : bFoundCharset = true;
94 0 : break;
95 : }
96 0 : if ( !aProperty.Name.isEmpty() )
97 : {
98 0 : aProperty.Value <<= sValue;
99 0 : rImport.addInfo(aProperty);
100 : }
101 0 : }
102 0 : if ( bAutoEnabled )
103 : {
104 0 : aProperty.Name = INFO_AUTORETRIEVEENABLED;
105 0 : aProperty.Value <<= sal_True;
106 0 : rImport.addInfo(aProperty);
107 : }
108 0 : if ( rImport.isNewFormat() )
109 : {
110 0 : if ( XML_TOK_DELIMITER == _nToken )
111 : {
112 0 : if ( !bFoundField )
113 : {
114 0 : aProperty.Name = INFO_FIELDDELIMITER;
115 0 : aProperty.Value <<= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(";"));
116 0 : rImport.addInfo(aProperty);
117 : }
118 0 : if ( !bFoundThousand )
119 : {
120 0 : aProperty.Name = INFO_THOUSANDSDELIMITER;
121 0 : aProperty.Value <<= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(","));
122 0 : rImport.addInfo(aProperty);
123 : }
124 : }
125 0 : if ( XML_TOK_FONT_CHARSET == _nToken && !bFoundCharset )
126 : {
127 0 : aProperty.Name = INFO_CHARSET;
128 0 : aProperty.Value <<= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("utf8"));
129 0 : rImport.addInfo(aProperty);
130 : }
131 0 : }
132 0 : }
133 : // -----------------------------------------------------------------------------
134 :
135 0 : OXMLDataSourceInfo::~OXMLDataSourceInfo()
136 : {
137 :
138 : DBG_DTOR(OXMLDataSourceInfo,NULL);
139 0 : }
140 : // -----------------------------------------------------------------------------
141 : //----------------------------------------------------------------------------
142 : } // namespace dbaxml
143 : // -----------------------------------------------------------------------------
144 :
145 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|