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 #ifndef INCLUDED_SC_SOURCE_FILTER_INC_CONNECTIONSBUFFER_HXX
21 #define INCLUDED_SC_SOURCE_FILTER_INC_CONNECTIONSBUFFER_HXX
23 #include <oox/helper/refvector.hxx>
24 #include "workbookhelper.hxx"
29 const sal_Int32 BIFF12_CONNECTION_UNKNOWN
= 0;
30 const sal_Int32 BIFF12_CONNECTION_ODBC
= 1;
31 const sal_Int32 BIFF12_CONNECTION_DAO
= 2;
32 const sal_Int32 BIFF12_CONNECTION_FILE
= 3;
33 const sal_Int32 BIFF12_CONNECTION_HTML
= 4;
34 const sal_Int32 BIFF12_CONNECTION_OLEDB
= 5;
35 const sal_Int32 BIFF12_CONNECTION_TEXT
= 6;
36 const sal_Int32 BIFF12_CONNECTION_ADO
= 7;
37 const sal_Int32 BIFF12_CONNECTION_DSP
= 8;
39 /** Special properties for data connections representing web queries. */
42 typedef ::std::vector
< ::com::sun::star::uno::Any
> TablesVector
;
44 TablesVector maTables
; /// Names or indexes of the web query tables.
45 OUString maUrl
; /// Source URL to refresh the data.
46 OUString maPostMethod
; /// POST method to query data.
47 OUString maEditPage
; /// Web page showing query data (for XML queries).
48 sal_Int32 mnHtmlFormat
; /// Plain text, rich text, or HTML.
49 bool mbXml
; /// True = XML query, false = HTML query.
50 bool mbSourceData
; /// True = import XML source data referred by HTML table.
51 bool mbParsePre
; /// True = parse preformatted sections (<pre> tag).
52 bool mbConsecutive
; /// True = join consecutive delimiters.
53 bool mbFirstRow
; /// True = use column withs of first row for entire <pre> tag.
54 bool mbXl97Created
; /// True = web query created with Excel 97.
55 bool mbTextDates
; /// True = read date values as text, false = parse dates.
56 bool mbXl2000Refreshed
; /// True = refreshed with Excel 2000 or newer.
57 bool mbHtmlTables
; /// True = HTML tables, false = entire document.
59 explicit WebPrModel();
62 /** Common properties of an external data connection. */
63 struct ConnectionModel
65 typedef ::std::unique_ptr
< WebPrModel
> WebPrModelPtr
;
67 WebPrModelPtr mxWebPr
; /// Special settings for web queries.
68 OUString maName
; /// Unique name of this connection.
69 OUString maDescription
; /// User description of this connection.
70 OUString maSourceFile
; /// URL of a source data file.
71 OUString maSourceConnFile
; /// URL of a source connection file.
72 OUString maSsoId
; /// Single sign-on identifier.
73 sal_Int32 mnId
; /// Unique connection identifier.
74 sal_Int32 mnType
; /// Data source type.
75 sal_Int32 mnReconnectMethod
; /// Reconnection method.
76 sal_Int32 mnCredentials
; /// Credentials method.
77 sal_Int32 mnInterval
; /// Refresh interval in minutes.
78 bool mbKeepAlive
; /// True = keep connection open after import.
79 bool mbNew
; /// True = new connection, never updated.
80 bool mbDeleted
; /// True = connection has been deleted.
81 bool mbOnlyUseConnFile
; /// True = use maSourceConnFile, ignore mnReconnectMethod.
82 bool mbBackground
; /// True = background refresh enabled.
83 bool mbRefreshOnLoad
; /// True = refresh connection on import.
84 bool mbSaveData
; /// True = save cached data with connection.
85 bool mbSavePassword
; /// True = save password in connection string.
87 explicit ConnectionModel();
89 WebPrModel
& createWebPr();
92 /** An external data connection (database, web query, etc.). */
93 class Connection
: public WorkbookHelper
96 explicit Connection( const WorkbookHelper
& rHelper
, sal_Int32 nConnId
= -1 );
98 /** Imports connection settings from the connection element. */
99 void importConnection( const AttributeList
& rAttribs
);
100 /** Imports web query settings from the webPr element. */
101 void importWebPr( const AttributeList
& rAttribs
);
102 /** Imports web query table settings from the tables element. */
103 void importTables( const AttributeList
& rAttribs
);
104 /** Imports a web query table identifier from the m, s, or x element. */
105 void importTable( const AttributeList
& rAttribs
, sal_Int32 nElement
);
107 /** Imports connection settings from the CONNECTION record. */
108 void importConnection( SequenceInputStream
& rStrm
);
109 /** Imports web query settings from the WEBPR record. */
110 void importWebPr( SequenceInputStream
& rStrm
);
111 /** Imports web query table settings from the WEBPRTABLES record. */
112 void importWebPrTables( SequenceInputStream
& rStrm
);
113 /** Imports a web query table identifier from the PCITEM_MISSING, PCITEM_STRING, or PCITEM_INDEX record. */
114 void importWebPrTable( SequenceInputStream
& rStrm
, sal_Int32 nRecId
);
116 /** Returns the unique connection identifier. */
117 inline sal_Int32
getConnectionId() const { return maModel
.mnId
; }
118 /** Returns the source data type of the connection. */
119 inline sal_Int32
getConnectionType() const { return maModel
.mnType
; }
120 /** Returns read-only access to the connection model data. */
121 const ConnectionModel
& getModel() const { return maModel
; }
124 ConnectionModel maModel
;
127 typedef std::shared_ptr
< Connection
> ConnectionRef
;
129 class ConnectionsBuffer
: public WorkbookHelper
132 explicit ConnectionsBuffer( const WorkbookHelper
& rHelper
);
134 /** Creates a new empty connection. */
135 Connection
& createConnection();
137 /** Maps all connections by their identifier. */
138 void finalizeImport();
140 /** Returns a data connection by its unique identifier. */
141 ConnectionRef
getConnection( sal_Int32 nConnId
) const;
144 /** Inserts the passed connection into the map according to its identifier. */
145 void insertConnectionToMap( const ConnectionRef
& rxConnection
);
148 typedef RefVector
< Connection
> ConnectionVector
;
149 typedef RefMap
< sal_Int32
, Connection
> ConnectionMap
;
151 ConnectionVector maConnections
;
152 ConnectionMap maConnectionsById
;
153 sal_Int32 mnUnusedId
;
161 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */