Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "connectionsbuffer.hxx"
30 : :
31 : : #include "oox/helper/attributelist.hxx"
32 : : #include "biffinputstream.hxx"
33 : :
34 : : namespace oox {
35 : : namespace xls {
36 : :
37 : : // ============================================================================
38 : :
39 : : using namespace ::com::sun::star::uno;
40 : :
41 : : using ::rtl::OUString;
42 : : using ::rtl::OUStringBuffer;
43 : :
44 : : // ============================================================================
45 : :
46 : : namespace {
47 : :
48 : : const sal_Int32 BIFF12_RECONNECT_AS_REQUIRED = 1;
49 : : const sal_Int32 BIFF12_RECONNECT_ALWAYS = 2;
50 : : const sal_Int32 BIFF12_RECONNECT_NEVER = 3;
51 : :
52 : : const sal_uInt8 BIFF12_CONNECTION_SAVEPASSWORD_ON = 1;
53 : : const sal_uInt8 BIFF12_CONNECTION_SAVEPASSWORD_OFF = 2;
54 : :
55 : : const sal_uInt16 BIFF12_CONNECTION_KEEPALIVE = 0x0001;
56 : : const sal_uInt16 BIFF12_CONNECTION_NEW = 0x0002;
57 : : const sal_uInt16 BIFF12_CONNECTION_DELETED = 0x0004;
58 : : const sal_uInt16 BIFF12_CONNECTION_ONLYUSECONNFILE = 0x0008;
59 : : const sal_uInt16 BIFF12_CONNECTION_BACKGROUND = 0x0010;
60 : : const sal_uInt16 BIFF12_CONNECTION_REFRESHONLOAD = 0x0020;
61 : : const sal_uInt16 BIFF12_CONNECTION_SAVEDATA = 0x0040;
62 : :
63 : : const sal_uInt16 BIFF12_CONNECTION_HAS_SOURCEFILE = 0x0001;
64 : : const sal_uInt16 BIFF12_CONNECTION_HAS_SOURCECONNFILE = 0x0002;
65 : : const sal_uInt16 BIFF12_CONNECTION_HAS_DESCRIPTION = 0x0004;
66 : : const sal_uInt16 BIFF12_CONNECTION_HAS_NAME = 0x0008;
67 : : const sal_uInt16 BIFF12_CONNECTION_HAS_SSOID = 0x0010;
68 : :
69 : : const sal_uInt32 BIFF12_WEBPR_XML = 0x00000100;
70 : : const sal_uInt32 BIFF12_WEBPR_SOURCEDATA = 0x00000200;
71 : : const sal_uInt32 BIFF12_WEBPR_PARSEPRE = 0x00000400;
72 : : const sal_uInt32 BIFF12_WEBPR_CONSECUTIVE = 0x00000800;
73 : : const sal_uInt32 BIFF12_WEBPR_FIRSTROW = 0x00001000;
74 : : const sal_uInt32 BIFF12_WEBPR_XL97CREATED = 0x00002000;
75 : : const sal_uInt32 BIFF12_WEBPR_TEXTDATES = 0x00004000;
76 : : const sal_uInt32 BIFF12_WEBPR_XL2000REFRESHED = 0x00008000;
77 : : const sal_uInt32 BIFF12_WEBPR_HTMLTABLES = 0x00010000;
78 : :
79 : : const sal_uInt8 BIFF12_WEBPR_HAS_POSTMETHOD = 0x01;
80 : : const sal_uInt8 BIFF12_WEBPR_HAS_EDITPAGE = 0x02;
81 : : const sal_uInt8 BIFF12_WEBPR_HAS_URL = 0x04;
82 : :
83 : : const sal_uInt16 BIFF_DBQUERY_ODBC = 0x0008;
84 : : const sal_uInt16 BIFF_DBQUERY_SQLQUERY = 0x0010;
85 : : const sal_uInt16 BIFF_DBQUERY_SERVERBASEDSQL = 0x0020;
86 : : const sal_uInt16 BIFF_DBQUERY_HTML = 0x0040;
87 : : const sal_uInt16 BIFF_DBQUERY_SAVEPASSWORD = 0x0080;
88 : : const sal_uInt16 BIFF_DBQUERY_HTMLTABLES = 0x0100;
89 : :
90 : : const sal_uInt16 BIFF_QTSETTINGS_KEEPALIVE = 0x0001;
91 : : const sal_uInt16 BIFF_QTSETTINGS_NEW = 0x0002;
92 : : const sal_uInt16 BIFF_QTSETTINGS_SOURCEDATA = 0x0004;
93 : : const sal_uInt16 BIFF_QTSETTINGS_WEBBASEDPROV = 0x0008;
94 : : const sal_uInt16 BIFF_QTSETTINGS_REINITLIST = 0x0010;
95 : : const sal_uInt16 BIFF_QTSETTINGS_XML = 0x0080;
96 : :
97 : : const sal_uInt16 BIFF_QTSETTINGS_PARSEPRE = 0x0001;
98 : : const sal_uInt16 BIFF_QTSETTINGS_CONSECUTIVE = 0x0002;
99 : : const sal_uInt16 BIFF_QTSETTINGS_FIRSTROW = 0x0004;
100 : : const sal_uInt16 BIFF_QTSETTINGS_XL97CREATED = 0x0008;
101 : : const sal_uInt16 BIFF_QTSETTINGS_TEXTDATES = 0x0010;
102 : : const sal_uInt16 BIFF_QTSETTINGS_XL2000REFRESHED = 0x0020;
103 : :
104 : : const sal_uInt16 BIFF_QTSETTINGS_TEXTQUERY = 0x0001;
105 : : const sal_uInt16 BIFF_QTSETTINGS_TABLENAMES = 0x0002;
106 : :
107 : : } // namespace
108 : :
109 : : // ============================================================================
110 : :
111 : 0 : WebPrModel::WebPrModel() :
112 : : mnHtmlFormat( XML_none ),
113 : : mbXml( false ),
114 : : mbSourceData( false ),
115 : : mbParsePre( false ),
116 : : mbConsecutive( false ),
117 : : mbFirstRow( false ),
118 : : mbXl97Created( false ),
119 : : mbTextDates( false ),
120 : : mbXl2000Refreshed( false ),
121 : 0 : mbHtmlTables( false )
122 : : {
123 : 0 : }
124 : :
125 : : // ----------------------------------------------------------------------------
126 : :
127 : 0 : ConnectionModel::ConnectionModel() :
128 : : mnId( -1 ),
129 : : mnType( BIFF12_CONNECTION_UNKNOWN ),
130 : : mnReconnectMethod( BIFF12_RECONNECT_AS_REQUIRED ),
131 : : mnCredentials( XML_integrated ),
132 : : mnInterval( 0 ),
133 : : mbKeepAlive( false ),
134 : : mbNew( false ),
135 : : mbDeleted( false ),
136 : : mbOnlyUseConnFile( false ),
137 : : mbBackground( false ),
138 : : mbRefreshOnLoad( false ),
139 : : mbSaveData( false ),
140 : 0 : mbSavePassword( false )
141 : : {
142 : 0 : }
143 : :
144 : 0 : WebPrModel& ConnectionModel::createWebPr()
145 : : {
146 : : OSL_ENSURE( !mxWebPr.get(), "ConnectionModel::createWebPr - multiple call" );
147 [ # # ]: 0 : mxWebPr.reset( new WebPrModel );
148 : 0 : return *mxWebPr;
149 : : }
150 : :
151 : : // ----------------------------------------------------------------------------
152 : :
153 : 0 : Connection::Connection( const WorkbookHelper& rHelper, sal_Int32 nConnId ) :
154 [ # # ]: 0 : WorkbookHelper( rHelper )
155 : : {
156 : 0 : maModel.mnId = nConnId;
157 : 0 : }
158 : :
159 : 0 : void Connection::importConnection( const AttributeList& rAttribs )
160 : : {
161 [ # # ]: 0 : maModel.maName = rAttribs.getXString( XML_name, OUString() );
162 [ # # ]: 0 : maModel.maDescription = rAttribs.getXString( XML_description, OUString() );
163 [ # # ]: 0 : maModel.maSourceFile = rAttribs.getXString( XML_sourceFile, OUString() );
164 [ # # ]: 0 : maModel.maSourceConnFile = rAttribs.getXString( XML_odcFile, OUString() );
165 [ # # ]: 0 : maModel.maSsoId = rAttribs.getXString( XML_singleSignOnId, OUString() );
166 : 0 : maModel.mnId = rAttribs.getInteger( XML_id, -1 );
167 : : // type and reconnectionMethod are using the BIFF12 constants instead of XML tokens
168 : 0 : maModel.mnType = rAttribs.getInteger( XML_type, BIFF12_CONNECTION_UNKNOWN );
169 : 0 : maModel.mnReconnectMethod = rAttribs.getInteger( XML_reconnectionMethod, BIFF12_RECONNECT_AS_REQUIRED );
170 : 0 : maModel.mnCredentials = rAttribs.getToken( XML_credentials, XML_integrated );
171 : 0 : maModel.mnInterval = rAttribs.getInteger( XML_interval, 0 );
172 : 0 : maModel.mbKeepAlive = rAttribs.getBool( XML_keepAlive, false );
173 : 0 : maModel.mbNew = rAttribs.getBool( XML_new, false );
174 : 0 : maModel.mbDeleted = rAttribs.getBool( XML_deleted, false );
175 : 0 : maModel.mbOnlyUseConnFile = rAttribs.getBool( XML_onlyUseConnectionFile, false );
176 : 0 : maModel.mbBackground = rAttribs.getBool( XML_background, false );
177 : 0 : maModel.mbRefreshOnLoad = rAttribs.getBool( XML_refreshOnLoad, false );
178 : 0 : maModel.mbSaveData = rAttribs.getBool( XML_saveData, false );
179 : 0 : maModel.mbSavePassword = rAttribs.getBool( XML_savePassword, false );
180 : 0 : }
181 : :
182 : 0 : void Connection::importWebPr( const AttributeList& rAttribs )
183 : : {
184 : 0 : WebPrModel& rWebPr = maModel.createWebPr();
185 : :
186 [ # # ]: 0 : rWebPr.maUrl = rAttribs.getXString( XML_url, OUString() );
187 [ # # ]: 0 : rWebPr.maPostMethod = rAttribs.getXString( XML_post, OUString() );
188 [ # # ]: 0 : rWebPr.maEditPage = rAttribs.getXString( XML_editPage, OUString() );
189 : 0 : rWebPr.mnHtmlFormat = rAttribs.getToken( XML_htmlFormat, XML_none );
190 : 0 : rWebPr.mbXml = rAttribs.getBool( XML_xml, false );
191 : 0 : rWebPr.mbSourceData = rAttribs.getBool( XML_sourceData, false );
192 : 0 : rWebPr.mbParsePre = rAttribs.getBool( XML_parsePre, false );
193 : 0 : rWebPr.mbConsecutive = rAttribs.getBool( XML_consecutive, false );
194 : 0 : rWebPr.mbFirstRow = rAttribs.getBool( XML_firstRow, false );
195 : 0 : rWebPr.mbXl97Created = rAttribs.getBool( XML_xl97, false );
196 : 0 : rWebPr.mbTextDates = rAttribs.getBool( XML_textDates, false );
197 : 0 : rWebPr.mbXl2000Refreshed = rAttribs.getBool( XML_xl2000, false );
198 : 0 : rWebPr.mbHtmlTables = rAttribs.getBool( XML_htmlTables, false );
199 : 0 : }
200 : :
201 : 0 : void Connection::importTables( const AttributeList& /*rAttribs*/ )
202 : : {
203 [ # # ]: 0 : if( maModel.mxWebPr.get() )
204 : : {
205 : : OSL_ENSURE( maModel.mxWebPr->maTables.empty(), "Connection::importTables - multiple calls" );
206 : 0 : maModel.mxWebPr->maTables.clear();
207 : : }
208 : 0 : }
209 : :
210 : 0 : void Connection::importTable( const AttributeList& rAttribs, sal_Int32 nElement )
211 : : {
212 [ # # ]: 0 : if( maModel.mxWebPr.get() )
213 : : {
214 : 0 : Any aTableAny;
215 [ # # # # ]: 0 : switch( nElement )
216 : : {
217 : 0 : case XLS_TOKEN( m ): break;
218 [ # # ][ # # ]: 0 : case XLS_TOKEN( s ): aTableAny <<= rAttribs.getXString( XML_v, OUString() ); break;
219 [ # # ][ # # ]: 0 : case XLS_TOKEN( x ): aTableAny <<= rAttribs.getInteger( XML_v, -1 ); break;
220 : : default:
221 : : OSL_ENSURE( false, "Connection::importTable - unexpected element" );
222 : 0 : return;
223 : : }
224 [ # # ][ # # ]: 0 : maModel.mxWebPr->maTables.push_back( aTableAny );
225 : : }
226 : : }
227 : :
228 : 0 : void Connection::importConnection( SequenceInputStream& rStrm )
229 : : {
230 : : sal_uInt16 nFlags, nStrFlags;
231 : : sal_uInt8 nSavePassword, nCredentials;
232 [ # # ]: 0 : rStrm.skip( 2 );
233 [ # # ]: 0 : rStrm >> nSavePassword;
234 [ # # ]: 0 : rStrm.skip( 1 );
235 [ # # ]: 0 : maModel.mnInterval = rStrm.readuInt16();
236 [ # # ][ # # ]: 0 : rStrm >> nFlags >> nStrFlags >> maModel.mnType >> maModel.mnReconnectMethod >> maModel.mnId >> nCredentials;
[ # # ][ # # ]
[ # # ][ # # ]
237 : :
238 [ # # ]: 0 : if( getFlag( nStrFlags, BIFF12_CONNECTION_HAS_SOURCEFILE ) )
239 [ # # ]: 0 : rStrm >> maModel.maSourceFile;
240 [ # # ]: 0 : if( getFlag( nStrFlags, BIFF12_CONNECTION_HAS_SOURCECONNFILE ) )
241 [ # # ]: 0 : rStrm >> maModel.maSourceConnFile;
242 [ # # ]: 0 : if( getFlag( nStrFlags, BIFF12_CONNECTION_HAS_DESCRIPTION ) )
243 [ # # ]: 0 : rStrm >> maModel.maDescription;
244 [ # # ]: 0 : if( getFlag( nStrFlags, BIFF12_CONNECTION_HAS_NAME ) )
245 [ # # ]: 0 : rStrm >> maModel.maName;
246 [ # # ]: 0 : if( getFlag( nStrFlags, BIFF12_CONNECTION_HAS_SSOID ) )
247 [ # # ]: 0 : rStrm >> maModel.maSsoId;
248 : :
249 : : static const sal_Int32 spnCredentials[] = { XML_integrated, XML_none, XML_stored, XML_prompt };
250 [ # # ]: 0 : maModel.mnCredentials = STATIC_ARRAY_SELECT( spnCredentials, nCredentials, XML_integrated );
251 : :
252 : 0 : maModel.mbKeepAlive = getFlag( nFlags, BIFF12_CONNECTION_KEEPALIVE );
253 : 0 : maModel.mbNew = getFlag( nFlags, BIFF12_CONNECTION_NEW );
254 : 0 : maModel.mbDeleted = getFlag( nFlags, BIFF12_CONNECTION_DELETED );
255 : 0 : maModel.mbOnlyUseConnFile = getFlag( nFlags, BIFF12_CONNECTION_ONLYUSECONNFILE );
256 : 0 : maModel.mbBackground = getFlag( nFlags, BIFF12_CONNECTION_BACKGROUND );
257 : 0 : maModel.mbRefreshOnLoad = getFlag( nFlags, BIFF12_CONNECTION_REFRESHONLOAD );
258 : 0 : maModel.mbSaveData = getFlag( nFlags, BIFF12_CONNECTION_SAVEDATA );
259 : 0 : maModel.mbSavePassword = nSavePassword == BIFF12_CONNECTION_SAVEPASSWORD_ON;
260 : 0 : }
261 : :
262 : 0 : void Connection::importWebPr( SequenceInputStream& rStrm )
263 : : {
264 [ # # ]: 0 : WebPrModel& rWebPr = maModel.createWebPr();
265 : :
266 : : sal_uInt32 nFlags;
267 : : sal_uInt8 nStrFlags;
268 [ # # ][ # # ]: 0 : rStrm >> nFlags >> nStrFlags;
269 : :
270 [ # # ]: 0 : if( getFlag( nStrFlags, BIFF12_WEBPR_HAS_URL ) )
271 [ # # ]: 0 : rStrm >> rWebPr.maUrl;
272 [ # # ]: 0 : if( getFlag( nStrFlags, BIFF12_WEBPR_HAS_POSTMETHOD ) )
273 [ # # ]: 0 : rStrm >> rWebPr.maPostMethod;
274 [ # # ]: 0 : if( getFlag( nStrFlags, BIFF12_WEBPR_HAS_EDITPAGE ) )
275 [ # # ]: 0 : rStrm >> rWebPr.maEditPage;
276 : :
277 : : static const sal_Int32 spnHmlFormats[] = { XML_none, XML_rtf, XML_all };
278 [ # # ]: 0 : rWebPr.mnHtmlFormat = STATIC_ARRAY_SELECT( spnHmlFormats, extractValue< sal_uInt8 >( nFlags, 0, 8 ), XML_none );
279 : :
280 : 0 : rWebPr.mbXml = getFlag( nFlags, BIFF12_WEBPR_XML );
281 : 0 : rWebPr.mbSourceData = getFlag( nFlags, BIFF12_WEBPR_SOURCEDATA );
282 : 0 : rWebPr.mbParsePre = getFlag( nFlags, BIFF12_WEBPR_PARSEPRE );
283 : 0 : rWebPr.mbConsecutive = getFlag( nFlags, BIFF12_WEBPR_CONSECUTIVE );
284 : 0 : rWebPr.mbFirstRow = getFlag( nFlags, BIFF12_WEBPR_FIRSTROW );
285 : 0 : rWebPr.mbXl97Created = getFlag( nFlags, BIFF12_WEBPR_XL97CREATED );
286 : 0 : rWebPr.mbTextDates = getFlag( nFlags, BIFF12_WEBPR_TEXTDATES );
287 : 0 : rWebPr.mbXl2000Refreshed = getFlag( nFlags, BIFF12_WEBPR_XL2000REFRESHED );
288 : 0 : rWebPr.mbHtmlTables = getFlag( nFlags, BIFF12_WEBPR_HTMLTABLES );
289 : 0 : }
290 : :
291 : 0 : void Connection::importWebPrTables( SequenceInputStream& /*rStrm*/ )
292 : : {
293 [ # # ]: 0 : if( maModel.mxWebPr.get() )
294 : : {
295 : : OSL_ENSURE( maModel.mxWebPr->maTables.empty(), "Connection::importWebPrTables - multiple calls" );
296 : 0 : maModel.mxWebPr->maTables.clear();
297 : : }
298 : 0 : }
299 : :
300 : 0 : void Connection::importWebPrTable( SequenceInputStream& rStrm, sal_Int32 nRecId )
301 : : {
302 [ # # ]: 0 : if( maModel.mxWebPr.get() )
303 : : {
304 : 0 : Any aTableAny;
305 [ # # # # ]: 0 : switch( nRecId )
306 : : {
307 : 0 : case BIFF12_ID_PCITEM_MISSING: break;
308 [ # # ][ # # ]: 0 : case BIFF12_ID_PCITEM_STRING: aTableAny <<= BiffHelper::readString( rStrm ); break;
309 [ # # ][ # # ]: 0 : case BIFF12_ID_PCITEM_INDEX: aTableAny <<= rStrm.readInt32(); break;
310 : : default:
311 : : OSL_ENSURE( false, "Connection::importWebPrTable - unexpected record" );
312 : 0 : return;
313 : : }
314 [ # # ][ # # ]: 0 : maModel.mxWebPr->maTables.push_back( aTableAny );
315 : : }
316 : : }
317 : :
318 : : // ============================================================================
319 : :
320 : 24 : ConnectionsBuffer::ConnectionsBuffer( const WorkbookHelper& rHelper ) :
321 : : WorkbookHelper( rHelper ),
322 [ + - ][ + - ]: 24 : mnUnusedId( 1 )
323 : : {
324 : 24 : }
325 : :
326 : 0 : Connection& ConnectionsBuffer::createConnection()
327 : : {
328 [ # # ][ # # ]: 0 : ConnectionRef xConnection( new Connection( *this ) );
[ # # ]
329 [ # # ]: 0 : maConnections.push_back( xConnection );
330 [ # # ]: 0 : return *xConnection;
331 : : }
332 : :
333 : 0 : void ConnectionsBuffer::finalizeImport()
334 : : {
335 [ # # ][ # # ]: 0 : for( ConnectionVector::iterator aIt = maConnections.begin(), aEnd = maConnections.end(); aIt != aEnd; ++aIt )
336 [ # # ]: 0 : insertConnectionToMap( *aIt );
337 : 0 : }
338 : :
339 : 0 : ConnectionRef ConnectionsBuffer::getConnection( sal_Int32 nConnId ) const
340 : : {
341 : 0 : return maConnectionsById.get( nConnId );
342 : : }
343 : :
344 : 0 : void ConnectionsBuffer::insertConnectionToMap( const ConnectionRef& rxConnection )
345 : : {
346 : 0 : sal_Int32 nConnId = rxConnection->getConnectionId();
347 [ # # ]: 0 : if( nConnId > 0 )
348 : : {
349 : : OSL_ENSURE( !maConnectionsById.has( nConnId ), "ConnectionsBuffer::insertConnectionToMap - multiple connection identifier" );
350 [ # # ][ # # ]: 0 : maConnectionsById[ nConnId ] = rxConnection;
351 [ # # ]: 0 : mnUnusedId = ::std::max< sal_Int32 >( mnUnusedId, nConnId + 1 );
352 : : }
353 : 0 : }
354 : :
355 : : // ============================================================================
356 : :
357 : : } // namespace xls
358 [ + - ][ + - ]: 24 : } // namespace oox
359 : :
360 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|