bump product version to 5.0.4.1
[LibreOffice.git] / dbaccess / source / filter / xml / xmlTable.cxx
blobc3478a36f8c1b38036202afdce3dba050fd28d33
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 "xmlTable.hxx"
21 #include "xmlfilter.hxx"
22 #include <xmloff/xmltoken.hxx>
23 #include <xmloff/xmlnmspe.hxx>
24 #include <xmloff/nmspmap.hxx>
25 #include "xmlEnums.hxx"
26 #include "xmlStyleImport.hxx"
27 #include "xmlHierarchyCollection.hxx"
28 #include "xmlstrings.hrc"
29 #include <ucbhelper/content.hxx>
30 #include <com/sun/star/ucb/XCommandEnvironment.hpp>
31 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
32 #include <comphelper/namecontainer.hxx>
33 #include <tools/debug.hxx>
35 namespace dbaxml
37 using namespace ::com::sun::star;
38 using namespace ::com::sun::star::uno;
39 using namespace ::com::sun::star::sdbcx;
40 using namespace ::com::sun::star::xml::sax;
42 OXMLTable::OXMLTable( ODBFilter& _rImport
43 ,sal_uInt16 nPrfx
44 ,const OUString& _sLocalName
45 ,const uno::Reference< XAttributeList > & _xAttrList
46 ,const uno::Reference< ::com::sun::star::container::XNameAccess >& _xParentContainer
47 ,const OUString& _sServiceName
49 :SvXMLImportContext( _rImport, nPrfx, _sLocalName )
50 ,m_xParentContainer(_xParentContainer)
51 ,m_sServiceName(_sServiceName)
52 ,m_bApplyFilter(false)
53 ,m_bApplyOrder(false)
56 OSL_ENSURE(_xAttrList.is(),"Attribute list is NULL!");
57 const SvXMLNamespaceMap& rMap = GetOwnImport().GetNamespaceMap();
58 const SvXMLTokenMap& rTokenMap = GetOwnImport().GetQueryElemTokenMap();
60 sal_Int16 nLength = (_xAttrList.is()) ? _xAttrList->getLength() : 0;
61 for(sal_Int16 i = 0; i < nLength; ++i)
63 OUString sLocalName;
64 OUString sAttrName = _xAttrList->getNameByIndex( i );
65 sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName );
66 OUString sValue = _xAttrList->getValueByIndex( i );
68 switch( rTokenMap.Get( nPrefix, sLocalName ) )
70 case XML_TOK_QUERY_NAME:
71 m_sName = sValue;
72 break;
73 case XML_TOK_CATALOG_NAME:
74 m_sCatalog = sValue;
75 break;
76 case XML_TOK_SCHEMA_NAME:
77 m_sSchema = sValue;
78 break;
79 case XML_TOK_STYLE_NAME:
80 m_sStyleName = sValue;
81 break;
82 case XML_TOK_APPLY_FILTER:
83 m_bApplyFilter = sValue == "true";
84 break;
85 case XML_TOK_APPLY_ORDER:
86 m_bApplyOrder = sValue == "true";
87 break;
90 Sequence< Any > aArguments(2);
91 PropertyValue aValue;
92 // set as folder
93 aValue.Name = "Name";
94 aValue.Value <<= m_sName;
95 aArguments[0] <<= aValue;
96 //parent
97 aValue.Name = "Parent";
98 aValue.Value <<= m_xParentContainer;
99 aArguments[1] <<= aValue;
100 m_xTable.set(
101 GetOwnImport().GetComponentContext()->getServiceManager()->createInstanceWithArgumentsAndContext(m_sServiceName,aArguments, GetOwnImport().GetComponentContext()),
102 UNO_QUERY);
105 OXMLTable::~OXMLTable()
110 SvXMLImportContext* OXMLTable::CreateChildContext(
111 sal_uInt16 nPrefix,
112 const OUString& rLocalName,
113 const uno::Reference< XAttributeList > & xAttrList )
115 SvXMLImportContext *pContext = 0;
116 const SvXMLTokenMap& rTokenMap = GetOwnImport().GetQueryElemTokenMap();
118 switch( rTokenMap.Get( nPrefix, rLocalName ) )
120 case XML_TOK_FILTER_STATEMENT:
122 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
123 OUString s1,s2,s3;
124 fillAttributes(nPrefix, rLocalName,xAttrList,m_sFilterStatement,s1,s2,s3);
126 break;
127 case XML_TOK_ORDER_STATEMENT:
129 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
130 OUString s1,s2,s3;
131 fillAttributes(nPrefix, rLocalName,xAttrList,m_sOrderStatement,s1,s2,s3);
133 break;
135 case XML_TOK_COLUMNS:
137 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
138 uno::Reference< XColumnsSupplier > xColumnsSup(m_xTable,UNO_QUERY);
139 uno::Reference< XNameAccess > xColumns;
140 if ( xColumnsSup.is() )
142 xColumns = xColumnsSup->getColumns();
144 pContext = new OXMLHierarchyCollection( GetOwnImport(), nPrefix, rLocalName ,xColumns,m_xTable);
146 break;
149 if( !pContext )
150 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
152 return pContext;
155 ODBFilter& OXMLTable::GetOwnImport()
157 return static_cast<ODBFilter&>(GetImport());
160 void OXMLTable::setProperties(uno::Reference< XPropertySet > & _xProp )
164 if ( _xProp.is() )
166 _xProp->setPropertyValue(PROPERTY_APPLYFILTER,makeAny(m_bApplyFilter));
167 _xProp->setPropertyValue(PROPERTY_FILTER,makeAny(m_sFilterStatement));
169 if ( _xProp->getPropertySetInfo()->hasPropertyByName(PROPERTY_APPLYORDER) )
170 _xProp->setPropertyValue(PROPERTY_APPLYORDER,makeAny(m_bApplyOrder));
171 _xProp->setPropertyValue(PROPERTY_ORDER,makeAny(m_sOrderStatement));
174 catch(Exception&)
176 OSL_FAIL("OXMLTable::EndElement -> exception catched");
180 void OXMLTable::EndElement()
182 uno::Reference<XNameContainer> xNameContainer(m_xParentContainer,UNO_QUERY);
183 if ( xNameContainer.is() )
187 if ( m_xTable.is() )
189 setProperties(m_xTable);
191 if ( !m_sStyleName.isEmpty() )
193 const SvXMLStylesContext* pAutoStyles = GetOwnImport().GetAutoStyles();
194 if ( pAutoStyles )
196 OTableStyleContext* pAutoStyle = const_cast<OTableStyleContext*>(PTR_CAST(OTableStyleContext,pAutoStyles->FindStyleChildContext(XML_STYLE_FAMILY_TABLE_TABLE,m_sStyleName)));
197 if ( pAutoStyle )
199 pAutoStyle->FillPropertySet(m_xTable);
204 xNameContainer->insertByName(m_sName,makeAny(m_xTable));
207 catch(Exception&)
209 OSL_FAIL("OXMLQuery::EndElement -> exception catched");
215 void OXMLTable::fillAttributes(sal_uInt16 /*nPrfx*/
216 ,const OUString& /*_sLocalName*/
217 ,const uno::Reference< XAttributeList > & _xAttrList
218 ,OUString& _rsCommand
219 ,OUString& _rsTableName
220 ,OUString& _rsTableSchema
221 ,OUString& _rsTableCatalog
224 OSL_ENSURE(_xAttrList.is(),"Attribute list is NULL!");
225 const SvXMLNamespaceMap& rMap = GetOwnImport().GetNamespaceMap();
226 const SvXMLTokenMap& rTokenMap = GetOwnImport().GetQueryElemTokenMap();
228 sal_Int16 nLength = (_xAttrList.is()) ? _xAttrList->getLength() : 0;
229 for(sal_Int16 i = 0; i < nLength; ++i)
231 OUString sLocalName;
232 OUString sAttrName = _xAttrList->getNameByIndex( i );
233 sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName );
234 OUString sValue = _xAttrList->getValueByIndex( i );
236 switch( rTokenMap.Get( nPrefix, sLocalName ) )
238 case XML_TOK_COMMAND:
239 _rsCommand = sValue;
240 break;
241 case XML_TOK_CATALOG_NAME:
242 _rsTableCatalog = sValue;
243 break;
244 case XML_TOK_SCHEMA_NAME:
245 _rsTableSchema = sValue;
246 break;
247 case XML_TOK_QUERY_NAME:
248 _rsTableName = sValue;
249 break;
254 } // namespace dbaxml
256 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */