1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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"
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>
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)
52 for (auto &aIter
: sax_fastparser::castToFastAttributeList( _xAttrList
))
54 OUString sValue
= aIter
.toString();
56 switch( aIter
.getToken() & TOKEN_MASK
)
61 case XML_CATALOG_NAME
:
68 m_sStyleName
= sValue
;
70 case XML_APPLY_FILTER
:
71 m_bApplyFilter
= sValue
== "true";
74 m_bApplyOrder
= sValue
== "true";
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
)}
86 GetOwnImport().GetComponentContext()->getServiceManager()->createInstanceWithArgumentsAndContext(_sServiceName
,aArguments
, GetOwnImport().GetComponentContext()),
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
);
106 fillAttributes(xAttrList
,m_sFilterStatement
,s1
,s2
,s3
);
109 case XML_ORDER_STATEMENT
:
111 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP
);
113 fillAttributes(xAttrList
,m_sOrderStatement
,s1
,s2
,s3
);
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
);
134 ODBFilter
& OXMLTable::GetOwnImport()
136 return static_cast<ODBFilter
&>(GetImport());
139 void OXMLTable::setProperties(uno::Reference
< XPropertySet
> & _xProp
)
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
));
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() )
169 setProperties(m_xTable
);
171 if ( !m_sStyleName
.isEmpty() )
173 const SvXMLStylesContext
* pAutoStyles
= GetOwnImport().GetAutoStyles();
176 OTableStyleContext
* pAutoStyle
= const_cast<OTableStyleContext
*>(dynamic_cast< const OTableStyleContext
* >(pAutoStyles
->FindStyleChildContext(XmlStyleFamily::TABLE_TABLE
,m_sStyleName
)));
179 pAutoStyle
->FillPropertySet(m_xTable
);
184 xNameContainer
->insertByName(m_sName
,Any(m_xTable
));
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
)
210 case XML_CATALOG_NAME
:
211 _rsTableCatalog
= sValue
;
213 case XML_SCHEMA_NAME
:
214 _rsTableSchema
= sValue
;
217 _rsTableName
= sValue
;
220 XMLOFF_WARN_UNKNOWN("dbaccess", aIter
);
225 } // namespace dbaxml
227 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */