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 "xmlHierarchyCollection.hxx"
21 #include "xmlComponent.hxx"
22 #include "xmlColumn.hxx"
23 #include "xmlfilter.hxx"
25 #include <xmloff/xmltoken.hxx>
26 #include <xmloff/ProgressBarHelper.hxx>
27 #include "xmlEnums.hxx"
28 #include <com/sun/star/container/XNameContainer.hpp>
29 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
30 #include <comphelper/propertysequence.hxx>
31 #include <comphelper/diagnose_ex.hxx>
35 using namespace ::com::sun::star::uno
;
36 using namespace ::com::sun::star::beans
;
37 using namespace ::com::sun::star::container
;
38 using namespace ::com::sun::star::xml::sax
;
40 OXMLHierarchyCollection::OXMLHierarchyCollection( ODBFilter
& rImport
41 ,const Reference
< XFastAttributeList
> & _xAttrList
42 ,const Reference
< XNameAccess
>& _xParentContainer
43 ,const OUString
& _sCollectionServiceName
44 ,OUString _sComponentServiceName
) :
45 SvXMLImportContext( rImport
)
46 ,m_sCollectionServiceName(_sCollectionServiceName
)
47 ,m_sComponentServiceName(std::move(_sComponentServiceName
))
50 for (auto &aIter
: sax_fastparser::castToFastAttributeList( _xAttrList
))
52 switch( aIter
.getToken() & TOKEN_MASK
)
55 sName
= aIter
.toString();
58 XMLOFF_WARN_UNKNOWN("dbaccess", aIter
);
61 if ( sName
.isEmpty() || !_xParentContainer
.is() )
66 Reference
<XMultiServiceFactory
> xORB(_xParentContainer
,UNO_QUERY
);
69 Sequence
<Any
> aArguments(comphelper::InitAnyPropertySequence(
71 {"Name", Any(sName
)}, // set as folder
72 {"Parent", Any(_xParentContainer
)},
74 m_xContainer
.set(xORB
->createInstanceWithArguments(_sCollectionServiceName
,aArguments
),UNO_QUERY
);
75 Reference
<XNameContainer
> xNameContainer(_xParentContainer
,UNO_QUERY
);
76 if ( xNameContainer
.is() && !xNameContainer
->hasByName(sName
) )
77 xNameContainer
->insertByName(sName
,Any(m_xContainer
));
82 TOOLS_WARN_EXCEPTION( "dbaccess", "OXMLHierarchyCollection::OXMLHierarchyCollection");
86 OXMLHierarchyCollection::OXMLHierarchyCollection( ODBFilter
& rImport
87 ,const Reference
< XNameAccess
>& _xContainer
88 ,const Reference
< XPropertySet
>& _xTable
90 SvXMLImportContext( rImport
)
91 ,m_xContainer(_xContainer
)
96 OXMLHierarchyCollection::~OXMLHierarchyCollection()
101 css::uno::Reference
< css::xml::sax::XFastContextHandler
> OXMLHierarchyCollection::createFastChildContext(
102 sal_Int32 nElement
, const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
)
104 SvXMLImportContext
*pContext
= nullptr;
106 switch( nElement
& TOKEN_MASK
)
109 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP
);
110 pContext
= new OXMLComponent( GetOwnImport(), xAttrList
,m_xContainer
,m_sComponentServiceName
);
113 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP
);
114 pContext
= new OXMLColumn( GetOwnImport(), xAttrList
,m_xContainer
,m_xTable
);
116 case XML_COMPONENT_COLLECTION
:
117 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP
);
118 pContext
= new OXMLHierarchyCollection( GetOwnImport(), xAttrList
,m_xContainer
,m_sCollectionServiceName
,m_sComponentServiceName
);
125 ODBFilter
& OXMLHierarchyCollection::GetOwnImport()
127 return static_cast<ODBFilter
&>(GetImport());
130 } // namespace dbaxml
132 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */