1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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"
22 #include <osl/diagnose.h>
23 #include <oox/helper/attributelist.hxx>
24 #include "biffinputstream.hxx"
29 using namespace ::com::sun::star::uno
;
33 const sal_Int32 BIFF12_RECONNECT_AS_REQUIRED
= 1;
35 const sal_uInt8 BIFF12_CONNECTION_SAVEPASSWORD_ON
= 1;
37 const sal_uInt16 BIFF12_CONNECTION_KEEPALIVE
= 0x0001;
38 const sal_uInt16 BIFF12_CONNECTION_NEW
= 0x0002;
39 const sal_uInt16 BIFF12_CONNECTION_DELETED
= 0x0004;
40 const sal_uInt16 BIFF12_CONNECTION_ONLYUSECONNFILE
= 0x0008;
41 const sal_uInt16 BIFF12_CONNECTION_BACKGROUND
= 0x0010;
42 const sal_uInt16 BIFF12_CONNECTION_REFRESHONLOAD
= 0x0020;
43 const sal_uInt16 BIFF12_CONNECTION_SAVEDATA
= 0x0040;
45 const sal_uInt16 BIFF12_CONNECTION_HAS_SOURCEFILE
= 0x0001;
46 const sal_uInt16 BIFF12_CONNECTION_HAS_SOURCECONNFILE
= 0x0002;
47 const sal_uInt16 BIFF12_CONNECTION_HAS_DESCRIPTION
= 0x0004;
48 const sal_uInt16 BIFF12_CONNECTION_HAS_NAME
= 0x0008;
49 const sal_uInt16 BIFF12_CONNECTION_HAS_SSOID
= 0x0010;
51 const sal_uInt32 BIFF12_WEBPR_XML
= 0x00000100;
52 const sal_uInt32 BIFF12_WEBPR_SOURCEDATA
= 0x00000200;
53 const sal_uInt32 BIFF12_WEBPR_PARSEPRE
= 0x00000400;
54 const sal_uInt32 BIFF12_WEBPR_CONSECUTIVE
= 0x00000800;
55 const sal_uInt32 BIFF12_WEBPR_FIRSTROW
= 0x00001000;
56 const sal_uInt32 BIFF12_WEBPR_XL97CREATED
= 0x00002000;
57 const sal_uInt32 BIFF12_WEBPR_TEXTDATES
= 0x00004000;
58 const sal_uInt32 BIFF12_WEBPR_XL2000REFRESHED
= 0x00008000;
59 const sal_uInt32 BIFF12_WEBPR_HTMLTABLES
= 0x00010000;
61 const sal_uInt8 BIFF12_WEBPR_HAS_POSTMETHOD
= 0x01;
62 const sal_uInt8 BIFF12_WEBPR_HAS_EDITPAGE
= 0x02;
63 const sal_uInt8 BIFF12_WEBPR_HAS_URL
= 0x04;
67 WebPrModel::WebPrModel() :
68 mnHtmlFormat( XML_none
),
70 mbSourceData( false ),
72 mbConsecutive( false ),
74 mbXl97Created( false ),
76 mbXl2000Refreshed( false ),
81 ConnectionModel::ConnectionModel() :
83 mnType( BIFF12_CONNECTION_UNKNOWN
),
84 mnReconnectMethod( BIFF12_RECONNECT_AS_REQUIRED
),
85 mnCredentials( XML_integrated
),
90 mbOnlyUseConnFile( false ),
91 mbBackground( false ),
92 mbRefreshOnLoad( false ),
94 mbSavePassword( false )
98 WebPrModel
& ConnectionModel::createWebPr()
100 OSL_ENSURE( !mxWebPr
.get(), "ConnectionModel::createWebPr - multiple call" );
101 mxWebPr
.reset( new WebPrModel
);
105 Connection::Connection( const WorkbookHelper
& rHelper
, sal_Int32 nConnId
) :
106 WorkbookHelper( rHelper
)
108 maModel
.mnId
= nConnId
;
111 void Connection::importConnection( const AttributeList
& rAttribs
)
113 maModel
.maName
= rAttribs
.getXString( XML_name
, OUString() );
114 maModel
.maDescription
= rAttribs
.getXString( XML_description
, OUString() );
115 maModel
.maSourceFile
= rAttribs
.getXString( XML_sourceFile
, OUString() );
116 maModel
.maSourceConnFile
= rAttribs
.getXString( XML_odcFile
, OUString() );
117 maModel
.maSsoId
= rAttribs
.getXString( XML_singleSignOnId
, OUString() );
118 maModel
.mnId
= rAttribs
.getInteger( XML_id
, -1 );
119 // type and reconnectionMethod are using the BIFF12 constants instead of XML tokens
120 maModel
.mnType
= rAttribs
.getInteger( XML_type
, BIFF12_CONNECTION_UNKNOWN
);
121 maModel
.mnReconnectMethod
= rAttribs
.getInteger( XML_reconnectionMethod
, BIFF12_RECONNECT_AS_REQUIRED
);
122 maModel
.mnCredentials
= rAttribs
.getToken( XML_credentials
, XML_integrated
);
123 maModel
.mnInterval
= rAttribs
.getInteger( XML_interval
, 0 );
124 maModel
.mbKeepAlive
= rAttribs
.getBool( XML_keepAlive
, false );
125 maModel
.mbNew
= rAttribs
.getBool( XML_new
, false );
126 maModel
.mbDeleted
= rAttribs
.getBool( XML_deleted
, false );
127 maModel
.mbOnlyUseConnFile
= rAttribs
.getBool( XML_onlyUseConnectionFile
, false );
128 maModel
.mbBackground
= rAttribs
.getBool( XML_background
, false );
129 maModel
.mbRefreshOnLoad
= rAttribs
.getBool( XML_refreshOnLoad
, false );
130 maModel
.mbSaveData
= rAttribs
.getBool( XML_saveData
, false );
131 maModel
.mbSavePassword
= rAttribs
.getBool( XML_savePassword
, false );
134 void Connection::importWebPr( const AttributeList
& rAttribs
)
136 WebPrModel
& rWebPr
= maModel
.createWebPr();
138 rWebPr
.maUrl
= rAttribs
.getXString( XML_url
, OUString() );
139 rWebPr
.maPostMethod
= rAttribs
.getXString( XML_post
, OUString() );
140 rWebPr
.maEditPage
= rAttribs
.getXString( XML_editPage
, OUString() );
141 rWebPr
.mnHtmlFormat
= rAttribs
.getToken( XML_htmlFormat
, XML_none
);
142 rWebPr
.mbXml
= rAttribs
.getBool( XML_xml
, false );
143 rWebPr
.mbSourceData
= rAttribs
.getBool( XML_sourceData
, false );
144 rWebPr
.mbParsePre
= rAttribs
.getBool( XML_parsePre
, false );
145 rWebPr
.mbConsecutive
= rAttribs
.getBool( XML_consecutive
, false );
146 rWebPr
.mbFirstRow
= rAttribs
.getBool( XML_firstRow
, false );
147 rWebPr
.mbXl97Created
= rAttribs
.getBool( XML_xl97
, false );
148 rWebPr
.mbTextDates
= rAttribs
.getBool( XML_textDates
, false );
149 rWebPr
.mbXl2000Refreshed
= rAttribs
.getBool( XML_xl2000
, false );
150 rWebPr
.mbHtmlTables
= rAttribs
.getBool( XML_htmlTables
, false );
153 void Connection::importTables( const AttributeList
& /*rAttribs*/ )
155 if( maModel
.mxWebPr
.get() )
157 OSL_ENSURE( maModel
.mxWebPr
->maTables
.empty(), "Connection::importTables - multiple calls" );
158 maModel
.mxWebPr
->maTables
.clear();
162 void Connection::importTable( const AttributeList
& rAttribs
, sal_Int32 nElement
)
164 if( maModel
.mxWebPr
.get() )
169 case XLS_TOKEN( m
): break;
170 case XLS_TOKEN( s
): aTableAny
<<= rAttribs
.getXString( XML_v
, OUString() ); break;
171 case XLS_TOKEN( x
): aTableAny
<<= rAttribs
.getInteger( XML_v
, -1 ); break;
173 OSL_ENSURE( false, "Connection::importTable - unexpected element" );
176 maModel
.mxWebPr
->maTables
.push_back( aTableAny
);
180 void Connection::importConnection( SequenceInputStream
& rStrm
)
182 sal_uInt16 nFlags
, nStrFlags
;
183 sal_uInt8 nSavePassword
, nCredentials
;
185 nSavePassword
= rStrm
.readuChar();
187 maModel
.mnInterval
= rStrm
.readuInt16();
188 nFlags
= rStrm
.readuInt16();
189 nStrFlags
= rStrm
.readuInt16();
190 maModel
.mnType
= rStrm
.readInt32();
191 maModel
.mnReconnectMethod
= rStrm
.readInt32();
192 maModel
.mnId
= rStrm
.readInt32();
193 nCredentials
= rStrm
.readuChar();
195 if( getFlag( nStrFlags
, BIFF12_CONNECTION_HAS_SOURCEFILE
) )
196 rStrm
>> maModel
.maSourceFile
;
197 if( getFlag( nStrFlags
, BIFF12_CONNECTION_HAS_SOURCECONNFILE
) )
198 rStrm
>> maModel
.maSourceConnFile
;
199 if( getFlag( nStrFlags
, BIFF12_CONNECTION_HAS_DESCRIPTION
) )
200 rStrm
>> maModel
.maDescription
;
201 if( getFlag( nStrFlags
, BIFF12_CONNECTION_HAS_NAME
) )
202 rStrm
>> maModel
.maName
;
203 if( getFlag( nStrFlags
, BIFF12_CONNECTION_HAS_SSOID
) )
204 rStrm
>> maModel
.maSsoId
;
206 static const sal_Int32 spnCredentials
[] = { XML_integrated
, XML_none
, XML_stored
, XML_prompt
};
207 maModel
.mnCredentials
= STATIC_ARRAY_SELECT( spnCredentials
, nCredentials
, XML_integrated
);
209 maModel
.mbKeepAlive
= getFlag( nFlags
, BIFF12_CONNECTION_KEEPALIVE
);
210 maModel
.mbNew
= getFlag( nFlags
, BIFF12_CONNECTION_NEW
);
211 maModel
.mbDeleted
= getFlag( nFlags
, BIFF12_CONNECTION_DELETED
);
212 maModel
.mbOnlyUseConnFile
= getFlag( nFlags
, BIFF12_CONNECTION_ONLYUSECONNFILE
);
213 maModel
.mbBackground
= getFlag( nFlags
, BIFF12_CONNECTION_BACKGROUND
);
214 maModel
.mbRefreshOnLoad
= getFlag( nFlags
, BIFF12_CONNECTION_REFRESHONLOAD
);
215 maModel
.mbSaveData
= getFlag( nFlags
, BIFF12_CONNECTION_SAVEDATA
);
216 maModel
.mbSavePassword
= nSavePassword
== BIFF12_CONNECTION_SAVEPASSWORD_ON
;
219 void Connection::importWebPr( SequenceInputStream
& rStrm
)
221 WebPrModel
& rWebPr
= maModel
.createWebPr();
225 nFlags
= rStrm
.readuInt32();
226 nStrFlags
= rStrm
.readuChar();
228 if( getFlag( nStrFlags
, BIFF12_WEBPR_HAS_URL
) )
229 rStrm
>> rWebPr
.maUrl
;
230 if( getFlag( nStrFlags
, BIFF12_WEBPR_HAS_POSTMETHOD
) )
231 rStrm
>> rWebPr
.maPostMethod
;
232 if( getFlag( nStrFlags
, BIFF12_WEBPR_HAS_EDITPAGE
) )
233 rStrm
>> rWebPr
.maEditPage
;
235 static const sal_Int32 spnHmlFormats
[] = { XML_none
, XML_rtf
, XML_all
};
236 rWebPr
.mnHtmlFormat
= STATIC_ARRAY_SELECT( spnHmlFormats
, extractValue
< sal_uInt8
>( nFlags
, 0, 8 ), XML_none
);
238 rWebPr
.mbXml
= getFlag( nFlags
, BIFF12_WEBPR_XML
);
239 rWebPr
.mbSourceData
= getFlag( nFlags
, BIFF12_WEBPR_SOURCEDATA
);
240 rWebPr
.mbParsePre
= getFlag( nFlags
, BIFF12_WEBPR_PARSEPRE
);
241 rWebPr
.mbConsecutive
= getFlag( nFlags
, BIFF12_WEBPR_CONSECUTIVE
);
242 rWebPr
.mbFirstRow
= getFlag( nFlags
, BIFF12_WEBPR_FIRSTROW
);
243 rWebPr
.mbXl97Created
= getFlag( nFlags
, BIFF12_WEBPR_XL97CREATED
);
244 rWebPr
.mbTextDates
= getFlag( nFlags
, BIFF12_WEBPR_TEXTDATES
);
245 rWebPr
.mbXl2000Refreshed
= getFlag( nFlags
, BIFF12_WEBPR_XL2000REFRESHED
);
246 rWebPr
.mbHtmlTables
= getFlag( nFlags
, BIFF12_WEBPR_HTMLTABLES
);
249 void Connection::importWebPrTables( SequenceInputStream
& /*rStrm*/ )
251 if( maModel
.mxWebPr
.get() )
253 OSL_ENSURE( maModel
.mxWebPr
->maTables
.empty(), "Connection::importWebPrTables - multiple calls" );
254 maModel
.mxWebPr
->maTables
.clear();
258 void Connection::importWebPrTable( SequenceInputStream
& rStrm
, sal_Int32 nRecId
)
260 if( maModel
.mxWebPr
.get() )
265 case BIFF12_ID_PCITEM_MISSING
: break;
266 case BIFF12_ID_PCITEM_STRING
: aTableAny
<<= BiffHelper::readString( rStrm
); break;
267 case BIFF12_ID_PCITEM_INDEX
: aTableAny
<<= rStrm
.readInt32(); break;
269 OSL_ENSURE( false, "Connection::importWebPrTable - unexpected record" );
272 maModel
.mxWebPr
->maTables
.push_back( aTableAny
);
276 ConnectionsBuffer::ConnectionsBuffer( const WorkbookHelper
& rHelper
) :
277 WorkbookHelper( rHelper
),
282 Connection
& ConnectionsBuffer::createConnection()
284 ConnectionRef
xConnection( new Connection( *this ) );
285 maConnections
.push_back( xConnection
);
289 void ConnectionsBuffer::finalizeImport()
291 for( ConnectionVector::iterator aIt
= maConnections
.begin(), aEnd
= maConnections
.end(); aIt
!= aEnd
; ++aIt
)
292 insertConnectionToMap( *aIt
);
295 ConnectionRef
ConnectionsBuffer::getConnection( sal_Int32 nConnId
) const
297 return maConnectionsById
.get( nConnId
);
300 void ConnectionsBuffer::insertConnectionToMap( const ConnectionRef
& rxConnection
)
302 sal_Int32 nConnId
= rxConnection
->getConnectionId();
305 OSL_ENSURE( !maConnectionsById
.has( nConnId
), "ConnectionsBuffer::insertConnectionToMap - multiple connection identifier" );
306 maConnectionsById
[ nConnId
] = rxConnection
;
307 mnUnusedId
= ::std::max
< sal_Int32
>( mnUnusedId
, nConnId
+ 1 );
314 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */