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 "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>
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
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
)
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
:
72 if ( !m_sName
.isEmpty() && _xParentContainer
.is() )
76 Sequence
< Any
> aArguments(2);
80 aValue
.Value
<<= m_sName
;
81 aArguments
[0] <<= aValue
;
83 aValue
.Name
= "Parent";
84 aValue
.Value
<<= _xParentContainer
;
85 aArguments
[1] <<= aValue
;
87 Reference
<XMultiServiceFactory
> xORB(_xParentContainer
,UNO_QUERY
);
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
));
98 OSL_FAIL("OXMLHierarchyCollection::OXMLHierarchyCollection -> exception catched");
103 OXMLHierarchyCollection::OXMLHierarchyCollection( ODBFilter
& rImport
105 ,const OUString
& _sLocalName
106 ,const Reference
< XNameAccess
>& _xContainer
107 ,const Reference
< XPropertySet
>& _xTable
109 SvXMLImportContext( rImport
, nPrfx
, _sLocalName
)
110 ,m_xContainer(_xContainer
)
115 OXMLHierarchyCollection::~OXMLHierarchyCollection()
120 SvXMLImportContext
* OXMLHierarchyCollection::CreateChildContext(
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
);
135 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP
);
136 pContext
= new OXMLColumn( GetOwnImport(), nPrefix
, rLocalName
,xAttrList
,m_xContainer
,m_xTable
);
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
);
145 pContext
= new SvXMLImportContext( GetImport(), nPrefix
, rLocalName
);
150 ODBFilter
& OXMLHierarchyCollection::GetOwnImport()
152 return static_cast<ODBFilter
&>(GetImport());
155 } // namespace dbaxml
157 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */