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