Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
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/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
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 .
18 : : */
19 : :
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>
34 : :
35 : : namespace dbaxml
36 : : {
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;
41 : : DBG_NAME(OXMLTable)
42 : :
43 : 24 : OXMLTable::OXMLTable( ODBFilter& _rImport
44 : : ,sal_uInt16 nPrfx
45 : : ,const ::rtl::OUString& _sLocalName
46 : : ,const uno::Reference< XAttributeList > & _xAttrList
47 : : ,const uno::Reference< ::com::sun::star::container::XNameAccess >& _xParentContainer
48 : : ,const ::rtl::OUString& _sServiceName
49 : : )
50 : : :SvXMLImportContext( _rImport, nPrfx, _sLocalName )
51 : : ,m_xParentContainer(_xParentContainer)
52 : : ,m_sServiceName(_sServiceName)
53 : : ,m_bApplyFilter(sal_False)
54 : 24 : ,m_bApplyOrder(sal_False)
55 : : {
56 : : DBG_CTOR(OXMLTable,NULL);
57 : :
58 : : OSL_ENSURE(_xAttrList.is(),"Attribute list is NULL!");
59 : 24 : const SvXMLNamespaceMap& rMap = GetOwnImport().GetNamespaceMap();
60 [ + - ]: 24 : const SvXMLTokenMap& rTokenMap = GetOwnImport().GetQueryElemTokenMap();
61 : :
62 [ + - ][ + - ]: 24 : sal_Int16 nLength = (_xAttrList.is()) ? _xAttrList->getLength() : 0;
[ + - ]
63 [ + + ]: 48 : for(sal_Int16 i = 0; i < nLength; ++i)
64 : : {
65 : 24 : ::rtl::OUString sLocalName;
66 [ + - ][ + - ]: 24 : rtl::OUString sAttrName = _xAttrList->getNameByIndex( i );
67 [ + - ]: 24 : sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName );
68 [ + - ][ + - ]: 24 : rtl::OUString sValue = _xAttrList->getValueByIndex( i );
69 : :
70 [ + - ][ + - : 24 : switch( rTokenMap.Get( nPrefix, sLocalName ) )
- - - -
- ]
71 : : {
72 : : case XML_TOK_QUERY_NAME:
73 : 24 : m_sName = sValue;
74 : 24 : break;
75 : : case XML_TOK_CATALOG_NAME:
76 : 0 : m_sCatalog = sValue;
77 : 0 : break;
78 : : case XML_TOK_SCHEMA_NAME:
79 : 0 : m_sSchema = sValue;
80 : 0 : break;
81 : : case XML_TOK_STYLE_NAME:
82 : 0 : m_sStyleName = sValue;
83 : 0 : break;
84 : : case XML_TOK_APPLY_FILTER:
85 : 0 : m_bApplyFilter = sValue == "true";
86 : 0 : break;
87 : : case XML_TOK_APPLY_ORDER:
88 : 0 : m_bApplyOrder = sValue == "true";
89 : 0 : break;
90 : : }
91 : 24 : }
92 [ + - ]: 24 : Sequence< Any > aArguments(2);
93 : 24 : PropertyValue aValue;
94 : : // set as folder
95 [ + - ]: 24 : aValue.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Name"));
96 [ + - ]: 24 : aValue.Value <<= m_sName;
97 [ + - ][ + - ]: 24 : aArguments[0] <<= aValue;
98 : : //parent
99 [ + - ]: 24 : aValue.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Parent"));
100 [ + - ]: 24 : aValue.Value <<= m_xParentContainer;
101 [ + - ][ + - ]: 24 : aArguments[1] <<= aValue;
102 [ + - ][ + - ]: 24 : m_xTable.set(GetOwnImport().getORB()->createInstanceWithArguments(m_sServiceName,aArguments),UNO_QUERY);
[ + - ][ + - ]
[ + - ]
103 : 24 : }
104 : : // -----------------------------------------------------------------------------
105 : :
106 : 24 : OXMLTable::~OXMLTable()
107 : : {
108 : :
109 : : DBG_DTOR(OXMLTable,NULL);
110 [ - + ]: 48 : }
111 : : // -----------------------------------------------------------------------------
112 : 24 : SvXMLImportContext* OXMLTable::CreateChildContext(
113 : : sal_uInt16 nPrefix,
114 : : const ::rtl::OUString& rLocalName,
115 : : const uno::Reference< XAttributeList > & xAttrList )
116 : : {
117 : 24 : SvXMLImportContext *pContext = 0;
118 : 24 : const SvXMLTokenMap& rTokenMap = GetOwnImport().GetQueryElemTokenMap();
119 : :
120 [ - + + - ]: 24 : switch( rTokenMap.Get( nPrefix, rLocalName ) )
121 : : {
122 : : case XML_TOK_FILTER_STATEMENT:
123 : : {
124 [ # # ][ # # ]: 0 : GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
125 : 0 : ::rtl::OUString s1,s2,s3;
126 [ # # ]: 0 : fillAttributes(nPrefix, rLocalName,xAttrList,m_sFilterStatement,s1,s2,s3);
127 : : }
128 : 0 : break;
129 : : case XML_TOK_ORDER_STATEMENT:
130 : : {
131 [ + - ][ + - ]: 12 : GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
132 : 12 : ::rtl::OUString s1,s2,s3;
133 [ + - ]: 12 : fillAttributes(nPrefix, rLocalName,xAttrList,m_sOrderStatement,s1,s2,s3);
134 : : }
135 : 12 : break;
136 : :
137 : : case XML_TOK_COLUMNS:
138 : : {
139 [ + - ][ + - ]: 12 : GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
140 [ + - ]: 12 : uno::Reference< XColumnsSupplier > xColumnsSup(m_xTable,UNO_QUERY);
141 : 12 : uno::Reference< XNameAccess > xColumns;
142 [ + - ]: 12 : if ( xColumnsSup.is() )
143 : : {
144 [ + - ][ + - ]: 12 : xColumns = xColumnsSup->getColumns();
[ + - ]
145 : : }
146 [ + - ][ + - ]: 12 : pContext = new OXMLHierarchyCollection( GetOwnImport(), nPrefix, rLocalName ,xColumns,m_xTable);
147 : : }
148 : 12 : break;
149 : : }
150 : :
151 [ + + ]: 24 : if( !pContext )
152 [ + - ]: 12 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
153 : :
154 : 24 : return pContext;
155 : : }
156 : : // -----------------------------------------------------------------------------
157 : 156 : ODBFilter& OXMLTable::GetOwnImport()
158 : : {
159 : 156 : return static_cast<ODBFilter&>(GetImport());
160 : : }
161 : : // -----------------------------------------------------------------------------
162 : 24 : void OXMLTable::setProperties(uno::Reference< XPropertySet > & _xProp )
163 : : {
164 : : try
165 : : {
166 [ + - ]: 24 : if ( _xProp.is() )
167 : : {
168 [ + - ][ + - ]: 24 : _xProp->setPropertyValue(PROPERTY_APPLYFILTER,makeAny(m_bApplyFilter));
[ + - ][ + - ]
169 [ + - ][ + - ]: 24 : _xProp->setPropertyValue(PROPERTY_FILTER,makeAny(m_sFilterStatement));
[ + - ][ + - ]
170 : :
171 [ + - ][ + - ]: 24 : if ( _xProp->getPropertySetInfo()->hasPropertyByName(PROPERTY_APPLYORDER) )
[ + - ][ + - ]
[ - + ][ + - ]
172 [ # # ][ # # ]: 0 : _xProp->setPropertyValue(PROPERTY_APPLYORDER,makeAny(m_bApplyOrder));
[ # # ][ # # ]
173 [ + - ][ + - ]: 24 : _xProp->setPropertyValue(PROPERTY_ORDER,makeAny(m_sOrderStatement));
[ + - ][ + - ]
[ # # ]
174 : : }
175 : : }
176 : 0 : catch(Exception&)
177 : : {
178 : : OSL_FAIL("OXMLTable::EndElement -> exception catched");
179 : : }
180 : 24 : }
181 : : // -----------------------------------------------------------------------------
182 : 24 : void OXMLTable::EndElement()
183 : : {
184 [ + - ]: 24 : uno::Reference<XNameContainer> xNameContainer(m_xParentContainer,UNO_QUERY);
185 [ + - ]: 24 : if ( xNameContainer.is() )
186 : : {
187 : : try
188 : : {
189 [ + - ]: 24 : if ( m_xTable.is() )
190 : : {
191 [ + - ]: 24 : setProperties(m_xTable);
192 : :
193 [ - + ]: 24 : if ( !m_sStyleName.isEmpty() )
194 : : {
195 [ # # ]: 0 : const SvXMLStylesContext* pAutoStyles = GetOwnImport().GetAutoStyles();
196 [ # # ]: 0 : if ( pAutoStyles )
197 : : {
198 [ # # ][ # # ]: 0 : OTableStyleContext* pAutoStyle = PTR_CAST(OTableStyleContext,pAutoStyles->FindStyleChildContext(XML_STYLE_FAMILY_TABLE_TABLE,m_sStyleName));
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
199 [ # # ]: 0 : if ( pAutoStyle )
200 : : {
201 [ # # ]: 0 : pAutoStyle->FillPropertySet(m_xTable);
202 : : }
203 : : }
204 : : }
205 : :
206 [ + - ][ + - ]: 24 : xNameContainer->insertByName(m_sName,makeAny(m_xTable));
[ + - ][ # # ]
207 : : }
208 : : }
209 [ # # ]: 0 : catch(Exception&)
210 : : {
211 : : OSL_FAIL("OXMLQuery::EndElement -> exception catched");
212 : : }
213 : 24 : }
214 : :
215 : 24 : }
216 : : // -----------------------------------------------------------------------------
217 : 12 : void OXMLTable::fillAttributes(sal_uInt16 /*nPrfx*/
218 : : ,const ::rtl::OUString& /*_sLocalName*/
219 : : ,const uno::Reference< XAttributeList > & _xAttrList
220 : : , ::rtl::OUString& _rsCommand
221 : : ,::rtl::OUString& _rsTableName
222 : : ,::rtl::OUString& _rsTableSchema
223 : : ,::rtl::OUString& _rsTableCatalog
224 : : )
225 : : {
226 : : OSL_ENSURE(_xAttrList.is(),"Attribute list is NULL!");
227 : 12 : const SvXMLNamespaceMap& rMap = GetOwnImport().GetNamespaceMap();
228 : 12 : const SvXMLTokenMap& rTokenMap = GetOwnImport().GetQueryElemTokenMap();
229 : :
230 [ + - ]: 12 : sal_Int16 nLength = (_xAttrList.is()) ? _xAttrList->getLength() : 0;
231 [ + + ]: 24 : for(sal_Int16 i = 0; i < nLength; ++i)
232 : : {
233 : 12 : ::rtl::OUString sLocalName;
234 [ + - ][ + - ]: 12 : rtl::OUString sAttrName = _xAttrList->getNameByIndex( i );
235 [ + - ]: 12 : sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName );
236 [ + - ][ + - ]: 12 : rtl::OUString sValue = _xAttrList->getValueByIndex( i );
237 : :
238 [ + - ][ + - : 12 : switch( rTokenMap.Get( nPrefix, sLocalName ) )
- - - ]
239 : : {
240 : : case XML_TOK_COMMAND:
241 : 12 : _rsCommand = sValue;
242 : 12 : break;
243 : : case XML_TOK_CATALOG_NAME:
244 : 0 : _rsTableCatalog = sValue;
245 : 0 : break;
246 : : case XML_TOK_SCHEMA_NAME:
247 : 0 : _rsTableSchema = sValue;
248 : 0 : break;
249 : : case XML_TOK_QUERY_NAME:
250 : 0 : _rsTableName = sValue;
251 : 0 : break;
252 : : }
253 : 12 : }
254 : 12 : }
255 : : //----------------------------------------------------------------------------
256 : : } // namespace dbaxml
257 : : // -----------------------------------------------------------------------------
258 : :
259 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|