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