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 0 : 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 0 : ,m_bApplyOrder(sal_False)
55 : {
56 : DBG_CTOR(OXMLTable,NULL);
57 :
58 : OSL_ENSURE(_xAttrList.is(),"Attribute list is NULL!");
59 0 : const SvXMLNamespaceMap& rMap = GetOwnImport().GetNamespaceMap();
60 0 : const SvXMLTokenMap& rTokenMap = GetOwnImport().GetQueryElemTokenMap();
61 :
62 0 : sal_Int16 nLength = (_xAttrList.is()) ? _xAttrList->getLength() : 0;
63 0 : for(sal_Int16 i = 0; i < nLength; ++i)
64 : {
65 0 : ::rtl::OUString sLocalName;
66 0 : rtl::OUString sAttrName = _xAttrList->getNameByIndex( i );
67 0 : sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName );
68 0 : rtl::OUString sValue = _xAttrList->getValueByIndex( i );
69 :
70 0 : switch( rTokenMap.Get( nPrefix, sLocalName ) )
71 : {
72 : case XML_TOK_QUERY_NAME:
73 0 : m_sName = sValue;
74 0 : 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 0 : }
92 0 : Sequence< Any > aArguments(2);
93 0 : PropertyValue aValue;
94 : // set as folder
95 0 : aValue.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Name"));
96 0 : aValue.Value <<= m_sName;
97 0 : aArguments[0] <<= aValue;
98 : //parent
99 0 : aValue.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Parent"));
100 0 : aValue.Value <<= m_xParentContainer;
101 0 : aArguments[1] <<= aValue;
102 0 : m_xTable.set(GetOwnImport().getORB()->createInstanceWithArguments(m_sServiceName,aArguments),UNO_QUERY);
103 0 : }
104 : // -----------------------------------------------------------------------------
105 :
106 0 : OXMLTable::~OXMLTable()
107 : {
108 :
109 : DBG_DTOR(OXMLTable,NULL);
110 0 : }
111 : // -----------------------------------------------------------------------------
112 0 : SvXMLImportContext* OXMLTable::CreateChildContext(
113 : sal_uInt16 nPrefix,
114 : const ::rtl::OUString& rLocalName,
115 : const uno::Reference< XAttributeList > & xAttrList )
116 : {
117 0 : SvXMLImportContext *pContext = 0;
118 0 : const SvXMLTokenMap& rTokenMap = GetOwnImport().GetQueryElemTokenMap();
119 :
120 0 : 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 0 : GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
132 0 : ::rtl::OUString s1,s2,s3;
133 0 : fillAttributes(nPrefix, rLocalName,xAttrList,m_sOrderStatement,s1,s2,s3);
134 : }
135 0 : break;
136 :
137 : case XML_TOK_COLUMNS:
138 : {
139 0 : GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
140 0 : uno::Reference< XColumnsSupplier > xColumnsSup(m_xTable,UNO_QUERY);
141 0 : uno::Reference< XNameAccess > xColumns;
142 0 : if ( xColumnsSup.is() )
143 : {
144 0 : xColumns = xColumnsSup->getColumns();
145 : }
146 0 : pContext = new OXMLHierarchyCollection( GetOwnImport(), nPrefix, rLocalName ,xColumns,m_xTable);
147 : }
148 0 : break;
149 : }
150 :
151 0 : if( !pContext )
152 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
153 :
154 0 : return pContext;
155 : }
156 : // -----------------------------------------------------------------------------
157 0 : ODBFilter& OXMLTable::GetOwnImport()
158 : {
159 0 : return static_cast<ODBFilter&>(GetImport());
160 : }
161 : // -----------------------------------------------------------------------------
162 0 : void OXMLTable::setProperties(uno::Reference< XPropertySet > & _xProp )
163 : {
164 : try
165 : {
166 0 : if ( _xProp.is() )
167 : {
168 0 : _xProp->setPropertyValue(PROPERTY_APPLYFILTER,makeAny(m_bApplyFilter));
169 0 : _xProp->setPropertyValue(PROPERTY_FILTER,makeAny(m_sFilterStatement));
170 :
171 0 : if ( _xProp->getPropertySetInfo()->hasPropertyByName(PROPERTY_APPLYORDER) )
172 0 : _xProp->setPropertyValue(PROPERTY_APPLYORDER,makeAny(m_bApplyOrder));
173 0 : _xProp->setPropertyValue(PROPERTY_ORDER,makeAny(m_sOrderStatement));
174 : }
175 : }
176 0 : catch(Exception&)
177 : {
178 : OSL_FAIL("OXMLTable::EndElement -> exception catched");
179 : }
180 0 : }
181 : // -----------------------------------------------------------------------------
182 0 : void OXMLTable::EndElement()
183 : {
184 0 : uno::Reference<XNameContainer> xNameContainer(m_xParentContainer,UNO_QUERY);
185 0 : if ( xNameContainer.is() )
186 : {
187 : try
188 : {
189 0 : if ( m_xTable.is() )
190 : {
191 0 : setProperties(m_xTable);
192 :
193 0 : 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 0 : xNameContainer->insertByName(m_sName,makeAny(m_xTable));
207 : }
208 : }
209 0 : catch(Exception&)
210 : {
211 : OSL_FAIL("OXMLQuery::EndElement -> exception catched");
212 : }
213 0 : }
214 :
215 0 : }
216 : // -----------------------------------------------------------------------------
217 0 : 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 0 : const SvXMLNamespaceMap& rMap = GetOwnImport().GetNamespaceMap();
228 0 : const SvXMLTokenMap& rTokenMap = GetOwnImport().GetQueryElemTokenMap();
229 :
230 0 : sal_Int16 nLength = (_xAttrList.is()) ? _xAttrList->getLength() : 0;
231 0 : for(sal_Int16 i = 0; i < nLength; ++i)
232 : {
233 0 : ::rtl::OUString sLocalName;
234 0 : rtl::OUString sAttrName = _xAttrList->getNameByIndex( i );
235 0 : sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName );
236 0 : rtl::OUString sValue = _xAttrList->getValueByIndex( i );
237 :
238 0 : switch( rTokenMap.Get( nPrefix, sLocalName ) )
239 : {
240 : case XML_TOK_COMMAND:
241 0 : _rsCommand = sValue;
242 0 : 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 0 : }
254 0 : }
255 : //----------------------------------------------------------------------------
256 : } // namespace dbaxml
257 : // -----------------------------------------------------------------------------
258 :
259 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|