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 "xmlTable.hxx"
21 #include "xmlfilter.hxx"
22 #include <xmloff/xmltoken.hxx>
23 #include <xmloff/xmlnmspe.hxx>
24 #include <xmloff/nmspmap.hxx>
25 #include "xmlEnums.hxx"
26 #include "xmlStyleImport.hxx"
27 #include "xmlHierarchyCollection.hxx"
28 #include "xmlstrings.hrc"
29 #include <ucbhelper/content.hxx>
30 #include <com/sun/star/ucb/XCommandEnvironment.hpp>
31 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
32 #include <comphelper/namecontainer.hxx>
33 #include <tools/debug.hxx>
37 using namespace ::com::sun::star
;
38 using namespace ::com::sun::star::uno
;
39 using namespace ::com::sun::star::sdbcx
;
40 using namespace ::com::sun::star::xml::sax
;
42 OXMLTable::OXMLTable( ODBFilter
& _rImport
44 ,const OUString
& _sLocalName
45 ,const uno::Reference
< XAttributeList
> & _xAttrList
46 ,const uno::Reference
< ::com::sun::star::container::XNameAccess
>& _xParentContainer
47 ,const OUString
& _sServiceName
49 :SvXMLImportContext( _rImport
, nPrfx
, _sLocalName
)
50 ,m_xParentContainer(_xParentContainer
)
51 ,m_sServiceName(_sServiceName
)
52 ,m_bApplyFilter(false)
56 OSL_ENSURE(_xAttrList
.is(),"Attribute list is NULL!");
57 const SvXMLNamespaceMap
& rMap
= GetOwnImport().GetNamespaceMap();
58 const SvXMLTokenMap
& rTokenMap
= GetOwnImport().GetQueryElemTokenMap();
60 sal_Int16 nLength
= (_xAttrList
.is()) ? _xAttrList
->getLength() : 0;
61 for(sal_Int16 i
= 0; i
< nLength
; ++i
)
64 OUString sAttrName
= _xAttrList
->getNameByIndex( i
);
65 sal_uInt16 nPrefix
= rMap
.GetKeyByAttrName( sAttrName
,&sLocalName
);
66 OUString sValue
= _xAttrList
->getValueByIndex( i
);
68 switch( rTokenMap
.Get( nPrefix
, sLocalName
) )
70 case XML_TOK_QUERY_NAME
:
73 case XML_TOK_CATALOG_NAME
:
76 case XML_TOK_SCHEMA_NAME
:
79 case XML_TOK_STYLE_NAME
:
80 m_sStyleName
= sValue
;
82 case XML_TOK_APPLY_FILTER
:
83 m_bApplyFilter
= sValue
== "true";
85 case XML_TOK_APPLY_ORDER
:
86 m_bApplyOrder
= sValue
== "true";
90 Sequence
< Any
> aArguments(2);
94 aValue
.Value
<<= m_sName
;
95 aArguments
[0] <<= aValue
;
97 aValue
.Name
= "Parent";
98 aValue
.Value
<<= m_xParentContainer
;
99 aArguments
[1] <<= aValue
;
101 GetOwnImport().GetComponentContext()->getServiceManager()->createInstanceWithArgumentsAndContext(m_sServiceName
,aArguments
, GetOwnImport().GetComponentContext()),
105 OXMLTable::~OXMLTable()
110 SvXMLImportContext
* OXMLTable::CreateChildContext(
112 const OUString
& rLocalName
,
113 const uno::Reference
< XAttributeList
> & xAttrList
)
115 SvXMLImportContext
*pContext
= 0;
116 const SvXMLTokenMap
& rTokenMap
= GetOwnImport().GetQueryElemTokenMap();
118 switch( rTokenMap
.Get( nPrefix
, rLocalName
) )
120 case XML_TOK_FILTER_STATEMENT
:
122 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP
);
124 fillAttributes(nPrefix
, rLocalName
,xAttrList
,m_sFilterStatement
,s1
,s2
,s3
);
127 case XML_TOK_ORDER_STATEMENT
:
129 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP
);
131 fillAttributes(nPrefix
, rLocalName
,xAttrList
,m_sOrderStatement
,s1
,s2
,s3
);
135 case XML_TOK_COLUMNS
:
137 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP
);
138 uno::Reference
< XColumnsSupplier
> xColumnsSup(m_xTable
,UNO_QUERY
);
139 uno::Reference
< XNameAccess
> xColumns
;
140 if ( xColumnsSup
.is() )
142 xColumns
= xColumnsSup
->getColumns();
144 pContext
= new OXMLHierarchyCollection( GetOwnImport(), nPrefix
, rLocalName
,xColumns
,m_xTable
);
150 pContext
= new SvXMLImportContext( GetImport(), nPrefix
, rLocalName
);
155 ODBFilter
& OXMLTable::GetOwnImport()
157 return static_cast<ODBFilter
&>(GetImport());
160 void OXMLTable::setProperties(uno::Reference
< XPropertySet
> & _xProp
)
166 _xProp
->setPropertyValue(PROPERTY_APPLYFILTER
,makeAny(m_bApplyFilter
));
167 _xProp
->setPropertyValue(PROPERTY_FILTER
,makeAny(m_sFilterStatement
));
169 if ( _xProp
->getPropertySetInfo()->hasPropertyByName(PROPERTY_APPLYORDER
) )
170 _xProp
->setPropertyValue(PROPERTY_APPLYORDER
,makeAny(m_bApplyOrder
));
171 _xProp
->setPropertyValue(PROPERTY_ORDER
,makeAny(m_sOrderStatement
));
176 OSL_FAIL("OXMLTable::EndElement -> exception catched");
180 void OXMLTable::EndElement()
182 uno::Reference
<XNameContainer
> xNameContainer(m_xParentContainer
,UNO_QUERY
);
183 if ( xNameContainer
.is() )
189 setProperties(m_xTable
);
191 if ( !m_sStyleName
.isEmpty() )
193 const SvXMLStylesContext
* pAutoStyles
= GetOwnImport().GetAutoStyles();
196 OTableStyleContext
* pAutoStyle
= const_cast<OTableStyleContext
*>(PTR_CAST(OTableStyleContext
,pAutoStyles
->FindStyleChildContext(XML_STYLE_FAMILY_TABLE_TABLE
,m_sStyleName
)));
199 pAutoStyle
->FillPropertySet(m_xTable
);
204 xNameContainer
->insertByName(m_sName
,makeAny(m_xTable
));
209 OSL_FAIL("OXMLQuery::EndElement -> exception catched");
215 void OXMLTable::fillAttributes(sal_uInt16
/*nPrfx*/
216 ,const OUString
& /*_sLocalName*/
217 ,const uno::Reference
< XAttributeList
> & _xAttrList
218 ,OUString
& _rsCommand
219 ,OUString
& _rsTableName
220 ,OUString
& _rsTableSchema
221 ,OUString
& _rsTableCatalog
224 OSL_ENSURE(_xAttrList
.is(),"Attribute list is NULL!");
225 const SvXMLNamespaceMap
& rMap
= GetOwnImport().GetNamespaceMap();
226 const SvXMLTokenMap
& rTokenMap
= GetOwnImport().GetQueryElemTokenMap();
228 sal_Int16 nLength
= (_xAttrList
.is()) ? _xAttrList
->getLength() : 0;
229 for(sal_Int16 i
= 0; i
< nLength
; ++i
)
232 OUString sAttrName
= _xAttrList
->getNameByIndex( i
);
233 sal_uInt16 nPrefix
= rMap
.GetKeyByAttrName( sAttrName
,&sLocalName
);
234 OUString sValue
= _xAttrList
->getValueByIndex( i
);
236 switch( rTokenMap
.Get( nPrefix
, sLocalName
) )
238 case XML_TOK_COMMAND
:
241 case XML_TOK_CATALOG_NAME
:
242 _rsTableCatalog
= sValue
;
244 case XML_TOK_SCHEMA_NAME
:
245 _rsTableSchema
= sValue
;
247 case XML_TOK_QUERY_NAME
:
248 _rsTableName
= sValue
;
254 } // namespace dbaxml
256 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */