Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / sc / source / filter / oox / connectionsbuffer.cxx
blob4433b69abe71505d3263ea62189a5604d72fc22a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <connectionsbuffer.hxx>
21 #include <biffhelper.hxx>
23 #include <osl/diagnose.h>
24 #include <oox/helper/attributelist.hxx>
25 #include <oox/token/namespaces.hxx>
26 #include <oox/token/tokens.hxx>
27 #include <oox/helper/binaryinputstream.hxx>
29 namespace oox {
30 namespace xls {
32 using namespace ::com::sun::star::uno;
34 namespace {
36 const sal_Int32 BIFF12_RECONNECT_AS_REQUIRED = 1;
38 const sal_uInt8 BIFF12_CONNECTION_SAVEPASSWORD_ON = 1;
40 const sal_uInt16 BIFF12_CONNECTION_KEEPALIVE = 0x0001;
41 const sal_uInt16 BIFF12_CONNECTION_NEW = 0x0002;
42 const sal_uInt16 BIFF12_CONNECTION_DELETED = 0x0004;
43 const sal_uInt16 BIFF12_CONNECTION_ONLYUSECONNFILE = 0x0008;
44 const sal_uInt16 BIFF12_CONNECTION_BACKGROUND = 0x0010;
45 const sal_uInt16 BIFF12_CONNECTION_REFRESHONLOAD = 0x0020;
46 const sal_uInt16 BIFF12_CONNECTION_SAVEDATA = 0x0040;
48 const sal_uInt16 BIFF12_CONNECTION_HAS_SOURCEFILE = 0x0001;
49 const sal_uInt16 BIFF12_CONNECTION_HAS_SOURCECONNFILE = 0x0002;
50 const sal_uInt16 BIFF12_CONNECTION_HAS_DESCRIPTION = 0x0004;
51 const sal_uInt16 BIFF12_CONNECTION_HAS_NAME = 0x0008;
52 const sal_uInt16 BIFF12_CONNECTION_HAS_SSOID = 0x0010;
54 const sal_uInt32 BIFF12_WEBPR_XML = 0x00000100;
55 const sal_uInt32 BIFF12_WEBPR_SOURCEDATA = 0x00000200;
56 const sal_uInt32 BIFF12_WEBPR_PARSEPRE = 0x00000400;
57 const sal_uInt32 BIFF12_WEBPR_CONSECUTIVE = 0x00000800;
58 const sal_uInt32 BIFF12_WEBPR_FIRSTROW = 0x00001000;
59 const sal_uInt32 BIFF12_WEBPR_XL97CREATED = 0x00002000;
60 const sal_uInt32 BIFF12_WEBPR_TEXTDATES = 0x00004000;
61 const sal_uInt32 BIFF12_WEBPR_XL2000REFRESHED = 0x00008000;
62 const sal_uInt32 BIFF12_WEBPR_HTMLTABLES = 0x00010000;
64 const sal_uInt8 BIFF12_WEBPR_HAS_POSTMETHOD = 0x01;
65 const sal_uInt8 BIFF12_WEBPR_HAS_EDITPAGE = 0x02;
66 const sal_uInt8 BIFF12_WEBPR_HAS_URL = 0x04;
68 } // namespace
70 WebPrModel::WebPrModel() :
71 mnHtmlFormat( XML_none ),
72 mbXml( false ),
73 mbSourceData( false ),
74 mbParsePre( false ),
75 mbConsecutive( false ),
76 mbFirstRow( false ),
77 mbXl97Created( false ),
78 mbTextDates( false ),
79 mbXl2000Refreshed( false ),
80 mbHtmlTables( false )
84 ConnectionModel::ConnectionModel() :
85 mnId( -1 ),
86 mnType( BIFF12_CONNECTION_UNKNOWN ),
87 mnReconnectMethod( BIFF12_RECONNECT_AS_REQUIRED ),
88 mnCredentials( XML_integrated ),
89 mnInterval( 0 ),
90 mbKeepAlive( false ),
91 mbNew( false ),
92 mbDeleted( false ),
93 mbOnlyUseConnFile( false ),
94 mbBackground( false ),
95 mbRefreshOnLoad( false ),
96 mbSaveData( false ),
97 mbSavePassword( false )
101 WebPrModel& ConnectionModel::createWebPr()
103 OSL_ENSURE( !mxWebPr.get(), "ConnectionModel::createWebPr - multiple call" );
104 mxWebPr.reset( new WebPrModel );
105 return *mxWebPr;
108 Connection::Connection( const WorkbookHelper& rHelper ) :
109 WorkbookHelper( rHelper )
111 maModel.mnId = -1;
114 void Connection::importConnection( const AttributeList& rAttribs )
116 maModel.maName = rAttribs.getXString( XML_name, OUString() );
117 maModel.maDescription = rAttribs.getXString( XML_description, OUString() );
118 maModel.maSourceFile = rAttribs.getXString( XML_sourceFile, OUString() );
119 maModel.maSourceConnFile = rAttribs.getXString( XML_odcFile, OUString() );
120 maModel.maSsoId = rAttribs.getXString( XML_singleSignOnId, OUString() );
121 maModel.mnId = rAttribs.getInteger( XML_id, -1 );
122 // type and reconnectionMethod are using the BIFF12 constants instead of XML tokens
123 maModel.mnType = rAttribs.getInteger( XML_type, BIFF12_CONNECTION_UNKNOWN );
124 maModel.mnReconnectMethod = rAttribs.getInteger( XML_reconnectionMethod, BIFF12_RECONNECT_AS_REQUIRED );
125 maModel.mnCredentials = rAttribs.getToken( XML_credentials, XML_integrated );
126 maModel.mnInterval = rAttribs.getInteger( XML_interval, 0 );
127 maModel.mbKeepAlive = rAttribs.getBool( XML_keepAlive, false );
128 maModel.mbNew = rAttribs.getBool( XML_new, false );
129 maModel.mbDeleted = rAttribs.getBool( XML_deleted, false );
130 maModel.mbOnlyUseConnFile = rAttribs.getBool( XML_onlyUseConnectionFile, false );
131 maModel.mbBackground = rAttribs.getBool( XML_background, false );
132 maModel.mbRefreshOnLoad = rAttribs.getBool( XML_refreshOnLoad, false );
133 maModel.mbSaveData = rAttribs.getBool( XML_saveData, false );
134 maModel.mbSavePassword = rAttribs.getBool( XML_savePassword, false );
137 void Connection::importWebPr( const AttributeList& rAttribs )
139 WebPrModel& rWebPr = maModel.createWebPr();
141 rWebPr.maUrl = rAttribs.getXString( XML_url, OUString() );
142 rWebPr.maPostMethod = rAttribs.getXString( XML_post, OUString() );
143 rWebPr.maEditPage = rAttribs.getXString( XML_editPage, OUString() );
144 rWebPr.mnHtmlFormat = rAttribs.getToken( XML_htmlFormat, XML_none );
145 rWebPr.mbXml = rAttribs.getBool( XML_xml, false );
146 rWebPr.mbSourceData = rAttribs.getBool( XML_sourceData, false );
147 rWebPr.mbParsePre = rAttribs.getBool( XML_parsePre, false );
148 rWebPr.mbConsecutive = rAttribs.getBool( XML_consecutive, false );
149 rWebPr.mbFirstRow = rAttribs.getBool( XML_firstRow, false );
150 rWebPr.mbXl97Created = rAttribs.getBool( XML_xl97, false );
151 rWebPr.mbTextDates = rAttribs.getBool( XML_textDates, false );
152 rWebPr.mbXl2000Refreshed = rAttribs.getBool( XML_xl2000, false );
153 rWebPr.mbHtmlTables = rAttribs.getBool( XML_htmlTables, false );
156 void Connection::importTables()
158 if( maModel.mxWebPr.get() )
160 OSL_ENSURE( maModel.mxWebPr->maTables.empty(), "Connection::importTables - multiple calls" );
161 maModel.mxWebPr->maTables.clear();
165 void Connection::importTable( const AttributeList& rAttribs, sal_Int32 nElement )
167 if( maModel.mxWebPr.get() )
169 Any aTableAny;
170 switch( nElement )
172 case XLS_TOKEN( m ): break;
173 case XLS_TOKEN( s ): aTableAny <<= rAttribs.getXString( XML_v, OUString() ); break;
174 case XLS_TOKEN( x ): aTableAny <<= rAttribs.getInteger( XML_v, -1 ); break;
175 default:
176 OSL_ENSURE( false, "Connection::importTable - unexpected element" );
177 return;
179 maModel.mxWebPr->maTables.push_back( aTableAny );
183 void Connection::importConnection( SequenceInputStream& rStrm )
185 sal_uInt16 nFlags, nStrFlags;
186 sal_uInt8 nSavePassword, nCredentials;
187 rStrm.skip( 2 );
188 nSavePassword = rStrm.readuChar();
189 rStrm.skip( 1 );
190 maModel.mnInterval = rStrm.readuInt16();
191 nFlags = rStrm.readuInt16();
192 nStrFlags = rStrm.readuInt16();
193 maModel.mnType = rStrm.readInt32();
194 maModel.mnReconnectMethod = rStrm.readInt32();
195 maModel.mnId = rStrm.readInt32();
196 nCredentials = rStrm.readuChar();
198 if( getFlag( nStrFlags, BIFF12_CONNECTION_HAS_SOURCEFILE ) )
199 rStrm >> maModel.maSourceFile;
200 if( getFlag( nStrFlags, BIFF12_CONNECTION_HAS_SOURCECONNFILE ) )
201 rStrm >> maModel.maSourceConnFile;
202 if( getFlag( nStrFlags, BIFF12_CONNECTION_HAS_DESCRIPTION ) )
203 rStrm >> maModel.maDescription;
204 if( getFlag( nStrFlags, BIFF12_CONNECTION_HAS_NAME ) )
205 rStrm >> maModel.maName;
206 if( getFlag( nStrFlags, BIFF12_CONNECTION_HAS_SSOID ) )
207 rStrm >> maModel.maSsoId;
209 static const sal_Int32 spnCredentials[] = { XML_integrated, XML_none, XML_stored, XML_prompt };
210 maModel.mnCredentials = STATIC_ARRAY_SELECT( spnCredentials, nCredentials, XML_integrated );
212 maModel.mbKeepAlive = getFlag( nFlags, BIFF12_CONNECTION_KEEPALIVE );
213 maModel.mbNew = getFlag( nFlags, BIFF12_CONNECTION_NEW );
214 maModel.mbDeleted = getFlag( nFlags, BIFF12_CONNECTION_DELETED );
215 maModel.mbOnlyUseConnFile = getFlag( nFlags, BIFF12_CONNECTION_ONLYUSECONNFILE );
216 maModel.mbBackground = getFlag( nFlags, BIFF12_CONNECTION_BACKGROUND );
217 maModel.mbRefreshOnLoad = getFlag( nFlags, BIFF12_CONNECTION_REFRESHONLOAD );
218 maModel.mbSaveData = getFlag( nFlags, BIFF12_CONNECTION_SAVEDATA );
219 maModel.mbSavePassword = nSavePassword == BIFF12_CONNECTION_SAVEPASSWORD_ON;
222 void Connection::importWebPr( SequenceInputStream& rStrm )
224 WebPrModel& rWebPr = maModel.createWebPr();
226 sal_uInt32 nFlags;
227 sal_uInt8 nStrFlags;
228 nFlags = rStrm.readuInt32();
229 nStrFlags = rStrm.readuChar();
231 if( getFlag( nStrFlags, BIFF12_WEBPR_HAS_URL ) )
232 rStrm >> rWebPr.maUrl;
233 if( getFlag( nStrFlags, BIFF12_WEBPR_HAS_POSTMETHOD ) )
234 rStrm >> rWebPr.maPostMethod;
235 if( getFlag( nStrFlags, BIFF12_WEBPR_HAS_EDITPAGE ) )
236 rStrm >> rWebPr.maEditPage;
238 static const sal_Int32 spnHmlFormats[] = { XML_none, XML_rtf, XML_all };
239 rWebPr.mnHtmlFormat = STATIC_ARRAY_SELECT( spnHmlFormats, extractValue< sal_uInt8 >( nFlags, 0, 8 ), XML_none );
241 rWebPr.mbXml = getFlag( nFlags, BIFF12_WEBPR_XML );
242 rWebPr.mbSourceData = getFlag( nFlags, BIFF12_WEBPR_SOURCEDATA );
243 rWebPr.mbParsePre = getFlag( nFlags, BIFF12_WEBPR_PARSEPRE );
244 rWebPr.mbConsecutive = getFlag( nFlags, BIFF12_WEBPR_CONSECUTIVE );
245 rWebPr.mbFirstRow = getFlag( nFlags, BIFF12_WEBPR_FIRSTROW );
246 rWebPr.mbXl97Created = getFlag( nFlags, BIFF12_WEBPR_XL97CREATED );
247 rWebPr.mbTextDates = getFlag( nFlags, BIFF12_WEBPR_TEXTDATES );
248 rWebPr.mbXl2000Refreshed = getFlag( nFlags, BIFF12_WEBPR_XL2000REFRESHED );
249 rWebPr.mbHtmlTables = getFlag( nFlags, BIFF12_WEBPR_HTMLTABLES );
252 void Connection::importWebPrTables( SequenceInputStream& /*rStrm*/ )
254 if( maModel.mxWebPr.get() )
256 OSL_ENSURE( maModel.mxWebPr->maTables.empty(), "Connection::importWebPrTables - multiple calls" );
257 maModel.mxWebPr->maTables.clear();
261 void Connection::importWebPrTable( SequenceInputStream& rStrm, sal_Int32 nRecId )
263 if( maModel.mxWebPr.get() )
265 Any aTableAny;
266 switch( nRecId )
268 case BIFF12_ID_PCITEM_MISSING: break;
269 case BIFF12_ID_PCITEM_STRING: aTableAny <<= BiffHelper::readString( rStrm ); break;
270 case BIFF12_ID_PCITEM_INDEX: aTableAny <<= rStrm.readInt32(); break;
271 default:
272 OSL_ENSURE( false, "Connection::importWebPrTable - unexpected record" );
273 return;
275 maModel.mxWebPr->maTables.push_back( aTableAny );
279 ConnectionsBuffer::ConnectionsBuffer( const WorkbookHelper& rHelper ) :
280 WorkbookHelper( rHelper ),
281 mnUnusedId( 1 )
285 Connection& ConnectionsBuffer::createConnection()
287 ConnectionRef xConnection( new Connection( *this ) );
288 maConnections.push_back( xConnection );
289 return *xConnection;
292 void ConnectionsBuffer::finalizeImport()
294 for( const auto& rxConnection : maConnections )
295 insertConnectionToMap( rxConnection );
298 ConnectionRef ConnectionsBuffer::getConnection( sal_Int32 nConnId ) const
300 return maConnectionsById.get( nConnId );
303 void ConnectionsBuffer::insertConnectionToMap( const ConnectionRef& rxConnection )
305 sal_Int32 nConnId = rxConnection->getConnectionId();
306 if( nConnId > 0 )
308 OSL_ENSURE( !maConnectionsById.has( nConnId ), "ConnectionsBuffer::insertConnectionToMap - multiple connection identifier" );
309 maConnectionsById[ nConnId ] = rxConnection;
310 mnUnusedId = ::std::max< sal_Int32 >( mnUnusedId, nConnId + 1 );
314 } // namespace xls
315 } // namespace oox
317 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */