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