1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xmlHierarchyCollection.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
33 #ifndef DBA_XMLHIERARCHYCOLLECTION_HXX
34 #include "xmlHierarchyCollection.hxx"
36 #ifndef DBA_XMLCOMPONENT_HXX
37 #include "xmlComponent.hxx"
39 #ifndef DBA_XMLQUERY_HXX
40 #include "xmlQuery.hxx"
42 #ifndef DBA_XMLCOLUMN_HXX
43 #include "xmlColumn.hxx"
45 #ifndef DBA_XMLFILTER_HXX
46 #include "xmlfilter.hxx"
48 #ifndef _XMLOFF_XMLTOKEN_HXX
49 #include <xmloff/xmltoken.hxx>
51 #ifndef _XMLOFF_XMLNMSPE_HXX
52 #include <xmloff/xmlnmspe.hxx>
54 #ifndef _XMLOFF_NMSPMAP_HXX
55 #include <xmloff/nmspmap.hxx>
57 #ifndef DBA_XMLENUMS_HXX
58 #include "xmlEnums.hxx"
60 #ifndef DBACCESS_SHARED_XMLSTRINGS_HRC
61 #include "xmlstrings.hrc"
63 #ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP_
64 #include <com/sun/star/beans/PropertyValue.hpp>
66 #ifndef _COM_SUN_STAR_CONTAINER_XNAMECONTAINER_HPP_
67 #include <com/sun/star/container/XNameContainer.hpp>
69 #ifndef _TOOLS_DEBUG_HXX
70 #include <tools/debug.hxx>
76 using namespace ::com::sun::star::uno
;
77 using namespace ::com::sun::star::beans
;
78 using namespace ::com::sun::star::container
;
79 using namespace ::com::sun::star::xml::sax
;
80 DBG_NAME(OXMLHierarchyCollection
)
82 OXMLHierarchyCollection::OXMLHierarchyCollection( ODBFilter
& rImport
84 ,const ::rtl::OUString
& _sLocalName
85 ,const Reference
< XAttributeList
> & _xAttrList
86 ,const Reference
< XNameAccess
>& _xParentContainer
87 ,const ::rtl::OUString
& _sCollectionServiceName
88 ,const ::rtl::OUString
& _sComponentServiceName
) :
89 SvXMLImportContext( rImport
, nPrfx
, _sLocalName
)
90 ,m_xParentContainer(_xParentContainer
)
91 ,m_sCollectionServiceName(_sCollectionServiceName
)
92 ,m_sComponentServiceName(_sComponentServiceName
)
94 DBG_CTOR(OXMLHierarchyCollection
,NULL
);
96 const SvXMLNamespaceMap
& rMap
= rImport
.GetNamespaceMap();
97 const SvXMLTokenMap
& rTokenMap
= rImport
.GetComponentElemTokenMap();
99 sal_Int16 nLength
= (_xAttrList
.is()) ? _xAttrList
->getLength() : 0;
100 for(sal_Int16 i
= 0; i
< nLength
; ++i
)
102 ::rtl::OUString sLocalName
;
103 rtl::OUString sAttrName
= _xAttrList
->getNameByIndex( i
);
104 sal_uInt16 nPrefix
= rMap
.GetKeyByAttrName( sAttrName
,&sLocalName
);
105 rtl::OUString sValue
= _xAttrList
->getValueByIndex( i
);
107 switch( rTokenMap
.Get( nPrefix
, sLocalName
) )
109 case XML_TOK_COMPONENT_NAME
:
114 if ( m_sName
.getLength() && _xParentContainer
.is() )
118 Sequence
< Any
> aArguments(2);
119 PropertyValue aValue
;
121 aValue
.Name
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Name"));
122 aValue
.Value
<<= m_sName
;
123 aArguments
[0] <<= aValue
;
125 aValue
.Name
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Parent"));
126 aValue
.Value
<<= _xParentContainer
;
127 aArguments
[1] <<= aValue
;
129 Reference
<XMultiServiceFactory
> xORB(_xParentContainer
,UNO_QUERY
);
132 m_xContainer
.set(xORB
->createInstanceWithArguments(_sCollectionServiceName
,aArguments
),UNO_QUERY
);
133 Reference
<XNameContainer
> xNameContainer(_xParentContainer
,UNO_QUERY
);
134 if ( xNameContainer
.is() && !xNameContainer
->hasByName(m_sName
) )
135 xNameContainer
->insertByName(m_sName
,makeAny(m_xContainer
));
140 OSL_ENSURE(0,"OXMLHierarchyCollection::OXMLHierarchyCollection -> exception catched");
144 // -----------------------------------------------------------------------------
145 OXMLHierarchyCollection::OXMLHierarchyCollection( ODBFilter
& rImport
147 ,const ::rtl::OUString
& _sLocalName
148 ,const Reference
< XNameAccess
>& _xContainer
149 ,const Reference
< XPropertySet
>& _xTable
151 SvXMLImportContext( rImport
, nPrfx
, _sLocalName
)
152 ,m_xContainer(_xContainer
)
155 DBG_CTOR(OXMLHierarchyCollection
,NULL
);
157 // -----------------------------------------------------------------------------
159 OXMLHierarchyCollection::~OXMLHierarchyCollection()
162 DBG_DTOR(OXMLHierarchyCollection
,NULL
);
164 // -----------------------------------------------------------------------------
165 SvXMLImportContext
* OXMLHierarchyCollection::CreateChildContext(
167 const ::rtl::OUString
& rLocalName
,
168 const Reference
< XAttributeList
> & xAttrList
)
170 SvXMLImportContext
*pContext
= 0;
171 const SvXMLTokenMap
& rTokenMap
= GetOwnImport().GetDocumentsElemTokenMap();
173 switch( rTokenMap
.Get( nPrefix
, rLocalName
) )
175 // case XML_TOK_QUERY:
176 // pContext = new OXMLQuery( GetOwnImport(), nPrefix, rLocalName,xAttrList,m_xContainer );
178 case XML_TOK_COMPONENT
:
179 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP
);
180 pContext
= new OXMLComponent( GetOwnImport(), nPrefix
, rLocalName
,xAttrList
,m_xContainer
,m_sComponentServiceName
);
183 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP
);
184 pContext
= new OXMLColumn( GetOwnImport(), nPrefix
, rLocalName
,xAttrList
,m_xContainer
,m_xTable
);
186 // case XML_TOK_QUERY_COLLECTION:
187 case XML_TOK_COMPONENT_COLLECTION
:
188 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP
);
189 pContext
= new OXMLHierarchyCollection( GetOwnImport(), nPrefix
, rLocalName
,xAttrList
,m_xContainer
,m_sCollectionServiceName
,m_sComponentServiceName
);
194 pContext
= new SvXMLImportContext( GetImport(), nPrefix
, rLocalName
);
198 // -----------------------------------------------------------------------------
199 ODBFilter
& OXMLHierarchyCollection::GetOwnImport()
201 return static_cast<ODBFilter
&>(GetImport());
203 // -----------------------------------------------------------------------------
204 //----------------------------------------------------------------------------
205 } // namespace dbaxml
206 // -----------------------------------------------------------------------------