1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef OOX_XLS_CONNECTIONSBUFFER_HXX 25 #define OOX_XLS_CONNECTIONSBUFFER_HXX 26 27 #include "oox/helper/refvector.hxx" 28 #include "oox/xls/workbookhelper.hxx" 29 30 namespace oox { 31 namespace xls { 32 33 // ============================================================================ 34 35 const sal_Int32 BIFF12_CONNECTION_UNKNOWN = 0; 36 const sal_Int32 BIFF12_CONNECTION_ODBC = 1; 37 const sal_Int32 BIFF12_CONNECTION_DAO = 2; 38 const sal_Int32 BIFF12_CONNECTION_FILE = 3; 39 const sal_Int32 BIFF12_CONNECTION_HTML = 4; 40 const sal_Int32 BIFF12_CONNECTION_OLEDB = 5; 41 const sal_Int32 BIFF12_CONNECTION_TEXT = 6; 42 const sal_Int32 BIFF12_CONNECTION_ADO = 7; 43 const sal_Int32 BIFF12_CONNECTION_DSP = 8; 44 45 // ============================================================================ 46 47 /** Special properties for data connections representing web queries. */ 48 struct WebPrModel 49 { 50 typedef ::std::vector< ::com::sun::star::uno::Any > TablesVector; 51 52 TablesVector maTables; /// Names or indexes of the web query tables. 53 ::rtl::OUString maUrl; /// Source URL to refresh the data. 54 ::rtl::OUString maPostMethod; /// POST method to query data. 55 ::rtl::OUString maEditPage; /// Web page showing query data (for XML queries). 56 sal_Int32 mnHtmlFormat; /// Plain text, rich text, or HTML. 57 bool mbXml; /// True = XML query, false = HTML query. 58 bool mbSourceData; /// True = import XML source data referred by HTML table. 59 bool mbParsePre; /// True = parse preformatted sections (<pre> tag). 60 bool mbConsecutive; /// True = join consecutive delimiters. 61 bool mbFirstRow; /// True = use column withs of first row for entire <pre> tag. 62 bool mbXl97Created; /// True = web query created with Excel 97. 63 bool mbTextDates; /// True = read date values as text, false = parse dates. 64 bool mbXl2000Refreshed; /// True = refreshed with Excel 2000 or newer. 65 bool mbHtmlTables; /// True = HTML tables, false = entire document. 66 67 explicit WebPrModel(); 68 }; 69 70 // ---------------------------------------------------------------------------- 71 72 /** Common properties of an external data connection. */ 73 struct ConnectionModel 74 { 75 typedef ::std::auto_ptr< WebPrModel > WebPrModelPtr; 76 77 WebPrModelPtr mxWebPr; /// Special settings for web queries. 78 ::rtl::OUString maName; /// Unique name of this connection. 79 ::rtl::OUString maDescription; /// User description of this connection. 80 ::rtl::OUString maSourceFile; /// URL of a source data file. 81 ::rtl::OUString maSourceConnFile; /// URL of a source connection file. 82 ::rtl::OUString maSsoId; /// Single sign-on identifier. 83 sal_Int32 mnId; /// Unique connection identifier. 84 sal_Int32 mnType; /// Data source type. 85 sal_Int32 mnReconnectMethod; /// Reconnection method. 86 sal_Int32 mnCredentials; /// Credentials method. 87 sal_Int32 mnInterval; /// Refresh interval in minutes. 88 bool mbKeepAlive; /// True = keep connection open after import. 89 bool mbNew; /// True = new connection, never updated. 90 bool mbDeleted; /// True = connection has been deleted. 91 bool mbOnlyUseConnFile; /// True = use maSourceConnFile, ignore mnReconnectMethod. 92 bool mbBackground; /// True = background refresh enabled. 93 bool mbRefreshOnLoad; /// True = refresh connection on import. 94 bool mbSaveData; /// True = save cached data with connection. 95 bool mbSavePassword; /// True = save password in connection string. 96 97 explicit ConnectionModel(); 98 99 WebPrModel& createWebPr(); 100 }; 101 102 // ---------------------------------------------------------------------------- 103 104 /** An external data connection (database, web query, etc.). */ 105 class Connection : public WorkbookHelper 106 { 107 public: 108 explicit Connection( const WorkbookHelper& rHelper, sal_Int32 nConnId = -1 ); 109 110 /** Imports connection settings from the connection element. */ 111 void importConnection( const AttributeList& rAttribs ); 112 /** Imports web query settings from the webPr element. */ 113 void importWebPr( const AttributeList& rAttribs ); 114 /** Imports web query table settings from the tables element. */ 115 void importTables( const AttributeList& rAttribs ); 116 /** Imports a web query table identifier from the m, s, or x element. */ 117 void importTable( const AttributeList& rAttribs, sal_Int32 nElement ); 118 119 /** Imports connection settings from the CONNECTION record. */ 120 void importConnection( SequenceInputStream& rStrm ); 121 /** Imports web query settings from the WEBPR record. */ 122 void importWebPr( SequenceInputStream& rStrm ); 123 /** Imports web query table settings from the WEBPRTABLES record. */ 124 void importWebPrTables( SequenceInputStream& rStrm ); 125 /** Imports a web query table identifier from the PCITEM_MISSING, PCITEM_STRING, or PCITEM_INDEX record. */ 126 void importWebPrTable( SequenceInputStream& rStrm, sal_Int32 nRecId ); 127 128 /** Imports connection settings from the DBQUERY record. */ 129 void importDbQuery( BiffInputStream& rStrm ); 130 /** Imports connection settings from the QUERYTABLESETTINGS record. */ 131 void importQueryTableSettings( BiffInputStream& rStrm ); 132 133 /** Returns the unique connection identifier. */ getConnectionId() const134 inline sal_Int32 getConnectionId() const { return maModel.mnId; } 135 /** Returns the source data type of the connection. */ getConnectionType() const136 inline sal_Int32 getConnectionType() const { return maModel.mnType; } 137 /** Returns read-only access to the connection model data. */ getModel() const138 const ConnectionModel& getModel() const { return maModel; } 139 140 private: 141 ConnectionModel maModel; 142 }; 143 144 typedef ::boost::shared_ptr< Connection > ConnectionRef; 145 146 // ============================================================================ 147 148 class ConnectionsBuffer : public WorkbookHelper 149 { 150 public: 151 explicit ConnectionsBuffer( const WorkbookHelper& rHelper ); 152 153 /** Creates a new empty connection. */ 154 Connection& createConnection(); 155 /** Creates a new empty connection with a valid but unused identifier. */ 156 Connection& createConnectionWithId(); 157 158 /** Maps all connections by their identifier. */ 159 void finalizeImport(); 160 161 /** Returns a data connection by its unique identifier. */ 162 ConnectionRef getConnection( sal_Int32 nConnId ) const; 163 164 private: 165 /** Inserts the passed connection into the map according to its identifier. */ 166 void insertConnectionToMap( const ConnectionRef& rxConnection ); 167 168 private: 169 typedef RefVector< Connection > ConnectionVector; 170 typedef RefMap< sal_Int32, Connection > ConnectionMap; 171 172 ConnectionVector maConnections; 173 ConnectionMap maConnectionsById; 174 sal_Int32 mnUnusedId; 175 }; 176 177 // ============================================================================ 178 179 } // namespace xls 180 } // namespace oox 181 182 #endif 183