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