tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / dbaccess / source / filter / xml / xmlTable.cxx
blobdd7df81c80723c4a408db0b71ab15e8b699d1cd3
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 <utility>
23 #include <xmloff/xmltoken.hxx>
24 #include <xmloff/ProgressBarHelper.hxx>
25 #include "xmlEnums.hxx"
26 #include "xmlStyleImport.hxx"
27 #include "xmlHierarchyCollection.hxx"
28 #include <strings.hxx>
29 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
30 #include <com/sun/star/container/XNameContainer.hpp>
31 #include <com/sun/star/uno/XComponentContext.hpp>
32 #include <comphelper/propertysequence.hxx>
33 #include <comphelper/diagnose_ex.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 ,const uno::Reference< XFastAttributeList > & _xAttrList
44 ,uno::Reference< css::container::XNameAccess > _xParentContainer
45 ,const OUString& _sServiceName
47 :SvXMLImportContext( _rImport )
48 ,m_xParentContainer(std::move(_xParentContainer))
49 ,m_bApplyFilter(false)
50 ,m_bApplyOrder(false)
52 for (auto &aIter : sax_fastparser::castToFastAttributeList( _xAttrList ))
54 OUString sValue = aIter.toString();
56 switch( aIter.getToken() & TOKEN_MASK )
58 case XML_NAME:
59 m_sName = sValue;
60 break;
61 case XML_CATALOG_NAME:
62 m_sCatalog = sValue;
63 break;
64 case XML_SCHEMA_NAME:
65 m_sSchema = sValue;
66 break;
67 case XML_STYLE_NAME:
68 m_sStyleName = sValue;
69 break;
70 case XML_APPLY_FILTER:
71 m_bApplyFilter = sValue == "true";
72 break;
73 case XML_APPLY_ORDER:
74 m_bApplyOrder = sValue == "true";
75 break;
76 default:
77 XMLOFF_WARN_UNKNOWN("dbaccess", aIter);
80 uno::Sequence<uno::Any> aArguments(comphelper::InitAnyPropertySequence(
82 {"Name", uno::Any(m_sName)}, // set as folder
83 {"Parent", uno::Any(m_xParentContainer)}
84 }));
85 m_xTable.set(
86 GetOwnImport().GetComponentContext()->getServiceManager()->createInstanceWithArgumentsAndContext(_sServiceName,aArguments, GetOwnImport().GetComponentContext()),
87 UNO_QUERY);
90 OXMLTable::~OXMLTable()
95 css::uno::Reference< css::xml::sax::XFastContextHandler > OXMLTable::createFastChildContext(
96 sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
98 SvXMLImportContext *pContext = nullptr;
100 switch( nElement & TOKEN_MASK )
102 case XML_FILTER_STATEMENT:
104 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
105 OUString s1,s2,s3;
106 fillAttributes(xAttrList,m_sFilterStatement,s1,s2,s3);
108 break;
109 case XML_ORDER_STATEMENT:
111 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
112 OUString s1,s2,s3;
113 fillAttributes(xAttrList,m_sOrderStatement,s1,s2,s3);
115 break;
117 case XML_COLUMNS:
119 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
120 uno::Reference< XColumnsSupplier > xColumnsSup(m_xTable,UNO_QUERY);
121 uno::Reference< XNameAccess > xColumns;
122 if ( xColumnsSup.is() )
124 xColumns = xColumnsSup->getColumns();
126 pContext = new OXMLHierarchyCollection( GetOwnImport(), xColumns,m_xTable);
128 break;
131 return pContext;
134 ODBFilter& OXMLTable::GetOwnImport()
136 return static_cast<ODBFilter&>(GetImport());
139 void OXMLTable::setProperties(uno::Reference< XPropertySet > & _xProp )
143 if ( _xProp.is() )
145 _xProp->setPropertyValue(PROPERTY_APPLYFILTER,Any(m_bApplyFilter));
146 _xProp->setPropertyValue(PROPERTY_FILTER,Any(m_sFilterStatement));
148 if ( _xProp->getPropertySetInfo()->hasPropertyByName(PROPERTY_APPLYORDER) )
149 _xProp->setPropertyValue(PROPERTY_APPLYORDER,Any(m_bApplyOrder));
150 _xProp->setPropertyValue(PROPERTY_ORDER,Any(m_sOrderStatement));
153 catch(Exception&)
155 TOOLS_WARN_EXCEPTION( "dbaccess", "OXMLTable::EndElement -> exception caught");
159 void OXMLTable::endFastElement(sal_Int32 )
161 uno::Reference<XNameContainer> xNameContainer(m_xParentContainer,UNO_QUERY);
162 if ( !xNameContainer.is() )
163 return;
167 if ( m_xTable.is() )
169 setProperties(m_xTable);
171 if ( !m_sStyleName.isEmpty() )
173 const SvXMLStylesContext* pAutoStyles = GetOwnImport().GetAutoStyles();
174 if ( pAutoStyles )
176 OTableStyleContext* pAutoStyle = const_cast<OTableStyleContext*>(dynamic_cast< const OTableStyleContext* >(pAutoStyles->FindStyleChildContext(XmlStyleFamily::TABLE_TABLE,m_sStyleName)));
177 if ( pAutoStyle )
179 pAutoStyle->FillPropertySet(m_xTable);
184 xNameContainer->insertByName(m_sName,Any(m_xTable));
187 catch(Exception&)
189 TOOLS_WARN_EXCEPTION( "dbaccess", "OXMLQuery::EndElement");
194 void OXMLTable::fillAttributes(const uno::Reference< XFastAttributeList > & _xAttrList
195 ,OUString& _rsCommand
196 ,OUString& _rsTableName
197 ,OUString& _rsTableSchema
198 ,OUString& _rsTableCatalog
201 for (auto &aIter : sax_fastparser::castToFastAttributeList( _xAttrList ))
203 OUString sValue = aIter.toString();
205 switch( aIter.getToken() & TOKEN_MASK )
207 case XML_COMMAND:
208 _rsCommand = sValue;
209 break;
210 case XML_CATALOG_NAME:
211 _rsTableCatalog = sValue;
212 break;
213 case XML_SCHEMA_NAME:
214 _rsTableSchema = sValue;
215 break;
216 case XML_QUERY_NAME:
217 _rsTableName = sValue;
218 break;
219 default:
220 XMLOFF_WARN_UNKNOWN("dbaccess", aIter);
225 } // namespace dbaxml
227 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */