Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / sc / source / filter / inc / connectionsbuffer.hxx
blob95eec918911e1a0c9dffab2a65b80da799714c11
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <memory>
24 #include <oox/helper/refvector.hxx>
25 #include "workbookhelper.hxx"
27 namespace oox { class AttributeList; }
28 namespace oox { class SequenceInputStream; }
30 namespace oox {
31 namespace xls {
33 const sal_Int32 BIFF12_CONNECTION_UNKNOWN = 0;
34 const sal_Int32 BIFF12_CONNECTION_ODBC = 1;
35 const sal_Int32 BIFF12_CONNECTION_DAO = 2;
36 const sal_Int32 BIFF12_CONNECTION_FILE = 3;
37 const sal_Int32 BIFF12_CONNECTION_HTML = 4;
38 const sal_Int32 BIFF12_CONNECTION_OLEDB = 5;
39 const sal_Int32 BIFF12_CONNECTION_TEXT = 6;
40 const sal_Int32 BIFF12_CONNECTION_ADO = 7;
41 const sal_Int32 BIFF12_CONNECTION_DSP = 8;
43 /** Special properties for data connections representing web queries. */
44 struct WebPrModel
46 typedef ::std::vector< css::uno::Any > TablesVector;
48 TablesVector maTables; /// Names or indexes of the web query tables.
49 OUString maUrl; /// Source URL to refresh the data.
50 OUString maPostMethod; /// POST method to query data.
51 OUString maEditPage; /// Web page showing query data (for XML queries).
52 sal_Int32 mnHtmlFormat; /// Plain text, rich text, or HTML.
53 bool mbXml; /// True = XML query, false = HTML query.
54 bool mbSourceData; /// True = import XML source data referred by HTML table.
55 bool mbParsePre; /// True = parse preformatted sections (<pre> tag).
56 bool mbConsecutive; /// True = join consecutive delimiters.
57 bool mbFirstRow; /// True = use column widths of first row for entire <pre> tag.
58 bool mbXl97Created; /// True = web query created with Excel 97.
59 bool mbTextDates; /// True = read date values as text, false = parse dates.
60 bool mbXl2000Refreshed; /// True = refreshed with Excel 2000 or newer.
61 bool mbHtmlTables; /// True = HTML tables, false = entire document.
63 explicit WebPrModel();
66 /** Common properties of an external data connection. */
67 struct ConnectionModel
69 typedef ::std::unique_ptr< WebPrModel > WebPrModelPtr;
71 WebPrModelPtr mxWebPr; /// Special settings for web queries.
72 OUString maName; /// Unique name of this connection.
73 OUString maDescription; /// User description of this connection.
74 OUString maSourceFile; /// URL of a source data file.
75 OUString maSourceConnFile; /// URL of a source connection file.
76 OUString maSsoId; /// Single sign-on identifier.
77 sal_Int32 mnId; /// Unique connection identifier.
78 sal_Int32 mnType; /// Data source type.
79 sal_Int32 mnReconnectMethod; /// Reconnection method.
80 sal_Int32 mnCredentials; /// Credentials method.
81 sal_Int32 mnInterval; /// Refresh interval in minutes.
82 bool mbKeepAlive; /// True = keep connection open after import.
83 bool mbNew; /// True = new connection, never updated.
84 bool mbDeleted; /// True = connection has been deleted.
85 bool mbOnlyUseConnFile; /// True = use maSourceConnFile, ignore mnReconnectMethod.
86 bool mbBackground; /// True = background refresh enabled.
87 bool mbRefreshOnLoad; /// True = refresh connection on import.
88 bool mbSaveData; /// True = save cached data with connection.
89 bool mbSavePassword; /// True = save password in connection string.
91 explicit ConnectionModel();
93 WebPrModel& createWebPr();
96 /** An external data connection (database, web query, etc.). */
97 class Connection : public WorkbookHelper
99 public:
100 explicit Connection( const WorkbookHelper& rHelper );
102 /** Imports connection settings from the connection element. */
103 void importConnection( const AttributeList& rAttribs );
104 /** Imports web query settings from the webPr element. */
105 void importWebPr( const AttributeList& rAttribs );
106 /** Imports web query table settings from the tables element. */
107 void importTables();
108 /** Imports a web query table identifier from the m, s, or x element. */
109 void importTable( const AttributeList& rAttribs, sal_Int32 nElement );
111 /** Imports connection settings from the CONNECTION record. */
112 void importConnection( SequenceInputStream& rStrm );
113 /** Imports web query settings from the WEBPR record. */
114 void importWebPr( SequenceInputStream& rStrm );
115 /** Imports web query table settings from the WEBPRTABLES record. */
116 void importWebPrTables( SequenceInputStream& rStrm );
117 /** Imports a web query table identifier from the PCITEM_MISSING, PCITEM_STRING, or PCITEM_INDEX record. */
118 void importWebPrTable( SequenceInputStream& rStrm, sal_Int32 nRecId );
120 /** Returns the unique connection identifier. */
121 sal_Int32 getConnectionId() const { return maModel.mnId; }
122 /** Returns the source data type of the connection. */
123 sal_Int32 getConnectionType() const { return maModel.mnType; }
124 /** Returns read-only access to the connection model data. */
125 const ConnectionModel& getModel() const { return maModel; }
127 private:
128 ConnectionModel maModel;
131 typedef std::shared_ptr< Connection > ConnectionRef;
133 class ConnectionsBuffer : public WorkbookHelper
135 public:
136 explicit ConnectionsBuffer( const WorkbookHelper& rHelper );
138 /** Creates a new empty connection. */
139 Connection& createConnection();
141 /** Maps all connections by their identifier. */
142 void finalizeImport();
144 /** Returns a data connection by its unique identifier. */
145 ConnectionRef getConnection( sal_Int32 nConnId ) const;
147 private:
148 /** Inserts the passed connection into the map according to its identifier. */
149 void insertConnectionToMap( const ConnectionRef& rxConnection );
151 private:
152 typedef RefVector< Connection > ConnectionVector;
153 typedef RefMap< sal_Int32, Connection > ConnectionMap;
155 ConnectionVector maConnections;
156 ConnectionMap maConnectionsById;
157 sal_Int32 mnUnusedId;
160 } // namespace xls
161 } // namespace oox
163 #endif
165 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */