update dev300-m58
[ooovba.git] / dbaccess / source / filter / xml / xmlHierarchyCollection.cxx
blobf638a52dbb8130897448806609f2740d11200891
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xmlHierarchyCollection.cxx,v $
10 * $Revision: 1.9 $
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"
35 #endif
36 #ifndef DBA_XMLCOMPONENT_HXX
37 #include "xmlComponent.hxx"
38 #endif
39 #ifndef DBA_XMLQUERY_HXX
40 #include "xmlQuery.hxx"
41 #endif
42 #ifndef DBA_XMLCOLUMN_HXX
43 #include "xmlColumn.hxx"
44 #endif
45 #ifndef DBA_XMLFILTER_HXX
46 #include "xmlfilter.hxx"
47 #endif
48 #ifndef _XMLOFF_XMLTOKEN_HXX
49 #include <xmloff/xmltoken.hxx>
50 #endif
51 #ifndef _XMLOFF_XMLNMSPE_HXX
52 #include <xmloff/xmlnmspe.hxx>
53 #endif
54 #ifndef _XMLOFF_NMSPMAP_HXX
55 #include <xmloff/nmspmap.hxx>
56 #endif
57 #ifndef DBA_XMLENUMS_HXX
58 #include "xmlEnums.hxx"
59 #endif
60 #ifndef DBACCESS_SHARED_XMLSTRINGS_HRC
61 #include "xmlstrings.hrc"
62 #endif
63 #ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP_
64 #include <com/sun/star/beans/PropertyValue.hpp>
65 #endif
66 #ifndef _COM_SUN_STAR_CONTAINER_XNAMECONTAINER_HPP_
67 #include <com/sun/star/container/XNameContainer.hpp>
68 #endif
69 #ifndef _TOOLS_DEBUG_HXX
70 #include <tools/debug.hxx>
71 #endif
74 namespace dbaxml
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
83 ,sal_uInt16 nPrfx
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:
110 m_sName = sValue;
111 break;
114 if ( m_sName.getLength() && _xParentContainer.is() )
118 Sequence< Any > aArguments(2);
119 PropertyValue aValue;
120 // set as folder
121 aValue.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Name"));
122 aValue.Value <<= m_sName;
123 aArguments[0] <<= aValue;
124 //parent
125 aValue.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Parent"));
126 aValue.Value <<= _xParentContainer;
127 aArguments[1] <<= aValue;
129 Reference<XMultiServiceFactory> xORB(_xParentContainer,UNO_QUERY);
130 if ( xORB.is() )
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));
138 catch(Exception&)
140 OSL_ENSURE(0,"OXMLHierarchyCollection::OXMLHierarchyCollection -> exception catched");
144 // -----------------------------------------------------------------------------
145 OXMLHierarchyCollection::OXMLHierarchyCollection( ODBFilter& rImport
146 ,sal_uInt16 nPrfx
147 ,const ::rtl::OUString& _sLocalName
148 ,const Reference< XNameAccess >& _xContainer
149 ,const Reference< XPropertySet >& _xTable
151 SvXMLImportContext( rImport, nPrfx, _sLocalName )
152 ,m_xContainer(_xContainer)
153 ,m_xTable(_xTable)
155 DBG_CTOR(OXMLHierarchyCollection,NULL);
157 // -----------------------------------------------------------------------------
159 OXMLHierarchyCollection::~OXMLHierarchyCollection()
162 DBG_DTOR(OXMLHierarchyCollection,NULL);
164 // -----------------------------------------------------------------------------
165 SvXMLImportContext* OXMLHierarchyCollection::CreateChildContext(
166 sal_uInt16 nPrefix,
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 );
177 // break;
178 case XML_TOK_COMPONENT:
179 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
180 pContext = new OXMLComponent( GetOwnImport(), nPrefix, rLocalName,xAttrList,m_xContainer,m_sComponentServiceName );
181 break;
182 case XML_TOK_COLUMN:
183 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
184 pContext = new OXMLColumn( GetOwnImport(), nPrefix, rLocalName,xAttrList,m_xContainer,m_xTable);
185 break;
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);
190 break;
193 if( !pContext )
194 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
196 return pContext;
198 // -----------------------------------------------------------------------------
199 ODBFilter& OXMLHierarchyCollection::GetOwnImport()
201 return static_cast<ODBFilter&>(GetImport());
203 // -----------------------------------------------------------------------------
204 //----------------------------------------------------------------------------
205 } // namespace dbaxml
206 // -----------------------------------------------------------------------------