bump product version to 5.0.4.1
[LibreOffice.git] / dbaccess / source / filter / xml / xmlHierarchyCollection.cxx
blob5abc7bf1500dd311ce3018c39206c60f72d87659
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 "xmlQuery.hxx"
23 #include "xmlColumn.hxx"
24 #include "xmlfilter.hxx"
25 #include <xmloff/xmltoken.hxx>
26 #include <xmloff/xmlnmspe.hxx>
27 #include <xmloff/nmspmap.hxx>
28 #include "xmlEnums.hxx"
29 #include "xmlstrings.hrc"
30 #include <com/sun/star/beans/PropertyValue.hpp>
31 #include <com/sun/star/container/XNameContainer.hpp>
32 #include <tools/debug.hxx>
34 namespace dbaxml
36 using namespace ::com::sun::star::uno;
37 using namespace ::com::sun::star::beans;
38 using namespace ::com::sun::star::container;
39 using namespace ::com::sun::star::xml::sax;
41 OXMLHierarchyCollection::OXMLHierarchyCollection( ODBFilter& rImport
42 ,sal_uInt16 nPrfx
43 ,const OUString& _sLocalName
44 ,const Reference< XAttributeList > & _xAttrList
45 ,const Reference< XNameAccess >& _xParentContainer
46 ,const OUString& _sCollectionServiceName
47 ,const OUString& _sComponentServiceName) :
48 SvXMLImportContext( rImport, nPrfx, _sLocalName )
49 ,m_xParentContainer(_xParentContainer)
50 ,m_sCollectionServiceName(_sCollectionServiceName)
51 ,m_sComponentServiceName(_sComponentServiceName)
54 const SvXMLNamespaceMap& rMap = rImport.GetNamespaceMap();
55 const SvXMLTokenMap& rTokenMap = rImport.GetComponentElemTokenMap();
57 sal_Int16 nLength = (_xAttrList.is()) ? _xAttrList->getLength() : 0;
58 for(sal_Int16 i = 0; i < nLength; ++i)
60 OUString sLocalName;
61 OUString sAttrName = _xAttrList->getNameByIndex( i );
62 sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName );
63 OUString sValue = _xAttrList->getValueByIndex( i );
65 switch( rTokenMap.Get( nPrefix, sLocalName ) )
67 case XML_TOK_COMPONENT_NAME:
68 m_sName = sValue;
69 break;
72 if ( !m_sName.isEmpty() && _xParentContainer.is() )
74 try
76 Sequence< Any > aArguments(2);
77 PropertyValue aValue;
78 // set as folder
79 aValue.Name = "Name";
80 aValue.Value <<= m_sName;
81 aArguments[0] <<= aValue;
82 //parent
83 aValue.Name = "Parent";
84 aValue.Value <<= _xParentContainer;
85 aArguments[1] <<= aValue;
87 Reference<XMultiServiceFactory> xORB(_xParentContainer,UNO_QUERY);
88 if ( xORB.is() )
90 m_xContainer.set(xORB->createInstanceWithArguments(_sCollectionServiceName,aArguments),UNO_QUERY);
91 Reference<XNameContainer> xNameContainer(_xParentContainer,UNO_QUERY);
92 if ( xNameContainer.is() && !xNameContainer->hasByName(m_sName) )
93 xNameContainer->insertByName(m_sName,makeAny(m_xContainer));
96 catch(Exception&)
98 OSL_FAIL("OXMLHierarchyCollection::OXMLHierarchyCollection -> exception catched");
103 OXMLHierarchyCollection::OXMLHierarchyCollection( ODBFilter& rImport
104 ,sal_uInt16 nPrfx
105 ,const OUString& _sLocalName
106 ,const Reference< XNameAccess >& _xContainer
107 ,const Reference< XPropertySet >& _xTable
109 SvXMLImportContext( rImport, nPrfx, _sLocalName )
110 ,m_xContainer(_xContainer)
111 ,m_xTable(_xTable)
115 OXMLHierarchyCollection::~OXMLHierarchyCollection()
120 SvXMLImportContext* OXMLHierarchyCollection::CreateChildContext(
121 sal_uInt16 nPrefix,
122 const OUString& rLocalName,
123 const Reference< XAttributeList > & xAttrList )
125 SvXMLImportContext *pContext = 0;
126 const SvXMLTokenMap& rTokenMap = GetOwnImport().GetDocumentsElemTokenMap();
128 switch( rTokenMap.Get( nPrefix, rLocalName ) )
130 case XML_TOK_COMPONENT:
131 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
132 pContext = new OXMLComponent( GetOwnImport(), nPrefix, rLocalName,xAttrList,m_xContainer,m_sComponentServiceName );
133 break;
134 case XML_TOK_COLUMN:
135 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
136 pContext = new OXMLColumn( GetOwnImport(), nPrefix, rLocalName,xAttrList,m_xContainer,m_xTable);
137 break;
138 case XML_TOK_COMPONENT_COLLECTION:
139 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
140 pContext = new OXMLHierarchyCollection( GetOwnImport(), nPrefix, rLocalName,xAttrList,m_xContainer,m_sCollectionServiceName,m_sComponentServiceName);
141 break;
144 if( !pContext )
145 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
147 return pContext;
150 ODBFilter& OXMLHierarchyCollection::GetOwnImport()
152 return static_cast<ODBFilter&>(GetImport());
155 } // namespace dbaxml
157 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */