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>
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>
31 using namespace ::com::sun::star::uno
;
35 const sal_Int32 BIFF12_RECONNECT_AS_REQUIRED
= 1;
37 const sal_uInt8 BIFF12_CONNECTION_SAVEPASSWORD_ON
= 1;
39 const sal_uInt16 BIFF12_CONNECTION_KEEPALIVE
= 0x0001;
40 const sal_uInt16 BIFF12_CONNECTION_NEW
= 0x0002;
41 const sal_uInt16 BIFF12_CONNECTION_DELETED
= 0x0004;
42 const sal_uInt16 BIFF12_CONNECTION_ONLYUSECONNFILE
= 0x0008;
43 const sal_uInt16 BIFF12_CONNECTION_BACKGROUND
= 0x0010;
44 const sal_uInt16 BIFF12_CONNECTION_REFRESHONLOAD
= 0x0020;
45 const sal_uInt16 BIFF12_CONNECTION_SAVEDATA
= 0x0040;
47 const sal_uInt16 BIFF12_CONNECTION_HAS_SOURCEFILE
= 0x0001;
48 const sal_uInt16 BIFF12_CONNECTION_HAS_SOURCECONNFILE
= 0x0002;
49 const sal_uInt16 BIFF12_CONNECTION_HAS_DESCRIPTION
= 0x0004;
50 const sal_uInt16 BIFF12_CONNECTION_HAS_NAME
= 0x0008;
51 const sal_uInt16 BIFF12_CONNECTION_HAS_SSOID
= 0x0010;
53 const sal_uInt32 BIFF12_WEBPR_XML
= 0x00000100;
54 const sal_uInt32 BIFF12_WEBPR_SOURCEDATA
= 0x00000200;
55 const sal_uInt32 BIFF12_WEBPR_PARSEPRE
= 0x00000400;
56 const sal_uInt32 BIFF12_WEBPR_CONSECUTIVE
= 0x00000800;
57 const sal_uInt32 BIFF12_WEBPR_FIRSTROW
= 0x00001000;
58 const sal_uInt32 BIFF12_WEBPR_XL97CREATED
= 0x00002000;
59 const sal_uInt32 BIFF12_WEBPR_TEXTDATES
= 0x00004000;
60 const sal_uInt32 BIFF12_WEBPR_XL2000REFRESHED
= 0x00008000;
61 const sal_uInt32 BIFF12_WEBPR_HTMLTABLES
= 0x00010000;
63 const sal_uInt8 BIFF12_WEBPR_HAS_POSTMETHOD
= 0x01;
64 const sal_uInt8 BIFF12_WEBPR_HAS_EDITPAGE
= 0x02;
65 const sal_uInt8 BIFF12_WEBPR_HAS_URL
= 0x04;
69 WebPrModel::WebPrModel() :
70 mnHtmlFormat( XML_none
),
72 mbSourceData( false ),
74 mbConsecutive( false ),
76 mbXl97Created( false ),
78 mbXl2000Refreshed( false ),
83 ConnectionModel::ConnectionModel() :
85 mnType( BIFF12_CONNECTION_UNKNOWN
),
86 mnReconnectMethod( BIFF12_RECONNECT_AS_REQUIRED
),
87 mnCredentials( XML_integrated
),
92 mbOnlyUseConnFile( false ),
93 mbBackground( false ),
94 mbRefreshOnLoad( false ),
96 mbSavePassword( false )
100 WebPrModel
& ConnectionModel::createWebPr()
102 OSL_ENSURE( !mxWebPr
, "ConnectionModel::createWebPr - multiple call" );
103 mxWebPr
.reset( new WebPrModel
);
107 Connection::Connection( const WorkbookHelper
& rHelper
) :
108 WorkbookHelper( rHelper
)
113 void Connection::importConnection( const AttributeList
& rAttribs
)
115 maModel
.maName
= rAttribs
.getXString( XML_name
, OUString() );
116 maModel
.maDescription
= rAttribs
.getXString( XML_description
, OUString() );
117 maModel
.maSourceFile
= rAttribs
.getXString( XML_sourceFile
, OUString() );
118 maModel
.maSourceConnFile
= rAttribs
.getXString( XML_odcFile
, OUString() );
119 maModel
.maSsoId
= rAttribs
.getXString( XML_singleSignOnId
, OUString() );
120 maModel
.mnId
= rAttribs
.getInteger( XML_id
, -1 );
121 // type and reconnectionMethod are using the BIFF12 constants instead of XML tokens
122 maModel
.mnType
= rAttribs
.getInteger( XML_type
, BIFF12_CONNECTION_UNKNOWN
);
123 maModel
.mnReconnectMethod
= rAttribs
.getInteger( XML_reconnectionMethod
, BIFF12_RECONNECT_AS_REQUIRED
);
124 maModel
.mnCredentials
= rAttribs
.getToken( XML_credentials
, XML_integrated
);
125 maModel
.mnInterval
= rAttribs
.getInteger( XML_interval
, 0 );
126 maModel
.mbKeepAlive
= rAttribs
.getBool( XML_keepAlive
, false );
127 maModel
.mbNew
= rAttribs
.getBool( XML_new
, false );
128 maModel
.mbDeleted
= rAttribs
.getBool( XML_deleted
, false );
129 maModel
.mbOnlyUseConnFile
= rAttribs
.getBool( XML_onlyUseConnectionFile
, false );
130 maModel
.mbBackground
= rAttribs
.getBool( XML_background
, false );
131 maModel
.mbRefreshOnLoad
= rAttribs
.getBool( XML_refreshOnLoad
, false );
132 maModel
.mbSaveData
= rAttribs
.getBool( XML_saveData
, false );
133 maModel
.mbSavePassword
= rAttribs
.getBool( XML_savePassword
, false );
136 void Connection::importWebPr( const AttributeList
& rAttribs
)
138 WebPrModel
& rWebPr
= maModel
.createWebPr();
140 rWebPr
.maUrl
= rAttribs
.getXString( XML_url
, OUString() );
141 rWebPr
.maPostMethod
= rAttribs
.getXString( XML_post
, OUString() );
142 rWebPr
.maEditPage
= rAttribs
.getXString( XML_editPage
, OUString() );
143 rWebPr
.mnHtmlFormat
= rAttribs
.getToken( XML_htmlFormat
, XML_none
);
144 rWebPr
.mbXml
= rAttribs
.getBool( XML_xml
, false );
145 rWebPr
.mbSourceData
= rAttribs
.getBool( XML_sourceData
, false );
146 rWebPr
.mbParsePre
= rAttribs
.getBool( XML_parsePre
, false );
147 rWebPr
.mbConsecutive
= rAttribs
.getBool( XML_consecutive
, false );
148 rWebPr
.mbFirstRow
= rAttribs
.getBool( XML_firstRow
, false );
149 rWebPr
.mbXl97Created
= rAttribs
.getBool( XML_xl97
, false );
150 rWebPr
.mbTextDates
= rAttribs
.getBool( XML_textDates
, false );
151 rWebPr
.mbXl2000Refreshed
= rAttribs
.getBool( XML_xl2000
, false );
152 rWebPr
.mbHtmlTables
= rAttribs
.getBool( XML_htmlTables
, false );
155 void Connection::importTables()
157 if( maModel
.mxWebPr
)
159 OSL_ENSURE( maModel
.mxWebPr
->maTables
.empty(), "Connection::importTables - multiple calls" );
160 maModel
.mxWebPr
->maTables
.clear();
164 void Connection::importTable( const AttributeList
& rAttribs
, sal_Int32 nElement
)
166 if( !maModel
.mxWebPr
)
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;
176 OSL_ENSURE( false, "Connection::importTable - unexpected element" );
179 maModel
.mxWebPr
->maTables
.push_back( aTableAny
);
182 void Connection::importConnection( SequenceInputStream
& rStrm
)
184 sal_uInt16 nFlags
, nStrFlags
;
185 sal_uInt8 nSavePassword
, nCredentials
;
187 nSavePassword
= rStrm
.readuChar();
189 maModel
.mnInterval
= rStrm
.readuInt16();
190 nFlags
= rStrm
.readuInt16();
191 nStrFlags
= rStrm
.readuInt16();
192 maModel
.mnType
= rStrm
.readInt32();
193 maModel
.mnReconnectMethod
= rStrm
.readInt32();
194 maModel
.mnId
= rStrm
.readInt32();
195 nCredentials
= rStrm
.readuChar();
197 if( getFlag( nStrFlags
, BIFF12_CONNECTION_HAS_SOURCEFILE
) )
198 rStrm
>> maModel
.maSourceFile
;
199 if( getFlag( nStrFlags
, BIFF12_CONNECTION_HAS_SOURCECONNFILE
) )
200 rStrm
>> maModel
.maSourceConnFile
;
201 if( getFlag( nStrFlags
, BIFF12_CONNECTION_HAS_DESCRIPTION
) )
202 rStrm
>> maModel
.maDescription
;
203 if( getFlag( nStrFlags
, BIFF12_CONNECTION_HAS_NAME
) )
204 rStrm
>> maModel
.maName
;
205 if( getFlag( nStrFlags
, BIFF12_CONNECTION_HAS_SSOID
) )
206 rStrm
>> maModel
.maSsoId
;
208 static const sal_Int32 spnCredentials
[] = { XML_integrated
, XML_none
, XML_stored
, XML_prompt
};
209 maModel
.mnCredentials
= STATIC_ARRAY_SELECT( spnCredentials
, nCredentials
, XML_integrated
);
211 maModel
.mbKeepAlive
= getFlag( nFlags
, BIFF12_CONNECTION_KEEPALIVE
);
212 maModel
.mbNew
= getFlag( nFlags
, BIFF12_CONNECTION_NEW
);
213 maModel
.mbDeleted
= getFlag( nFlags
, BIFF12_CONNECTION_DELETED
);
214 maModel
.mbOnlyUseConnFile
= getFlag( nFlags
, BIFF12_CONNECTION_ONLYUSECONNFILE
);
215 maModel
.mbBackground
= getFlag( nFlags
, BIFF12_CONNECTION_BACKGROUND
);
216 maModel
.mbRefreshOnLoad
= getFlag( nFlags
, BIFF12_CONNECTION_REFRESHONLOAD
);
217 maModel
.mbSaveData
= getFlag( nFlags
, BIFF12_CONNECTION_SAVEDATA
);
218 maModel
.mbSavePassword
= nSavePassword
== BIFF12_CONNECTION_SAVEPASSWORD_ON
;
221 void Connection::importWebPr( SequenceInputStream
& rStrm
)
223 WebPrModel
& rWebPr
= maModel
.createWebPr();
227 nFlags
= rStrm
.readuInt32();
228 nStrFlags
= rStrm
.readuChar();
230 if( getFlag( nStrFlags
, BIFF12_WEBPR_HAS_URL
) )
231 rStrm
>> rWebPr
.maUrl
;
232 if( getFlag( nStrFlags
, BIFF12_WEBPR_HAS_POSTMETHOD
) )
233 rStrm
>> rWebPr
.maPostMethod
;
234 if( getFlag( nStrFlags
, BIFF12_WEBPR_HAS_EDITPAGE
) )
235 rStrm
>> rWebPr
.maEditPage
;
237 static const sal_Int32 spnHmlFormats
[] = { XML_none
, XML_rtf
, XML_all
};
238 rWebPr
.mnHtmlFormat
= STATIC_ARRAY_SELECT( spnHmlFormats
, extractValue
< sal_uInt8
>( nFlags
, 0, 8 ), XML_none
);
240 rWebPr
.mbXml
= getFlag( nFlags
, BIFF12_WEBPR_XML
);
241 rWebPr
.mbSourceData
= getFlag( nFlags
, BIFF12_WEBPR_SOURCEDATA
);
242 rWebPr
.mbParsePre
= getFlag( nFlags
, BIFF12_WEBPR_PARSEPRE
);
243 rWebPr
.mbConsecutive
= getFlag( nFlags
, BIFF12_WEBPR_CONSECUTIVE
);
244 rWebPr
.mbFirstRow
= getFlag( nFlags
, BIFF12_WEBPR_FIRSTROW
);
245 rWebPr
.mbXl97Created
= getFlag( nFlags
, BIFF12_WEBPR_XL97CREATED
);
246 rWebPr
.mbTextDates
= getFlag( nFlags
, BIFF12_WEBPR_TEXTDATES
);
247 rWebPr
.mbXl2000Refreshed
= getFlag( nFlags
, BIFF12_WEBPR_XL2000REFRESHED
);
248 rWebPr
.mbHtmlTables
= getFlag( nFlags
, BIFF12_WEBPR_HTMLTABLES
);
251 void Connection::importWebPrTables( SequenceInputStream
& /*rStrm*/ )
253 if( maModel
.mxWebPr
)
255 OSL_ENSURE( maModel
.mxWebPr
->maTables
.empty(), "Connection::importWebPrTables - multiple calls" );
256 maModel
.mxWebPr
->maTables
.clear();
260 void Connection::importWebPrTable( SequenceInputStream
& rStrm
, sal_Int32 nRecId
)
262 if( !maModel
.mxWebPr
)
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;
272 OSL_ENSURE( false, "Connection::importWebPrTable - unexpected record" );
275 maModel
.mxWebPr
->maTables
.push_back( aTableAny
);
278 ConnectionsBuffer::ConnectionsBuffer( const WorkbookHelper
& rHelper
) :
279 WorkbookHelper( rHelper
),
284 Connection
& ConnectionsBuffer::createConnection()
286 ConnectionRef xConnection
= std::make_shared
<Connection
>( *this );
287 maConnections
.push_back( xConnection
);
291 void ConnectionsBuffer::finalizeImport()
293 for( const auto& rxConnection
: maConnections
)
294 insertConnectionToMap( rxConnection
);
297 ConnectionRef
ConnectionsBuffer::getConnection( sal_Int32 nConnId
) const
299 return maConnectionsById
.get( nConnId
);
302 void ConnectionsBuffer::insertConnectionToMap( const ConnectionRef
& rxConnection
)
304 sal_Int32 nConnId
= rxConnection
->getConnectionId();
307 OSL_ENSURE( !maConnectionsById
.has( nConnId
), "ConnectionsBuffer::insertConnectionToMap - multiple connection identifier" );
308 maConnectionsById
[ nConnId
] = rxConnection
;
309 mnUnusedId
= ::std::max
< sal_Int32
>( mnUnusedId
, nConnId
+ 1 );
313 } // namespace oox::xls
315 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */