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