1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #include "oox/xls/connectionsbuffer.hxx"
29*cdf0e10cSrcweir 
30*cdf0e10cSrcweir #include "oox/helper/attributelist.hxx"
31*cdf0e10cSrcweir #include "oox/xls/biffinputstream.hxx"
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir namespace oox {
34*cdf0e10cSrcweir namespace xls {
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir // ============================================================================
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir using ::rtl::OUString;
41*cdf0e10cSrcweir using ::rtl::OUStringBuffer;
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir // ============================================================================
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir namespace {
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir const sal_Int32 BIFF12_RECONNECT_AS_REQUIRED            = 1;
48*cdf0e10cSrcweir const sal_Int32 BIFF12_RECONNECT_ALWAYS                 = 2;
49*cdf0e10cSrcweir const sal_Int32 BIFF12_RECONNECT_NEVER                  = 3;
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir const sal_uInt8 BIFF12_CONNECTION_SAVEPASSWORD_ON       = 1;
52*cdf0e10cSrcweir const sal_uInt8 BIFF12_CONNECTION_SAVEPASSWORD_OFF      = 2;
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir const sal_uInt16 BIFF12_CONNECTION_KEEPALIVE            = 0x0001;
55*cdf0e10cSrcweir const sal_uInt16 BIFF12_CONNECTION_NEW                  = 0x0002;
56*cdf0e10cSrcweir const sal_uInt16 BIFF12_CONNECTION_DELETED              = 0x0004;
57*cdf0e10cSrcweir const sal_uInt16 BIFF12_CONNECTION_ONLYUSECONNFILE      = 0x0008;
58*cdf0e10cSrcweir const sal_uInt16 BIFF12_CONNECTION_BACKGROUND           = 0x0010;
59*cdf0e10cSrcweir const sal_uInt16 BIFF12_CONNECTION_REFRESHONLOAD        = 0x0020;
60*cdf0e10cSrcweir const sal_uInt16 BIFF12_CONNECTION_SAVEDATA             = 0x0040;
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir const sal_uInt16 BIFF12_CONNECTION_HAS_SOURCEFILE       = 0x0001;
63*cdf0e10cSrcweir const sal_uInt16 BIFF12_CONNECTION_HAS_SOURCECONNFILE   = 0x0002;
64*cdf0e10cSrcweir const sal_uInt16 BIFF12_CONNECTION_HAS_DESCRIPTION      = 0x0004;
65*cdf0e10cSrcweir const sal_uInt16 BIFF12_CONNECTION_HAS_NAME             = 0x0008;
66*cdf0e10cSrcweir const sal_uInt16 BIFF12_CONNECTION_HAS_SSOID            = 0x0010;
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir const sal_uInt32 BIFF12_WEBPR_XML                       = 0x00000100;
69*cdf0e10cSrcweir const sal_uInt32 BIFF12_WEBPR_SOURCEDATA                = 0x00000200;
70*cdf0e10cSrcweir const sal_uInt32 BIFF12_WEBPR_PARSEPRE                  = 0x00000400;
71*cdf0e10cSrcweir const sal_uInt32 BIFF12_WEBPR_CONSECUTIVE               = 0x00000800;
72*cdf0e10cSrcweir const sal_uInt32 BIFF12_WEBPR_FIRSTROW                  = 0x00001000;
73*cdf0e10cSrcweir const sal_uInt32 BIFF12_WEBPR_XL97CREATED               = 0x00002000;
74*cdf0e10cSrcweir const sal_uInt32 BIFF12_WEBPR_TEXTDATES                 = 0x00004000;
75*cdf0e10cSrcweir const sal_uInt32 BIFF12_WEBPR_XL2000REFRESHED           = 0x00008000;
76*cdf0e10cSrcweir const sal_uInt32 BIFF12_WEBPR_HTMLTABLES                = 0x00010000;
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir const sal_uInt8 BIFF12_WEBPR_HAS_POSTMETHOD             = 0x01;
79*cdf0e10cSrcweir const sal_uInt8 BIFF12_WEBPR_HAS_EDITPAGE               = 0x02;
80*cdf0e10cSrcweir const sal_uInt8 BIFF12_WEBPR_HAS_URL                    = 0x04;
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir const sal_uInt16 BIFF_DBQUERY_ODBC                      = 0x0008;
83*cdf0e10cSrcweir const sal_uInt16 BIFF_DBQUERY_SQLQUERY                  = 0x0010;
84*cdf0e10cSrcweir const sal_uInt16 BIFF_DBQUERY_SERVERBASEDSQL            = 0x0020;
85*cdf0e10cSrcweir const sal_uInt16 BIFF_DBQUERY_HTML                      = 0x0040;
86*cdf0e10cSrcweir const sal_uInt16 BIFF_DBQUERY_SAVEPASSWORD              = 0x0080;
87*cdf0e10cSrcweir const sal_uInt16 BIFF_DBQUERY_HTMLTABLES                = 0x0100;
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir const sal_uInt16 BIFF_QTSETTINGS_KEEPALIVE              = 0x0001;
90*cdf0e10cSrcweir const sal_uInt16 BIFF_QTSETTINGS_NEW                    = 0x0002;
91*cdf0e10cSrcweir const sal_uInt16 BIFF_QTSETTINGS_SOURCEDATA             = 0x0004;
92*cdf0e10cSrcweir const sal_uInt16 BIFF_QTSETTINGS_WEBBASEDPROV           = 0x0008;
93*cdf0e10cSrcweir const sal_uInt16 BIFF_QTSETTINGS_REINITLIST             = 0x0010;
94*cdf0e10cSrcweir const sal_uInt16 BIFF_QTSETTINGS_XML                    = 0x0080;
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir const sal_uInt16 BIFF_QTSETTINGS_PARSEPRE               = 0x0001;
97*cdf0e10cSrcweir const sal_uInt16 BIFF_QTSETTINGS_CONSECUTIVE            = 0x0002;
98*cdf0e10cSrcweir const sal_uInt16 BIFF_QTSETTINGS_FIRSTROW               = 0x0004;
99*cdf0e10cSrcweir const sal_uInt16 BIFF_QTSETTINGS_XL97CREATED            = 0x0008;
100*cdf0e10cSrcweir const sal_uInt16 BIFF_QTSETTINGS_TEXTDATES              = 0x0010;
101*cdf0e10cSrcweir const sal_uInt16 BIFF_QTSETTINGS_XL2000REFRESHED        = 0x0020;
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir const sal_uInt16 BIFF_QTSETTINGS_TEXTQUERY              = 0x0001;
104*cdf0e10cSrcweir const sal_uInt16 BIFF_QTSETTINGS_TABLENAMES             = 0x0002;
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir // ----------------------------------------------------------------------------
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir OUString lclReadQueryString( BiffInputStream& rStrm, sal_uInt16 nCount )
109*cdf0e10cSrcweir {
110*cdf0e10cSrcweir     bool bValidRec = true;
111*cdf0e10cSrcweir     OUStringBuffer aBuffer;
112*cdf0e10cSrcweir     for( sal_uInt16 nIndex = 0; bValidRec && (nIndex < nCount); ++nIndex )
113*cdf0e10cSrcweir     {
114*cdf0e10cSrcweir         bValidRec = (rStrm.getNextRecId() == BIFF_ID_PCITEM_STRING) && rStrm.startNextRecord();
115*cdf0e10cSrcweir         if( bValidRec )
116*cdf0e10cSrcweir             aBuffer.append( rStrm.readUniString() );
117*cdf0e10cSrcweir     }
118*cdf0e10cSrcweir     OSL_ENSURE( bValidRec, "lclReadQueryString - missing PCITEM_STRING records" );
119*cdf0e10cSrcweir     return aBuffer.makeStringAndClear();
120*cdf0e10cSrcweir }
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir void lclParseTables( WebPrModel::TablesVector& rTables, const OUString& rTableNames )
123*cdf0e10cSrcweir {
124*cdf0e10cSrcweir     rTables.clear();
125*cdf0e10cSrcweir     OUString aTableNames = rTableNames.trim();
126*cdf0e10cSrcweir     while( aTableNames.getLength() > 0 )
127*cdf0e10cSrcweir     {
128*cdf0e10cSrcweir         sal_Int32 nSep = -1;
129*cdf0e10cSrcweir         // table names are enclosed in double quotes
130*cdf0e10cSrcweir         if( aTableNames[ 0 ] == '"' )
131*cdf0e10cSrcweir         {
132*cdf0e10cSrcweir             // search closing quote character
133*cdf0e10cSrcweir             sal_Int32 nEndQuote = aTableNames.indexOf( '"', 1 );
134*cdf0e10cSrcweir             OSL_ENSURE( nEndQuote >= 1, "lclParseTables - invalid syntax" );
135*cdf0e10cSrcweir             if( nEndQuote < 0 )
136*cdf0e10cSrcweir                 nEndQuote = aTableNames.getLength();
137*cdf0e10cSrcweir             else
138*cdf0e10cSrcweir                 nSep = aTableNames.indexOf( ',', nEndQuote + 1 );
139*cdf0e10cSrcweir             // extract text between quote characters
140*cdf0e10cSrcweir             OUString aTableName = aTableNames.copy( 1, nEndQuote - 1 ).trim();
141*cdf0e10cSrcweir             if( aTableName.getLength() > 0 )
142*cdf0e10cSrcweir                 rTables.push_back( Any( aTableName ) );
143*cdf0e10cSrcweir             else
144*cdf0e10cSrcweir                 rTables.push_back( Any() );
145*cdf0e10cSrcweir         }
146*cdf0e10cSrcweir         else
147*cdf0e10cSrcweir         {
148*cdf0e10cSrcweir             nSep = aTableNames.indexOf( ',' );
149*cdf0e10cSrcweir             if( nSep < 0 )
150*cdf0e10cSrcweir                 nSep = aTableNames.getLength();
151*cdf0e10cSrcweir             OUString aTableIndex = aTableNames.copy( 0, nSep ).trim();
152*cdf0e10cSrcweir             if( (aTableIndex.getLength() > 0) && (aTableIndex[ 0 ] >= '1') && (aTableIndex[ 0 ] <= '9') )
153*cdf0e10cSrcweir                 rTables.push_back( Any( aTableIndex.toInt32() ) );
154*cdf0e10cSrcweir             else
155*cdf0e10cSrcweir                 rTables.push_back( Any() );
156*cdf0e10cSrcweir         }
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir         // remove processed item from aTableNames
159*cdf0e10cSrcweir         if( (nSep < 0) || (nSep >= aTableNames.getLength()) )
160*cdf0e10cSrcweir             aTableNames = OUString();
161*cdf0e10cSrcweir         else
162*cdf0e10cSrcweir             aTableNames = aTableNames.copy( nSep + 1 ).trim();
163*cdf0e10cSrcweir     }
164*cdf0e10cSrcweir }
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir } // namespace
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir // ============================================================================
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir WebPrModel::WebPrModel() :
171*cdf0e10cSrcweir     mnHtmlFormat( XML_none ),
172*cdf0e10cSrcweir     mbXml( false ),
173*cdf0e10cSrcweir     mbSourceData( false ),
174*cdf0e10cSrcweir     mbParsePre( false ),
175*cdf0e10cSrcweir     mbConsecutive( false ),
176*cdf0e10cSrcweir     mbFirstRow( false ),
177*cdf0e10cSrcweir     mbXl97Created( false ),
178*cdf0e10cSrcweir     mbTextDates( false ),
179*cdf0e10cSrcweir     mbXl2000Refreshed( false ),
180*cdf0e10cSrcweir     mbHtmlTables( false )
181*cdf0e10cSrcweir {
182*cdf0e10cSrcweir }
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir // ----------------------------------------------------------------------------
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir ConnectionModel::ConnectionModel() :
187*cdf0e10cSrcweir     mnId( -1 ),
188*cdf0e10cSrcweir     mnType( BIFF12_CONNECTION_UNKNOWN ),
189*cdf0e10cSrcweir     mnReconnectMethod( BIFF12_RECONNECT_AS_REQUIRED ),
190*cdf0e10cSrcweir     mnCredentials( XML_integrated ),
191*cdf0e10cSrcweir     mnInterval( 0 ),
192*cdf0e10cSrcweir     mbKeepAlive( false ),
193*cdf0e10cSrcweir     mbNew( false ),
194*cdf0e10cSrcweir     mbDeleted( false ),
195*cdf0e10cSrcweir     mbOnlyUseConnFile( false ),
196*cdf0e10cSrcweir     mbBackground( false ),
197*cdf0e10cSrcweir     mbRefreshOnLoad( false ),
198*cdf0e10cSrcweir     mbSaveData( false ),
199*cdf0e10cSrcweir     mbSavePassword( false )
200*cdf0e10cSrcweir {
201*cdf0e10cSrcweir }
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir WebPrModel& ConnectionModel::createWebPr()
204*cdf0e10cSrcweir {
205*cdf0e10cSrcweir     OSL_ENSURE( !mxWebPr.get(), "ConnectionModel::createWebPr - multiple call" );
206*cdf0e10cSrcweir     mxWebPr.reset( new WebPrModel );
207*cdf0e10cSrcweir     return *mxWebPr;
208*cdf0e10cSrcweir }
209*cdf0e10cSrcweir 
210*cdf0e10cSrcweir // ----------------------------------------------------------------------------
211*cdf0e10cSrcweir 
212*cdf0e10cSrcweir Connection::Connection( const WorkbookHelper& rHelper, sal_Int32 nConnId ) :
213*cdf0e10cSrcweir     WorkbookHelper( rHelper )
214*cdf0e10cSrcweir {
215*cdf0e10cSrcweir     maModel.mnId = nConnId;
216*cdf0e10cSrcweir }
217*cdf0e10cSrcweir 
218*cdf0e10cSrcweir void Connection::importConnection( const AttributeList& rAttribs )
219*cdf0e10cSrcweir {
220*cdf0e10cSrcweir     maModel.maName            = rAttribs.getXString( XML_name, OUString() );
221*cdf0e10cSrcweir     maModel.maDescription     = rAttribs.getXString( XML_description, OUString() );
222*cdf0e10cSrcweir     maModel.maSourceFile      = rAttribs.getXString( XML_sourceFile, OUString() );
223*cdf0e10cSrcweir     maModel.maSourceConnFile  = rAttribs.getXString( XML_odcFile, OUString() );
224*cdf0e10cSrcweir     maModel.maSsoId           = rAttribs.getXString( XML_singleSignOnId, OUString() );
225*cdf0e10cSrcweir     maModel.mnId              = rAttribs.getInteger( XML_id, -1 );
226*cdf0e10cSrcweir     // type and reconnectionMethod are using the BIFF12 constants instead of XML tokens
227*cdf0e10cSrcweir     maModel.mnType            = rAttribs.getInteger( XML_type, BIFF12_CONNECTION_UNKNOWN );
228*cdf0e10cSrcweir     maModel.mnReconnectMethod = rAttribs.getInteger( XML_reconnectionMethod, BIFF12_RECONNECT_AS_REQUIRED );
229*cdf0e10cSrcweir     maModel.mnCredentials     = rAttribs.getToken( XML_credentials, XML_integrated );
230*cdf0e10cSrcweir     maModel.mnInterval        = rAttribs.getInteger( XML_interval, 0 );
231*cdf0e10cSrcweir     maModel.mbKeepAlive       = rAttribs.getBool( XML_keepAlive, false );
232*cdf0e10cSrcweir     maModel.mbNew             = rAttribs.getBool( XML_new, false );
233*cdf0e10cSrcweir     maModel.mbDeleted         = rAttribs.getBool( XML_deleted, false );
234*cdf0e10cSrcweir     maModel.mbOnlyUseConnFile = rAttribs.getBool( XML_onlyUseConnectionFile, false );
235*cdf0e10cSrcweir     maModel.mbBackground      = rAttribs.getBool( XML_background, false );
236*cdf0e10cSrcweir     maModel.mbRefreshOnLoad   = rAttribs.getBool( XML_refreshOnLoad, false );
237*cdf0e10cSrcweir     maModel.mbSaveData        = rAttribs.getBool( XML_saveData, false );
238*cdf0e10cSrcweir     maModel.mbSavePassword    = rAttribs.getBool( XML_savePassword, false );
239*cdf0e10cSrcweir }
240*cdf0e10cSrcweir 
241*cdf0e10cSrcweir void Connection::importWebPr( const AttributeList& rAttribs )
242*cdf0e10cSrcweir {
243*cdf0e10cSrcweir     WebPrModel& rWebPr = maModel.createWebPr();
244*cdf0e10cSrcweir 
245*cdf0e10cSrcweir     rWebPr.maUrl             = rAttribs.getXString( XML_url, OUString() );
246*cdf0e10cSrcweir     rWebPr.maPostMethod      = rAttribs.getXString( XML_post, OUString() );
247*cdf0e10cSrcweir     rWebPr.maEditPage        = rAttribs.getXString( XML_editPage, OUString() );
248*cdf0e10cSrcweir     rWebPr.mnHtmlFormat      = rAttribs.getToken( XML_htmlFormat, XML_none );
249*cdf0e10cSrcweir     rWebPr.mbXml             = rAttribs.getBool( XML_xml, false );
250*cdf0e10cSrcweir     rWebPr.mbSourceData      = rAttribs.getBool( XML_sourceData, false );
251*cdf0e10cSrcweir     rWebPr.mbParsePre        = rAttribs.getBool( XML_parsePre, false );
252*cdf0e10cSrcweir     rWebPr.mbConsecutive     = rAttribs.getBool( XML_consecutive, false );
253*cdf0e10cSrcweir     rWebPr.mbFirstRow        = rAttribs.getBool( XML_firstRow, false );
254*cdf0e10cSrcweir     rWebPr.mbXl97Created     = rAttribs.getBool( XML_xl97, false );
255*cdf0e10cSrcweir     rWebPr.mbTextDates       = rAttribs.getBool( XML_textDates, false );
256*cdf0e10cSrcweir     rWebPr.mbXl2000Refreshed = rAttribs.getBool( XML_xl2000, false );
257*cdf0e10cSrcweir     rWebPr.mbHtmlTables      = rAttribs.getBool( XML_htmlTables, false );
258*cdf0e10cSrcweir }
259*cdf0e10cSrcweir 
260*cdf0e10cSrcweir void Connection::importTables( const AttributeList& /*rAttribs*/ )
261*cdf0e10cSrcweir {
262*cdf0e10cSrcweir     if( maModel.mxWebPr.get() )
263*cdf0e10cSrcweir     {
264*cdf0e10cSrcweir         OSL_ENSURE( maModel.mxWebPr->maTables.empty(), "Connection::importTables - multiple calls" );
265*cdf0e10cSrcweir         maModel.mxWebPr->maTables.clear();
266*cdf0e10cSrcweir     }
267*cdf0e10cSrcweir }
268*cdf0e10cSrcweir 
269*cdf0e10cSrcweir void Connection::importTable( const AttributeList& rAttribs, sal_Int32 nElement )
270*cdf0e10cSrcweir {
271*cdf0e10cSrcweir     if( maModel.mxWebPr.get() )
272*cdf0e10cSrcweir     {
273*cdf0e10cSrcweir         Any aTableAny;
274*cdf0e10cSrcweir         switch( nElement )
275*cdf0e10cSrcweir         {
276*cdf0e10cSrcweir             case XLS_TOKEN( m ):                                                            break;
277*cdf0e10cSrcweir             case XLS_TOKEN( s ):    aTableAny <<= rAttribs.getXString( XML_v, OUString() ); break;
278*cdf0e10cSrcweir             case XLS_TOKEN( x ):    aTableAny <<= rAttribs.getInteger( XML_v, -1 );         break;
279*cdf0e10cSrcweir             default:
280*cdf0e10cSrcweir                 OSL_ENSURE( false, "Connection::importTable - unexpected element" );
281*cdf0e10cSrcweir                 return;
282*cdf0e10cSrcweir         }
283*cdf0e10cSrcweir         maModel.mxWebPr->maTables.push_back( aTableAny );
284*cdf0e10cSrcweir     }
285*cdf0e10cSrcweir }
286*cdf0e10cSrcweir 
287*cdf0e10cSrcweir void Connection::importConnection( SequenceInputStream& rStrm )
288*cdf0e10cSrcweir {
289*cdf0e10cSrcweir     sal_uInt16 nFlags, nStrFlags;
290*cdf0e10cSrcweir     sal_uInt8 nSavePassword, nCredentials;
291*cdf0e10cSrcweir     rStrm.skip( 2 );
292*cdf0e10cSrcweir     rStrm >> nSavePassword;
293*cdf0e10cSrcweir     rStrm.skip( 1 );
294*cdf0e10cSrcweir     maModel.mnInterval = rStrm.readuInt16();
295*cdf0e10cSrcweir     rStrm >> nFlags >> nStrFlags >> maModel.mnType >> maModel.mnReconnectMethod >> maModel.mnId >> nCredentials;
296*cdf0e10cSrcweir 
297*cdf0e10cSrcweir     if( getFlag( nStrFlags, BIFF12_CONNECTION_HAS_SOURCEFILE ) )
298*cdf0e10cSrcweir         rStrm >> maModel.maSourceFile;
299*cdf0e10cSrcweir     if( getFlag( nStrFlags, BIFF12_CONNECTION_HAS_SOURCECONNFILE ) )
300*cdf0e10cSrcweir         rStrm >> maModel.maSourceConnFile;
301*cdf0e10cSrcweir     if( getFlag( nStrFlags, BIFF12_CONNECTION_HAS_DESCRIPTION ) )
302*cdf0e10cSrcweir         rStrm >> maModel.maDescription;
303*cdf0e10cSrcweir     if( getFlag( nStrFlags, BIFF12_CONNECTION_HAS_NAME ) )
304*cdf0e10cSrcweir         rStrm >> maModel.maName;
305*cdf0e10cSrcweir     if( getFlag( nStrFlags, BIFF12_CONNECTION_HAS_SSOID ) )
306*cdf0e10cSrcweir         rStrm >> maModel.maSsoId;
307*cdf0e10cSrcweir 
308*cdf0e10cSrcweir     static const sal_Int32 spnCredentials[] = { XML_integrated, XML_none, XML_stored, XML_prompt };
309*cdf0e10cSrcweir     maModel.mnCredentials = STATIC_ARRAY_SELECT( spnCredentials, nCredentials, XML_integrated );
310*cdf0e10cSrcweir 
311*cdf0e10cSrcweir     maModel.mbKeepAlive       = getFlag( nFlags, BIFF12_CONNECTION_KEEPALIVE );
312*cdf0e10cSrcweir     maModel.mbNew             = getFlag( nFlags, BIFF12_CONNECTION_NEW );
313*cdf0e10cSrcweir     maModel.mbDeleted         = getFlag( nFlags, BIFF12_CONNECTION_DELETED );
314*cdf0e10cSrcweir     maModel.mbOnlyUseConnFile = getFlag( nFlags, BIFF12_CONNECTION_ONLYUSECONNFILE );
315*cdf0e10cSrcweir     maModel.mbBackground      = getFlag( nFlags, BIFF12_CONNECTION_BACKGROUND );
316*cdf0e10cSrcweir     maModel.mbRefreshOnLoad   = getFlag( nFlags, BIFF12_CONNECTION_REFRESHONLOAD );
317*cdf0e10cSrcweir     maModel.mbSaveData        = getFlag( nFlags, BIFF12_CONNECTION_SAVEDATA );
318*cdf0e10cSrcweir     maModel.mbSavePassword    = nSavePassword == BIFF12_CONNECTION_SAVEPASSWORD_ON;
319*cdf0e10cSrcweir }
320*cdf0e10cSrcweir 
321*cdf0e10cSrcweir void Connection::importWebPr( SequenceInputStream& rStrm )
322*cdf0e10cSrcweir {
323*cdf0e10cSrcweir     WebPrModel& rWebPr = maModel.createWebPr();
324*cdf0e10cSrcweir 
325*cdf0e10cSrcweir     sal_uInt32 nFlags;
326*cdf0e10cSrcweir     sal_uInt8 nStrFlags;
327*cdf0e10cSrcweir     rStrm >> nFlags >> nStrFlags;
328*cdf0e10cSrcweir 
329*cdf0e10cSrcweir     if( getFlag( nStrFlags, BIFF12_WEBPR_HAS_URL ) )
330*cdf0e10cSrcweir         rStrm >> rWebPr.maUrl;
331*cdf0e10cSrcweir     if( getFlag( nStrFlags, BIFF12_WEBPR_HAS_POSTMETHOD ) )
332*cdf0e10cSrcweir         rStrm >> rWebPr.maPostMethod;
333*cdf0e10cSrcweir     if( getFlag( nStrFlags, BIFF12_WEBPR_HAS_EDITPAGE ) )
334*cdf0e10cSrcweir         rStrm >> rWebPr.maEditPage;
335*cdf0e10cSrcweir 
336*cdf0e10cSrcweir     static const sal_Int32 spnHmlFormats[] = { XML_none, XML_rtf, XML_all };
337*cdf0e10cSrcweir     rWebPr.mnHtmlFormat = STATIC_ARRAY_SELECT( spnHmlFormats, extractValue< sal_uInt8 >( nFlags, 0, 8 ), XML_none );
338*cdf0e10cSrcweir 
339*cdf0e10cSrcweir     rWebPr.mbXml             = getFlag( nFlags, BIFF12_WEBPR_XML );
340*cdf0e10cSrcweir     rWebPr.mbSourceData      = getFlag( nFlags, BIFF12_WEBPR_SOURCEDATA );
341*cdf0e10cSrcweir     rWebPr.mbParsePre        = getFlag( nFlags, BIFF12_WEBPR_PARSEPRE );
342*cdf0e10cSrcweir     rWebPr.mbConsecutive     = getFlag( nFlags, BIFF12_WEBPR_CONSECUTIVE );
343*cdf0e10cSrcweir     rWebPr.mbFirstRow        = getFlag( nFlags, BIFF12_WEBPR_FIRSTROW );
344*cdf0e10cSrcweir     rWebPr.mbXl97Created     = getFlag( nFlags, BIFF12_WEBPR_XL97CREATED );
345*cdf0e10cSrcweir     rWebPr.mbTextDates       = getFlag( nFlags, BIFF12_WEBPR_TEXTDATES );
346*cdf0e10cSrcweir     rWebPr.mbXl2000Refreshed = getFlag( nFlags, BIFF12_WEBPR_XL2000REFRESHED );
347*cdf0e10cSrcweir     rWebPr.mbHtmlTables      = getFlag( nFlags, BIFF12_WEBPR_HTMLTABLES );
348*cdf0e10cSrcweir }
349*cdf0e10cSrcweir 
350*cdf0e10cSrcweir void Connection::importWebPrTables( SequenceInputStream& /*rStrm*/ )
351*cdf0e10cSrcweir {
352*cdf0e10cSrcweir     if( maModel.mxWebPr.get() )
353*cdf0e10cSrcweir     {
354*cdf0e10cSrcweir         OSL_ENSURE( maModel.mxWebPr->maTables.empty(), "Connection::importWebPrTables - multiple calls" );
355*cdf0e10cSrcweir         maModel.mxWebPr->maTables.clear();
356*cdf0e10cSrcweir     }
357*cdf0e10cSrcweir }
358*cdf0e10cSrcweir 
359*cdf0e10cSrcweir void Connection::importWebPrTable( SequenceInputStream& rStrm, sal_Int32 nRecId )
360*cdf0e10cSrcweir {
361*cdf0e10cSrcweir     if( maModel.mxWebPr.get() )
362*cdf0e10cSrcweir     {
363*cdf0e10cSrcweir         Any aTableAny;
364*cdf0e10cSrcweir         switch( nRecId )
365*cdf0e10cSrcweir         {
366*cdf0e10cSrcweir             case BIFF12_ID_PCITEM_MISSING:                                                  break;
367*cdf0e10cSrcweir             case BIFF12_ID_PCITEM_STRING:   aTableAny <<= BiffHelper::readString( rStrm );  break;
368*cdf0e10cSrcweir             case BIFF12_ID_PCITEM_INDEX:    aTableAny <<= rStrm.readInt32();                break;
369*cdf0e10cSrcweir             default:
370*cdf0e10cSrcweir                 OSL_ENSURE( false, "Connection::importWebPrTable - unexpected record" );
371*cdf0e10cSrcweir                 return;
372*cdf0e10cSrcweir         }
373*cdf0e10cSrcweir         maModel.mxWebPr->maTables.push_back( aTableAny );
374*cdf0e10cSrcweir     }
375*cdf0e10cSrcweir }
376*cdf0e10cSrcweir 
377*cdf0e10cSrcweir void Connection::importDbQuery( BiffInputStream& rStrm )
378*cdf0e10cSrcweir {
379*cdf0e10cSrcweir     sal_uInt16 nFlags, nSqlParamCount, nCommandCount, nPostMethodCount, nServerSqlCount, nOdbcConnCount;
380*cdf0e10cSrcweir     rStrm >> nFlags >> nSqlParamCount >> nCommandCount >> nPostMethodCount >> nServerSqlCount >> nOdbcConnCount;
381*cdf0e10cSrcweir 
382*cdf0e10cSrcweir     // same type constants in all BIFF versions
383*cdf0e10cSrcweir     maModel.mnType = extractValue< sal_Int32 >( nFlags, 0, 3 );
384*cdf0e10cSrcweir     maModel.mbSavePassword = getFlag( nFlags, BIFF_DBQUERY_SAVEPASSWORD );
385*cdf0e10cSrcweir 
386*cdf0e10cSrcweir     OSL_ENSURE( getFlag( nFlags, BIFF_DBQUERY_ODBC ) == (maModel.mnType == BIFF12_CONNECTION_ODBC), "Connection::importDbQuery - wrong ODBC flag" );
387*cdf0e10cSrcweir     OSL_ENSURE( getFlag( nFlags, BIFF_DBQUERY_SQLQUERY ) != (maModel.mnType == BIFF12_CONNECTION_HTML), "Connection::importDbQuery - wrong SQL query flag" );
388*cdf0e10cSrcweir     OSL_ENSURE( getFlag( nFlags, BIFF_DBQUERY_HTML ) == (maModel.mnType == BIFF12_CONNECTION_HTML), "Connection::importDbQuery - wrong HTML flag" );
389*cdf0e10cSrcweir 
390*cdf0e10cSrcweir     if( (maModel.mnType == BIFF12_CONNECTION_HTML) && getFlag( nFlags, BIFF_DBQUERY_HTML ) )
391*cdf0e10cSrcweir     {
392*cdf0e10cSrcweir         WebPrModel& rWebPr = maModel.createWebPr();
393*cdf0e10cSrcweir         rWebPr.mbHtmlTables = getFlag( nFlags, BIFF_DBQUERY_HTMLTABLES );
394*cdf0e10cSrcweir 
395*cdf0e10cSrcweir         // read HTML query URL and post method
396*cdf0e10cSrcweir         rWebPr.maUrl = lclReadQueryString( rStrm, nCommandCount );
397*cdf0e10cSrcweir         rWebPr.maPostMethod = lclReadQueryString( rStrm, nPostMethodCount );
398*cdf0e10cSrcweir     }
399*cdf0e10cSrcweir }
400*cdf0e10cSrcweir 
401*cdf0e10cSrcweir void Connection::importQueryTableSettings( BiffInputStream& rStrm )
402*cdf0e10cSrcweir {
403*cdf0e10cSrcweir     rStrm.skip( 4 );
404*cdf0e10cSrcweir     // source data type, again
405*cdf0e10cSrcweir     sal_uInt16 nType = rStrm.readuInt16();
406*cdf0e10cSrcweir     OSL_ENSURE( nType == maModel.mnType, "Connection::importQueryTableSettings - source data type mismatch" );
407*cdf0e10cSrcweir     if( nType == maModel.mnType )
408*cdf0e10cSrcweir     {
409*cdf0e10cSrcweir         sal_uInt16 nFlags1, nFlags2, nFlags3, nHtmlFormat;
410*cdf0e10cSrcweir         rStrm >> nFlags1 >> nFlags2 >> nFlags3;
411*cdf0e10cSrcweir         rStrm.skip( 10 );
412*cdf0e10cSrcweir         maModel.mnInterval = rStrm.readuInt16();
413*cdf0e10cSrcweir         rStrm >> nHtmlFormat;
414*cdf0e10cSrcweir 
415*cdf0e10cSrcweir         // first flags field: generic connection flags
416*cdf0e10cSrcweir         maModel.mbKeepAlive = getFlag( nFlags1, BIFF_QTSETTINGS_KEEPALIVE );
417*cdf0e10cSrcweir         maModel.mbNew       = getFlag( nFlags1, BIFF_QTSETTINGS_NEW );
418*cdf0e10cSrcweir 
419*cdf0e10cSrcweir         // meaning of second flags field is dependent on source data type
420*cdf0e10cSrcweir         if( (maModel.mnType == BIFF12_CONNECTION_HTML) && maModel.mxWebPr.get() )
421*cdf0e10cSrcweir         {
422*cdf0e10cSrcweir             WebPrModel& rWebPr = *maModel.mxWebPr;
423*cdf0e10cSrcweir 
424*cdf0e10cSrcweir             // HTML format is one-based in BIFF8 (but zero-based in BIFF12)
425*cdf0e10cSrcweir             static const sal_Int32 spnHmlFormats[] = { XML_none, XML_none, XML_rtf, XML_all };
426*cdf0e10cSrcweir             rWebPr.mnHtmlFormat = STATIC_ARRAY_SELECT( spnHmlFormats, nHtmlFormat, XML_none );
427*cdf0e10cSrcweir 
428*cdf0e10cSrcweir             rWebPr.mbXml             = getFlag( nFlags1, BIFF_QTSETTINGS_XML );
429*cdf0e10cSrcweir             rWebPr.mbSourceData      = getFlag( nFlags1, BIFF_QTSETTINGS_SOURCEDATA );
430*cdf0e10cSrcweir             rWebPr.mbParsePre        = getFlag( nFlags2, BIFF_QTSETTINGS_PARSEPRE );
431*cdf0e10cSrcweir             rWebPr.mbConsecutive     = getFlag( nFlags2, BIFF_QTSETTINGS_CONSECUTIVE );
432*cdf0e10cSrcweir             rWebPr.mbFirstRow        = getFlag( nFlags2, BIFF_QTSETTINGS_FIRSTROW );
433*cdf0e10cSrcweir             rWebPr.mbXl97Created     = getFlag( nFlags2, BIFF_QTSETTINGS_XL97CREATED );
434*cdf0e10cSrcweir             rWebPr.mbTextDates       = getFlag( nFlags2, BIFF_QTSETTINGS_TEXTDATES );
435*cdf0e10cSrcweir             rWebPr.mbXl2000Refreshed = getFlag( nFlags2, BIFF_QTSETTINGS_XL2000REFRESHED );
436*cdf0e10cSrcweir 
437*cdf0e10cSrcweir             // list of HTML table names or indexes
438*cdf0e10cSrcweir             if( getFlag( nFlags3, BIFF_QTSETTINGS_TABLENAMES ) )
439*cdf0e10cSrcweir             {
440*cdf0e10cSrcweir                 // a QUERYTABLESTRING record containing the table names must follow
441*cdf0e10cSrcweir                 bool bHasQTString = (rStrm.getNextRecId() == BIFF_ID_QUERYTABLESTRING) && rStrm.startNextRecord();
442*cdf0e10cSrcweir                 OSL_ENSURE( bHasQTString, "Connection::importQueryTableSettings - missing QUERYTABLESTRING record" );
443*cdf0e10cSrcweir                 if( bHasQTString )
444*cdf0e10cSrcweir                 {
445*cdf0e10cSrcweir                     rStrm.skip( 4 );
446*cdf0e10cSrcweir                     lclParseTables( rWebPr.maTables, rStrm.readUniString() );
447*cdf0e10cSrcweir                 }
448*cdf0e10cSrcweir             }
449*cdf0e10cSrcweir         }
450*cdf0e10cSrcweir     }
451*cdf0e10cSrcweir }
452*cdf0e10cSrcweir 
453*cdf0e10cSrcweir // ============================================================================
454*cdf0e10cSrcweir 
455*cdf0e10cSrcweir ConnectionsBuffer::ConnectionsBuffer( const WorkbookHelper& rHelper ) :
456*cdf0e10cSrcweir     WorkbookHelper( rHelper ),
457*cdf0e10cSrcweir     mnUnusedId( 1 )
458*cdf0e10cSrcweir {
459*cdf0e10cSrcweir }
460*cdf0e10cSrcweir 
461*cdf0e10cSrcweir Connection& ConnectionsBuffer::createConnection()
462*cdf0e10cSrcweir {
463*cdf0e10cSrcweir     ConnectionRef xConnection( new Connection( *this ) );
464*cdf0e10cSrcweir     maConnections.push_back( xConnection );
465*cdf0e10cSrcweir     return *xConnection;
466*cdf0e10cSrcweir }
467*cdf0e10cSrcweir 
468*cdf0e10cSrcweir Connection& ConnectionsBuffer::createConnectionWithId()
469*cdf0e10cSrcweir {
470*cdf0e10cSrcweir     ConnectionRef xConnection( new Connection( *this, mnUnusedId ) );
471*cdf0e10cSrcweir     maConnections.push_back( xConnection );
472*cdf0e10cSrcweir     insertConnectionToMap( xConnection );
473*cdf0e10cSrcweir     return *xConnection;
474*cdf0e10cSrcweir }
475*cdf0e10cSrcweir 
476*cdf0e10cSrcweir void ConnectionsBuffer::finalizeImport()
477*cdf0e10cSrcweir {
478*cdf0e10cSrcweir     for( ConnectionVector::iterator aIt = maConnections.begin(), aEnd = maConnections.end(); aIt != aEnd; ++aIt )
479*cdf0e10cSrcweir         insertConnectionToMap( *aIt );
480*cdf0e10cSrcweir }
481*cdf0e10cSrcweir 
482*cdf0e10cSrcweir ConnectionRef ConnectionsBuffer::getConnection( sal_Int32 nConnId ) const
483*cdf0e10cSrcweir {
484*cdf0e10cSrcweir     return maConnectionsById.get( nConnId );
485*cdf0e10cSrcweir }
486*cdf0e10cSrcweir 
487*cdf0e10cSrcweir void ConnectionsBuffer::insertConnectionToMap( const ConnectionRef& rxConnection )
488*cdf0e10cSrcweir {
489*cdf0e10cSrcweir     sal_Int32 nConnId = rxConnection->getConnectionId();
490*cdf0e10cSrcweir     if( nConnId > 0 )
491*cdf0e10cSrcweir     {
492*cdf0e10cSrcweir         OSL_ENSURE( !maConnectionsById.has( nConnId ), "ConnectionsBuffer::insertConnectionToMap - multiple connection identifier" );
493*cdf0e10cSrcweir         maConnectionsById[ nConnId ] = rxConnection;
494*cdf0e10cSrcweir         mnUnusedId = ::std::max< sal_Int32 >( mnUnusedId, nConnId + 1 );
495*cdf0e10cSrcweir     }
496*cdf0e10cSrcweir }
497*cdf0e10cSrcweir 
498*cdf0e10cSrcweir // ============================================================================
499*cdf0e10cSrcweir 
500*cdf0e10cSrcweir } // namespace xls
501*cdf0e10cSrcweir } // namespace oox
502