Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef OOX_XLS_CONNECTIONSBUFFER_HXX
21 : #define OOX_XLS_CONNECTIONSBUFFER_HXX
22 :
23 : #include "oox/helper/refvector.hxx"
24 : #include "workbookhelper.hxx"
25 :
26 : namespace oox {
27 : namespace xls {
28 :
29 : // ============================================================================
30 :
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;
40 :
41 : // ============================================================================
42 :
43 : /** Special properties for data connections representing web queries. */
44 0 : struct WebPrModel
45 : {
46 : typedef ::std::vector< ::com::sun::star::uno::Any > TablesVector;
47 :
48 : TablesVector maTables; /// Names or indexes of the web query tables.
49 : ::rtl::OUString maUrl; /// Source URL to refresh the data.
50 : ::rtl::OUString maPostMethod; /// POST method to query data.
51 : ::rtl::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 withs 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.
62 :
63 : explicit WebPrModel();
64 : };
65 :
66 : // ----------------------------------------------------------------------------
67 :
68 : /** Common properties of an external data connection. */
69 0 : struct ConnectionModel
70 : {
71 : typedef ::std::auto_ptr< WebPrModel > WebPrModelPtr;
72 :
73 : WebPrModelPtr mxWebPr; /// Special settings for web queries.
74 : ::rtl::OUString maName; /// Unique name of this connection.
75 : ::rtl::OUString maDescription; /// User description of this connection.
76 : ::rtl::OUString maSourceFile; /// URL of a source data file.
77 : ::rtl::OUString maSourceConnFile; /// URL of a source connection file.
78 : ::rtl::OUString maSsoId; /// Single sign-on identifier.
79 : sal_Int32 mnId; /// Unique connection identifier.
80 : sal_Int32 mnType; /// Data source type.
81 : sal_Int32 mnReconnectMethod; /// Reconnection method.
82 : sal_Int32 mnCredentials; /// Credentials method.
83 : sal_Int32 mnInterval; /// Refresh interval in minutes.
84 : bool mbKeepAlive; /// True = keep connection open after import.
85 : bool mbNew; /// True = new connection, never updated.
86 : bool mbDeleted; /// True = connection has been deleted.
87 : bool mbOnlyUseConnFile; /// True = use maSourceConnFile, ignore mnReconnectMethod.
88 : bool mbBackground; /// True = background refresh enabled.
89 : bool mbRefreshOnLoad; /// True = refresh connection on import.
90 : bool mbSaveData; /// True = save cached data with connection.
91 : bool mbSavePassword; /// True = save password in connection string.
92 :
93 : explicit ConnectionModel();
94 :
95 : WebPrModel& createWebPr();
96 : };
97 :
98 : // ----------------------------------------------------------------------------
99 :
100 : /** An external data connection (database, web query, etc.). */
101 0 : class Connection : public WorkbookHelper
102 : {
103 : public:
104 : explicit Connection( const WorkbookHelper& rHelper, sal_Int32 nConnId = -1 );
105 :
106 : /** Imports connection settings from the connection element. */
107 : void importConnection( const AttributeList& rAttribs );
108 : /** Imports web query settings from the webPr element. */
109 : void importWebPr( const AttributeList& rAttribs );
110 : /** Imports web query table settings from the tables element. */
111 : void importTables( const AttributeList& rAttribs );
112 : /** Imports a web query table identifier from the m, s, or x element. */
113 : void importTable( const AttributeList& rAttribs, sal_Int32 nElement );
114 :
115 : /** Imports connection settings from the CONNECTION record. */
116 : void importConnection( SequenceInputStream& rStrm );
117 : /** Imports web query settings from the WEBPR record. */
118 : void importWebPr( SequenceInputStream& rStrm );
119 : /** Imports web query table settings from the WEBPRTABLES record. */
120 : void importWebPrTables( SequenceInputStream& rStrm );
121 : /** Imports a web query table identifier from the PCITEM_MISSING, PCITEM_STRING, or PCITEM_INDEX record. */
122 : void importWebPrTable( SequenceInputStream& rStrm, sal_Int32 nRecId );
123 :
124 : /** Returns the unique connection identifier. */
125 0 : inline sal_Int32 getConnectionId() const { return maModel.mnId; }
126 : /** Returns the source data type of the connection. */
127 0 : inline sal_Int32 getConnectionType() const { return maModel.mnType; }
128 : /** Returns read-only access to the connection model data. */
129 0 : const ConnectionModel& getModel() const { return maModel; }
130 :
131 : private:
132 : ConnectionModel maModel;
133 : };
134 :
135 : typedef ::boost::shared_ptr< Connection > ConnectionRef;
136 :
137 : // ============================================================================
138 :
139 22 : class ConnectionsBuffer : public WorkbookHelper
140 : {
141 : public:
142 : explicit ConnectionsBuffer( const WorkbookHelper& rHelper );
143 :
144 : /** Creates a new empty connection. */
145 : Connection& createConnection();
146 :
147 : /** Maps all connections by their identifier. */
148 : void finalizeImport();
149 :
150 : /** Returns a data connection by its unique identifier. */
151 : ConnectionRef getConnection( sal_Int32 nConnId ) const;
152 :
153 : private:
154 : /** Inserts the passed connection into the map according to its identifier. */
155 : void insertConnectionToMap( const ConnectionRef& rxConnection );
156 :
157 : private:
158 : typedef RefVector< Connection > ConnectionVector;
159 : typedef RefMap< sal_Int32, Connection > ConnectionMap;
160 :
161 : ConnectionVector maConnections;
162 : ConnectionMap maConnectionsById;
163 : sal_Int32 mnUnusedId;
164 : };
165 :
166 : // ============================================================================
167 :
168 : } // namespace xls
169 : } // namespace oox
170 :
171 : #endif
172 :
173 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|