LibreOffice Module dbaccess (master) 1
xmlHierarchyCollection.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
21#include "xmlComponent.hxx"
22#include "xmlColumn.hxx"
23#include "xmlfilter.hxx"
24#include <utility>
25#include <xmloff/xmltoken.hxx>
27#include "xmlEnums.hxx"
28#include <com/sun/star/container/XNameContainer.hpp>
29#include <com/sun/star/lang/XMultiServiceFactory.hpp>
32
33namespace dbaxml
34{
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;
39
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))
48{
49 OUString sName;
50 for (auto &aIter : sax_fastparser::castToFastAttributeList( _xAttrList ))
51 {
52 switch( aIter.getToken() & TOKEN_MASK )
53 {
54 case XML_NAME:
55 sName = aIter.toString();
56 break;
57 default:
58 XMLOFF_WARN_UNKNOWN("dbaccess", aIter);
59 }
60 }
61 if ( sName.isEmpty() || !_xParentContainer.is() )
62 return;
63
64 try
65 {
66 Reference<XMultiServiceFactory> xORB(_xParentContainer,UNO_QUERY);
67 if ( xORB.is() )
68 {
70 {
71 {"Name", Any(sName)}, // set as folder
72 {"Parent", Any(_xParentContainer)},
73 }));
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));
78 }
79 }
80 catch(Exception&)
81 {
82 TOOLS_WARN_EXCEPTION( "dbaccess", "OXMLHierarchyCollection::OXMLHierarchyCollection");
83 }
84}
85
86OXMLHierarchyCollection::OXMLHierarchyCollection( ODBFilter& rImport
87 ,const Reference< XNameAccess >& _xContainer
88 ,const Reference< XPropertySet >& _xTable
89 ) :
90 SvXMLImportContext( rImport )
91 ,m_xContainer(_xContainer)
92 ,m_xTable(_xTable)
93{
94}
95
96OXMLHierarchyCollection::~OXMLHierarchyCollection()
97{
98
99}
100
101css::uno::Reference< css::xml::sax::XFastContextHandler > OXMLHierarchyCollection::createFastChildContext(
102 sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
103{
104 SvXMLImportContext *pContext = nullptr;
105
106 switch( nElement & TOKEN_MASK )
107 {
108 case XML_COMPONENT:
109 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
110 pContext = new OXMLComponent( GetOwnImport(), xAttrList,m_xContainer,m_sComponentServiceName );
111 break;
112 case XML_COLUMN:
113 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
114 pContext = new OXMLColumn( GetOwnImport(), xAttrList,m_xContainer,m_xTable);
115 break;
117 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
118 pContext = new OXMLHierarchyCollection( GetOwnImport(), xAttrList,m_xContainer,m_sCollectionServiceName,m_sComponentServiceName);
119 break;
120 }
121
122 return pContext;
123}
124
125ODBFilter& OXMLHierarchyCollection::GetOwnImport()
126{
127 return static_cast<ODBFilter&>(GetImport());
128}
129
130} // namespace dbaxml
131
132/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OptionalString sName
OXMLHierarchyCollection(ODBFilter &rImport, const css::uno::Reference< css::xml::sax::XFastAttributeList > &_xAttrList, const css::uno::Reference< css::container::XNameAccess > &_xParentContainer, const OUString &_sCollectionServiceName, OUString _sComponentServiceName)
#define TOOLS_WARN_EXCEPTION(area, stream)
Sequence< PropertyValue > aArguments
Definition: intercept.cxx:88
css::uno::Sequence< css::uno::Any > InitAnyPropertySequence(::std::initializer_list< ::std::pair< OUString, css::uno::Any > > vInit)
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
XML_COLUMN
XML_COMPONENT_COLLECTION
XML_NAME
XML_COMPONENT
Reference< XNameAccess > m_xContainer
Definition: objectnames.cxx:80
#define PROGRESS_BAR_STEP
Definition: xmlEnums.hxx:21
#define XMLOFF_WARN_UNKNOWN(area, rIter)
constexpr sal_Int32 TOKEN_MASK