1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_dbaxml.hxx"
26 #ifndef DBA_XMLHIERARCHYCOLLECTION_HXX
27 #include "xmlHierarchyCollection.hxx"
28 #endif
29 #ifndef DBA_XMLCOMPONENT_HXX
30 #include "xmlComponent.hxx"
31 #endif
32 #ifndef DBA_XMLQUERY_HXX
33 #include "xmlQuery.hxx"
34 #endif
35 #ifndef DBA_XMLCOLUMN_HXX
36 #include "xmlColumn.hxx"
37 #endif
38 #ifndef DBA_XMLFILTER_HXX
39 #include "xmlfilter.hxx"
40 #endif
41 #ifndef _XMLOFF_XMLTOKEN_HXX
42 #include <xmloff/xmltoken.hxx>
43 #endif
44 #ifndef _XMLOFF_XMLNMSPE_HXX
45 #include <xmloff/xmlnmspe.hxx>
46 #endif
47 #ifndef _XMLOFF_NMSPMAP_HXX
48 #include <xmloff/nmspmap.hxx>
49 #endif
50 #ifndef DBA_XMLENUMS_HXX
51 #include "xmlEnums.hxx"
52 #endif
53 #ifndef DBACCESS_SHARED_XMLSTRINGS_HRC
54 #include "xmlstrings.hrc"
55 #endif
56 #ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP_
57 #include <com/sun/star/beans/PropertyValue.hpp>
58 #endif
59 #ifndef _COM_SUN_STAR_CONTAINER_XNAMECONTAINER_HPP_
60 #include <com/sun/star/container/XNameContainer.hpp>
61 #endif
62 #ifndef _TOOLS_DEBUG_HXX
63 #include <tools/debug.hxx>
64 #endif
65
66
67 namespace dbaxml
68 {
69 using namespace ::com::sun::star::uno;
70 using namespace ::com::sun::star::beans;
71 using namespace ::com::sun::star::container;
72 using namespace ::com::sun::star::xml::sax;
DBG_NAME(OXMLHierarchyCollection)73 DBG_NAME(OXMLHierarchyCollection)
74
75 OXMLHierarchyCollection::OXMLHierarchyCollection( ODBFilter& rImport
76 ,sal_uInt16 nPrfx
77 ,const ::rtl::OUString& _sLocalName
78 ,const Reference< XAttributeList > & _xAttrList
79 ,const Reference< XNameAccess >& _xParentContainer
80 ,const ::rtl::OUString& _sCollectionServiceName
81 ,const ::rtl::OUString& _sComponentServiceName) :
82 SvXMLImportContext( rImport, nPrfx, _sLocalName )
83 ,m_xParentContainer(_xParentContainer)
84 ,m_sCollectionServiceName(_sCollectionServiceName)
85 ,m_sComponentServiceName(_sComponentServiceName)
86 {
87 DBG_CTOR(OXMLHierarchyCollection,NULL);
88
89 const SvXMLNamespaceMap& rMap = rImport.GetNamespaceMap();
90 const SvXMLTokenMap& rTokenMap = rImport.GetComponentElemTokenMap();
91
92 sal_Int16 nLength = (_xAttrList.is()) ? _xAttrList->getLength() : 0;
93 for(sal_Int16 i = 0; i < nLength; ++i)
94 {
95 ::rtl::OUString sLocalName;
96 rtl::OUString sAttrName = _xAttrList->getNameByIndex( i );
97 sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName );
98 rtl::OUString sValue = _xAttrList->getValueByIndex( i );
99
100 switch( rTokenMap.Get( nPrefix, sLocalName ) )
101 {
102 case XML_TOK_COMPONENT_NAME:
103 m_sName = sValue;
104 break;
105 }
106 }
107 if ( m_sName.getLength() && _xParentContainer.is() )
108 {
109 try
110 {
111 Sequence< Any > aArguments(2);
112 PropertyValue aValue;
113 // set as folder
114 aValue.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Name"));
115 aValue.Value <<= m_sName;
116 aArguments[0] <<= aValue;
117 //parent
118 aValue.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Parent"));
119 aValue.Value <<= _xParentContainer;
120 aArguments[1] <<= aValue;
121
122 Reference<XMultiServiceFactory> xORB(_xParentContainer,UNO_QUERY);
123 if ( xORB.is() )
124 {
125 m_xContainer.set(xORB->createInstanceWithArguments(_sCollectionServiceName,aArguments),UNO_QUERY);
126 Reference<XNameContainer> xNameContainer(_xParentContainer,UNO_QUERY);
127 if ( xNameContainer.is() && !xNameContainer->hasByName(m_sName) )
128 xNameContainer->insertByName(m_sName,makeAny(m_xContainer));
129 }
130 }
131 catch(Exception&)
132 {
133 OSL_ENSURE(0,"OXMLHierarchyCollection::OXMLHierarchyCollection -> exception catched");
134 }
135 }
136 }
137 // -----------------------------------------------------------------------------
OXMLHierarchyCollection(ODBFilter & rImport,sal_uInt16 nPrfx,const::rtl::OUString & _sLocalName,const Reference<XNameAccess> & _xContainer,const Reference<XPropertySet> & _xTable)138 OXMLHierarchyCollection::OXMLHierarchyCollection( ODBFilter& rImport
139 ,sal_uInt16 nPrfx
140 ,const ::rtl::OUString& _sLocalName
141 ,const Reference< XNameAccess >& _xContainer
142 ,const Reference< XPropertySet >& _xTable
143 ) :
144 SvXMLImportContext( rImport, nPrfx, _sLocalName )
145 ,m_xContainer(_xContainer)
146 ,m_xTable(_xTable)
147 {
148 DBG_CTOR(OXMLHierarchyCollection,NULL);
149 }
150 // -----------------------------------------------------------------------------
151
~OXMLHierarchyCollection()152 OXMLHierarchyCollection::~OXMLHierarchyCollection()
153 {
154
155 DBG_DTOR(OXMLHierarchyCollection,NULL);
156 }
157 // -----------------------------------------------------------------------------
CreateChildContext(sal_uInt16 nPrefix,const::rtl::OUString & rLocalName,const Reference<XAttributeList> & xAttrList)158 SvXMLImportContext* OXMLHierarchyCollection::CreateChildContext(
159 sal_uInt16 nPrefix,
160 const ::rtl::OUString& rLocalName,
161 const Reference< XAttributeList > & xAttrList )
162 {
163 SvXMLImportContext *pContext = 0;
164 const SvXMLTokenMap& rTokenMap = GetOwnImport().GetDocumentsElemTokenMap();
165
166 switch( rTokenMap.Get( nPrefix, rLocalName ) )
167 {
168 // case XML_TOK_QUERY:
169 // pContext = new OXMLQuery( GetOwnImport(), nPrefix, rLocalName,xAttrList,m_xContainer );
170 // break;
171 case XML_TOK_COMPONENT:
172 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
173 pContext = new OXMLComponent( GetOwnImport(), nPrefix, rLocalName,xAttrList,m_xContainer,m_sComponentServiceName );
174 break;
175 case XML_TOK_COLUMN:
176 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
177 pContext = new OXMLColumn( GetOwnImport(), nPrefix, rLocalName,xAttrList,m_xContainer,m_xTable);
178 break;
179 // case XML_TOK_QUERY_COLLECTION:
180 case XML_TOK_COMPONENT_COLLECTION:
181 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
182 pContext = new OXMLHierarchyCollection( GetOwnImport(), nPrefix, rLocalName,xAttrList,m_xContainer,m_sCollectionServiceName,m_sComponentServiceName);
183 break;
184 }
185
186 if( !pContext )
187 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
188
189 return pContext;
190 }
191 // -----------------------------------------------------------------------------
GetOwnImport()192 ODBFilter& OXMLHierarchyCollection::GetOwnImport()
193 {
194 return static_cast<ODBFilter&>(GetImport());
195 }
196 // -----------------------------------------------------------------------------
197 //----------------------------------------------------------------------------
198 } // namespace dbaxml
199 // -----------------------------------------------------------------------------
200