merge the formfield patch from ooo-build
[ooovba.git] / dbaccess / source / filter / xml / xmlTable.cxx
blobd9bda203c37ded0317a31ca6c015fe744c16434a
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: xmlTable.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_XMLTABLE_HXX
34 #include "xmlTable.hxx"
35 #endif
36 #ifndef DBA_XMLFILTER_HXX
37 #include "xmlfilter.hxx"
38 #endif
39 #ifndef _XMLOFF_XMLTOKEN_HXX
40 #include <xmloff/xmltoken.hxx>
41 #endif
42 #ifndef _XMLOFF_XMLNMSPE_HXX
43 #include <xmloff/xmlnmspe.hxx>
44 #endif
45 #ifndef _XMLOFF_NMSPMAP_HXX
46 #include <xmloff/nmspmap.hxx>
47 #endif
48 #ifndef DBA_XMLENUMS_HXX
49 #include "xmlEnums.hxx"
50 #endif
51 #ifndef DBA_XMLSTYLEIMPORT_HXX
52 #include "xmlStyleImport.hxx"
53 #endif
54 #ifndef DBA_XMLHIERARCHYCOLLECTION_HXX
55 #include "xmlHierarchyCollection.hxx"
56 #endif
57 #ifndef DBACCESS_SHARED_XMLSTRINGS_HRC
58 #include "xmlstrings.hrc"
59 #endif
60 #ifndef _UCBHELPER_CONTENT_HXX
61 #include <ucbhelper/content.hxx>
62 #endif
63 #ifndef _COM_SUN_STAR_UCB_XCOMMANDENVIRONMENT_HPP_
64 #include <com/sun/star/ucb/XCommandEnvironment.hpp>
65 #endif
66 #ifndef _COM_SUN_STAR_SDBCX_XCOLUMNSSUPPLIER_HPP_
67 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
68 #endif
69 #ifndef _COMPHELPER_NAMECONTAINER_HXX_
70 #include <comphelper/namecontainer.hxx>
71 #endif
72 #ifndef _TOOLS_DEBUG_HXX
73 #include <tools/debug.hxx>
74 #endif
76 namespace dbaxml
78 using namespace ::com::sun::star;
79 using namespace ::com::sun::star::uno;
80 using namespace ::com::sun::star::sdbcx;
81 using namespace ::com::sun::star::xml::sax;
82 DBG_NAME(OXMLTable)
84 OXMLTable::OXMLTable( ODBFilter& _rImport
85 ,sal_uInt16 nPrfx
86 ,const ::rtl::OUString& _sLocalName
87 ,const uno::Reference< XAttributeList > & _xAttrList
88 ,const uno::Reference< ::com::sun::star::container::XNameAccess >& _xParentContainer
89 ,const ::rtl::OUString& _sServiceName
91 :SvXMLImportContext( _rImport, nPrfx, _sLocalName )
92 ,m_xParentContainer(_xParentContainer)
93 ,m_sServiceName(_sServiceName)
94 ,m_bApplyFilter(sal_False)
95 ,m_bApplyOrder(sal_False)
97 DBG_CTOR(OXMLTable,NULL);
99 OSL_ENSURE(_xAttrList.is(),"Attribute list is NULL!");
100 const SvXMLNamespaceMap& rMap = GetOwnImport().GetNamespaceMap();
101 const SvXMLTokenMap& rTokenMap = GetOwnImport().GetQueryElemTokenMap();
103 sal_Int16 nLength = (_xAttrList.is()) ? _xAttrList->getLength() : 0;
104 for(sal_Int16 i = 0; i < nLength; ++i)
106 ::rtl::OUString sLocalName;
107 rtl::OUString sAttrName = _xAttrList->getNameByIndex( i );
108 sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName );
109 rtl::OUString sValue = _xAttrList->getValueByIndex( i );
111 switch( rTokenMap.Get( nPrefix, sLocalName ) )
113 case XML_TOK_QUERY_NAME:
114 m_sName = sValue;
115 break;
116 case XML_TOK_CATALOG_NAME:
117 m_sCatalog = sValue;
118 break;
119 case XML_TOK_SCHEMA_NAME:
120 m_sSchema = sValue;
121 break;
122 case XML_TOK_STYLE_NAME:
123 m_sStyleName = sValue;
124 break;
125 case XML_TOK_APPLY_FILTER:
126 m_bApplyFilter = sValue.equalsAscii("true");
127 break;
128 case XML_TOK_APPLY_ORDER:
129 m_bApplyOrder = sValue.equalsAscii("true");
130 break;
133 Sequence< Any > aArguments(2);
134 PropertyValue aValue;
135 // set as folder
136 aValue.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Name"));
137 aValue.Value <<= m_sName;
138 aArguments[0] <<= aValue;
139 //parent
140 aValue.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Parent"));
141 aValue.Value <<= m_xParentContainer;
142 aArguments[1] <<= aValue;
143 m_xTable.set(GetOwnImport().getORB()->createInstanceWithArguments(m_sServiceName,aArguments),UNO_QUERY);
145 // -----------------------------------------------------------------------------
147 OXMLTable::~OXMLTable()
150 DBG_DTOR(OXMLTable,NULL);
152 // -----------------------------------------------------------------------------
153 SvXMLImportContext* OXMLTable::CreateChildContext(
154 sal_uInt16 nPrefix,
155 const ::rtl::OUString& rLocalName,
156 const uno::Reference< XAttributeList > & xAttrList )
158 SvXMLImportContext *pContext = 0;
159 const SvXMLTokenMap& rTokenMap = GetOwnImport().GetQueryElemTokenMap();
161 switch( rTokenMap.Get( nPrefix, rLocalName ) )
163 case XML_TOK_FILTER_STATEMENT:
165 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
166 ::rtl::OUString s1,s2,s3;
167 fillAttributes(nPrefix, rLocalName,xAttrList,m_sFilterStatement,s1,s2,s3);
169 break;
170 case XML_TOK_ORDER_STATEMENT:
172 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
173 ::rtl::OUString s1,s2,s3;
174 fillAttributes(nPrefix, rLocalName,xAttrList,m_sOrderStatement,s1,s2,s3);
176 break;
178 case XML_TOK_COLUMNS:
180 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
181 uno::Reference< XColumnsSupplier > xColumnsSup(m_xTable,UNO_QUERY);
182 uno::Reference< XNameAccess > xColumns;
183 if ( xColumnsSup.is() )
185 xColumns = xColumnsSup->getColumns();
187 pContext = new OXMLHierarchyCollection( GetOwnImport(), nPrefix, rLocalName ,xColumns,m_xTable);
189 break;
192 if( !pContext )
193 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
195 return pContext;
197 // -----------------------------------------------------------------------------
198 ODBFilter& OXMLTable::GetOwnImport()
200 return static_cast<ODBFilter&>(GetImport());
202 // -----------------------------------------------------------------------------
203 void OXMLTable::setProperties(uno::Reference< XPropertySet > & _xProp )
207 if ( _xProp.is() )
209 _xProp->setPropertyValue(PROPERTY_APPLYFILTER,makeAny(m_bApplyFilter));
210 _xProp->setPropertyValue(PROPERTY_FILTER,makeAny(m_sFilterStatement));
212 if ( _xProp->getPropertySetInfo()->hasPropertyByName(PROPERTY_APPLYORDER) )
213 _xProp->setPropertyValue(PROPERTY_APPLYORDER,makeAny(m_bApplyOrder));
214 _xProp->setPropertyValue(PROPERTY_ORDER,makeAny(m_sOrderStatement));
217 catch(Exception&)
219 OSL_ENSURE(0,"OXMLTable::EndElement -> exception catched");
222 // -----------------------------------------------------------------------------
223 void OXMLTable::EndElement()
225 uno::Reference<XNameContainer> xNameContainer(m_xParentContainer,UNO_QUERY);
226 if ( xNameContainer.is() )
230 if ( m_xTable.is() )
232 setProperties(m_xTable);
234 if ( m_sStyleName.getLength() )
236 const SvXMLStylesContext* pAutoStyles = GetOwnImport().GetAutoStyles();
237 if ( pAutoStyles )
239 OTableStyleContext* pAutoStyle = PTR_CAST(OTableStyleContext,pAutoStyles->FindStyleChildContext(XML_STYLE_FAMILY_TABLE_TABLE,m_sStyleName));
240 if ( pAutoStyle )
242 pAutoStyle->FillPropertySet(m_xTable);
247 xNameContainer->insertByName(m_sName,makeAny(m_xTable));
250 catch(Exception&)
252 OSL_ENSURE(0,"OXMLQuery::EndElement -> exception catched");
257 // -----------------------------------------------------------------------------
258 void OXMLTable::fillAttributes(sal_uInt16 /*nPrfx*/
259 ,const ::rtl::OUString& /*_sLocalName*/
260 ,const uno::Reference< XAttributeList > & _xAttrList
261 , ::rtl::OUString& _rsCommand
262 ,::rtl::OUString& _rsTableName
263 ,::rtl::OUString& _rsTableSchema
264 ,::rtl::OUString& _rsTableCatalog
267 OSL_ENSURE(_xAttrList.is(),"Attribute list is NULL!");
268 const SvXMLNamespaceMap& rMap = GetOwnImport().GetNamespaceMap();
269 const SvXMLTokenMap& rTokenMap = GetOwnImport().GetQueryElemTokenMap();
271 sal_Int16 nLength = (_xAttrList.is()) ? _xAttrList->getLength() : 0;
272 for(sal_Int16 i = 0; i < nLength; ++i)
274 ::rtl::OUString sLocalName;
275 rtl::OUString sAttrName = _xAttrList->getNameByIndex( i );
276 sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName );
277 rtl::OUString sValue = _xAttrList->getValueByIndex( i );
279 switch( rTokenMap.Get( nPrefix, sLocalName ) )
281 case XML_TOK_COMMAND:
282 _rsCommand = sValue;
283 break;
284 case XML_TOK_CATALOG_NAME:
285 _rsTableCatalog = sValue;
286 break;
287 case XML_TOK_SCHEMA_NAME:
288 _rsTableSchema = sValue;
289 break;
290 case XML_TOK_QUERY_NAME:
291 _rsTableName = sValue;
292 break;
296 //----------------------------------------------------------------------------
297 } // namespace dbaxml
298 // -----------------------------------------------------------------------------