1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_dbaccess.hxx"
26 #ifndef DBA_XMLDATASOURCEINFO_HXX
27 #include "xmlDataSourceInfo.hxx"
28 #endif
29 #ifndef DBA_XMLDATASOURCE_HXX
30 #include "xmlDataSource.hxx"
31 #endif
32 #ifndef DBA_XMLFILTER_HXX
33 #include "xmlfilter.hxx"
34 #endif
35 #ifndef _XMLOFF_XMLTOKEN_HXX
36 #include <xmloff/xmltoken.hxx>
37 #endif
38 #ifndef _XMLOFF_XMLNMSPE_HXX
39 #include <xmloff/xmlnmspe.hxx>
40 #endif
41 #ifndef _XMLOFF_NMSPMAP_HXX
42 #include <xmloff/nmspmap.hxx>
43 #endif
44 #ifndef DBA_XMLENUMS_HXX
45 #include "xmlEnums.hxx"
46 #endif
47 #ifndef DBACCESS_SHARED_XMLSTRINGS_HRC
48 #include "xmlstrings.hrc"
49 #endif
50 #ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP_
51 #include <com/sun/star/beans/PropertyValue.hpp>
52 #endif
53 #ifndef _TOOLS_DEBUG_HXX
54 #include <tools/debug.hxx>
55 #endif
56 #include <vector>
57 
58 namespace dbaxml
59 {
60 	using namespace ::com::sun::star::uno;
61 	using namespace ::com::sun::star::xml::sax;
DBG_NAME(OXMLDataSourceInfo)62 DBG_NAME(OXMLDataSourceInfo)
63 
64 OXMLDataSourceInfo::OXMLDataSourceInfo( ODBFilter& rImport
65 				,sal_uInt16 nPrfx
66 				,const ::rtl::OUString& _sLocalName
67 				,const Reference< XAttributeList > & _xAttrList
68                 ,const sal_uInt16 _nToken) :
69 	SvXMLImportContext( rImport, nPrfx, _sLocalName )
70 {
71     DBG_CTOR(OXMLDataSourceInfo,NULL);
72 
73 	OSL_ENSURE(_xAttrList.is(),"Attribute list is NULL!");
74 	const SvXMLNamespaceMap& rMap = rImport.GetNamespaceMap();
75 	const SvXMLTokenMap& rTokenMap = rImport.GetDataSourceInfoElemTokenMap();
76 
77 	PropertyValue aProperty;
78 	sal_Int16 nLength = (_xAttrList.is()) ? _xAttrList->getLength() : 0;
79 	bool bAutoEnabled = false;
80     bool bFoundField = false,bFoundThousand = false, bFoundCharset = false;
81     ::std::vector< sal_uInt16 > aTokens;
82 	for(sal_Int16 i = 0; i < nLength; ++i)
83 	{
84 		::rtl::OUString sLocalName;
85 		rtl::OUString sAttrName = _xAttrList->getNameByIndex( i );
86 		sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName );
87 		rtl::OUString sValue = _xAttrList->getValueByIndex( i );
88 
89 		aProperty.Name = ::rtl::OUString();
90 
91         sal_uInt16 nToken = rTokenMap.Get( nPrefix, sLocalName );
92         aTokens.push_back(nToken);
93 		switch( nToken )
94 		{
95 			case XML_TOK_ADDITIONAL_COLUMN_STATEMENT:
96 				aProperty.Name = PROPERTY_AUTOINCREMENTCREATION;
97 				bAutoEnabled = true;
98 				break;
99 			case XML_TOK_ROW_RETRIEVING_STATEMENT:
100 				aProperty.Name = INFO_AUTORETRIEVEVALUE;
101 				bAutoEnabled = true;
102 				break;
103 			case XML_TOK_STRING:
104 				aProperty.Name = INFO_TEXTDELIMITER;
105 				break;
106 			case XML_TOK_FIELD:
107 				aProperty.Name = INFO_FIELDDELIMITER;
108                 bFoundField = true;
109 				break;
110 			case XML_TOK_DECIMAL:
111 				aProperty.Name = INFO_DECIMALDELIMITER;
112 				break;
113 			case XML_TOK_THOUSAND:
114 				aProperty.Name = INFO_THOUSANDSDELIMITER;
115                 bFoundThousand = true;
116 				break;
117 			case XML_TOK_ENCODING:
118 				aProperty.Name = INFO_CHARSET;
119                 bFoundCharset = true;
120 				break;
121 		}
122 		if ( aProperty.Name.getLength() )
123 		{
124 			aProperty.Value <<= sValue;
125 			rImport.addInfo(aProperty);
126 		}
127 	}
128 	if ( bAutoEnabled )
129 	{
130 		aProperty.Name = INFO_AUTORETRIEVEENABLED;
131 		aProperty.Value <<= sal_True;
132 		rImport.addInfo(aProperty);
133 	}
134     if ( rImport.isNewFormat() )
135     {
136         if ( XML_TOK_DELIMITER == _nToken )
137         {
138             if ( !bFoundField )
139             {
140                 aProperty.Name = INFO_FIELDDELIMITER;
141                 aProperty.Value <<= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(";"));
142 		        rImport.addInfo(aProperty);
143             }
144             if ( !bFoundThousand )
145             {
146                 aProperty.Name = INFO_THOUSANDSDELIMITER;
147                 aProperty.Value <<= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(","));
148 		        rImport.addInfo(aProperty);
149             } // if ( !bFoundThousand )
150         }
151         if ( XML_TOK_FONT_CHARSET == _nToken && !bFoundCharset )
152         {
153             aProperty.Name = INFO_CHARSET;
154             aProperty.Value <<= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("utf8"));
155 		    rImport.addInfo(aProperty);
156         }
157     }
158 }
159 // -----------------------------------------------------------------------------
160 
~OXMLDataSourceInfo()161 OXMLDataSourceInfo::~OXMLDataSourceInfo()
162 {
163 
164     DBG_DTOR(OXMLDataSourceInfo,NULL);
165 }
166 // -----------------------------------------------------------------------------
167 //----------------------------------------------------------------------------
168 } // namespace dbaxml
169 // -----------------------------------------------------------------------------
170