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