nss: upgrade to release 3.73
[LibreOffice.git] / dbaccess / source / filter / xml / xmlHierarchyCollection.cxx
blob45f0c6ad2d8c6bc337d8d3811285ccd9cb43cee2
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 "xmlHierarchyCollection.hxx"
21 #include "xmlComponent.hxx"
22 #include "xmlColumn.hxx"
23 #include "xmlfilter.hxx"
24 #include <xmloff/xmltoken.hxx>
25 #include <xmloff/ProgressBarHelper.hxx>
26 #include "xmlEnums.hxx"
27 #include <com/sun/star/container/XNameContainer.hpp>
28 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
29 #include <comphelper/propertysequence.hxx>
30 #include <osl/diagnose.h>
31 #include <sal/log.hxx>
33 namespace dbaxml
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 ,const OUString& _sComponentServiceName) :
45 SvXMLImportContext( rImport )
46 ,m_sCollectionServiceName(_sCollectionServiceName)
47 ,m_sComponentServiceName(_sComponentServiceName)
49 OUString sName;
50 for (auto &aIter : sax_fastparser::castToFastAttributeList( _xAttrList ))
52 OUString sValue = aIter.toString();
54 switch( aIter.getToken() & TOKEN_MASK )
56 case XML_NAME:
57 sName = sValue;
58 break;
59 default:
60 XMLOFF_WARN_UNKNOWN("dbaccess", aIter);
63 if ( sName.isEmpty() || !_xParentContainer.is() )
64 return;
66 try
68 Reference<XMultiServiceFactory> xORB(_xParentContainer,UNO_QUERY);
69 if ( xORB.is() )
71 Sequence<Any> aArguments(comphelper::InitAnyPropertySequence(
73 {"Name", Any(sName)}, // set as folder
74 {"Parent", Any(_xParentContainer)},
75 }));
76 m_xContainer.set(xORB->createInstanceWithArguments(_sCollectionServiceName,aArguments),UNO_QUERY);
77 Reference<XNameContainer> xNameContainer(_xParentContainer,UNO_QUERY);
78 if ( xNameContainer.is() && !xNameContainer->hasByName(sName) )
79 xNameContainer->insertByName(sName,makeAny(m_xContainer));
82 catch(Exception&)
84 OSL_FAIL("OXMLHierarchyCollection::OXMLHierarchyCollection -> exception caught");
88 OXMLHierarchyCollection::OXMLHierarchyCollection( ODBFilter& rImport
89 ,const Reference< XNameAccess >& _xContainer
90 ,const Reference< XPropertySet >& _xTable
91 ) :
92 SvXMLImportContext( rImport )
93 ,m_xContainer(_xContainer)
94 ,m_xTable(_xTable)
98 OXMLHierarchyCollection::~OXMLHierarchyCollection()
103 css::uno::Reference< css::xml::sax::XFastContextHandler > OXMLHierarchyCollection::createFastChildContext(
104 sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
106 SvXMLImportContext *pContext = nullptr;
108 switch( nElement & TOKEN_MASK )
110 case XML_COMPONENT:
111 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
112 pContext = new OXMLComponent( GetOwnImport(), xAttrList,m_xContainer,m_sComponentServiceName );
113 break;
114 case XML_COLUMN:
115 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
116 pContext = new OXMLColumn( GetOwnImport(), xAttrList,m_xContainer,m_xTable);
117 break;
118 case XML_COMPONENT_COLLECTION:
119 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
120 pContext = new OXMLHierarchyCollection( GetOwnImport(), xAttrList,m_xContainer,m_sCollectionServiceName,m_sComponentServiceName);
121 break;
124 return pContext;
127 ODBFilter& OXMLHierarchyCollection::GetOwnImport()
129 return static_cast<ODBFilter&>(GetImport());
132 } // namespace dbaxml
134 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */