Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / sc / source / filter / oox / tablecolumnsbuffer.cxx
blob1cbb502052684cd28e5a39c2931539f17cb126bf
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 #include "tablecolumnsbuffer.hxx"
22 #include <com/sun/star/sheet/XDatabaseRange.hpp>
23 #include <rtl/ustrbuf.hxx>
24 #include <osl/diagnose.h>
25 #include <oox/helper/attributelist.hxx>
26 #include <oox/helper/containerhelper.hxx>
27 #include <oox/helper/propertyset.hxx>
28 #include <oox/token/properties.hxx>
29 #include <oox/token/tokens.hxx>
30 #include "addressconverter.hxx"
31 #include "biffinputstream.hxx"
32 #include "defnamesbuffer.hxx"
33 #include "dbdata.hxx"
35 namespace oox {
36 namespace xls {
38 using namespace ::com::sun::star::sheet;
39 using namespace ::com::sun::star::table;
40 using namespace ::com::sun::star::uno;
42 TableColumn::TableColumn( const WorkbookHelper& rHelper ) :
43 WorkbookHelper( rHelper ),
44 mnId( -1 ),
45 mnDataDxfId( -1 )
49 void TableColumn::importTableColumn( const AttributeList& rAttribs )
51 mnId = rAttribs.getInteger( XML_id, -1 );
52 maName = rAttribs.getString( XML_name, OUString() );
53 mnDataDxfId = rAttribs.getInteger( XML_dataDxfId, -1 );
56 void TableColumn::importTableColumn( SequenceInputStream& /*rStrm*/ )
58 /* XXX not implemented */
59 (void) mnId;
62 const OUString& TableColumn::getName() const
64 return maName;
67 TableColumns::TableColumns( const WorkbookHelper& rHelper ) :
68 WorkbookHelper( rHelper ),
69 mnCount(0)
73 void TableColumns::importTableColumns( const AttributeList& rAttribs )
75 mnCount = rAttribs.getInteger( XML_count, 0 );
78 void TableColumns::importTableColumns( SequenceInputStream& /*rStrm*/ )
80 /* XXX not implemented */
81 (void) mnCount;
84 TableColumn& TableColumns::createTableColumn()
86 TableColumnVector::value_type xTableColumn( new TableColumn( *this ) );
87 maTableColumnVector.push_back( xTableColumn );
88 return *xTableColumn;
91 bool TableColumns::finalizeImport( ScDBData* pDBData )
93 SAL_WARN_IF( static_cast<size_t>(mnCount) != maTableColumnVector.size(), "sc.filter",
94 "TableColumns::finalizeImport - count attribute doesn't match number of tableColumn elements");
95 if ( pDBData )
97 /* TODO: use svl::SharedString for names */
98 ::std::vector< OUString > aNames( maTableColumnVector.size());
99 size_t i = 0;
100 for (TableColumnVector::const_iterator aIt = maTableColumnVector.begin(), aEnd = maTableColumnVector.end();
101 aIt != aEnd; ++aIt, ++i)
103 aNames[i] = (*aIt)->getName();
105 pDBData->SetTableColumnNames( aNames);
106 return true;
108 return false;
111 TableColumnsBuffer::TableColumnsBuffer( const WorkbookHelper& rHelper ) :
112 WorkbookHelper( rHelper )
116 TableColumns& TableColumnsBuffer::createTableColumns()
118 TableColumnsVector::value_type xTableColumns( new TableColumns( *this ) );
119 maTableColumnsVector.push_back( xTableColumns );
120 return *xTableColumns;
123 void TableColumnsBuffer::finalizeImport( ScDBData* pDBData )
125 TableColumns* pTableColumns = getActiveTableColumns();
126 if ( pTableColumns )
127 pTableColumns->finalizeImport( pDBData );
130 TableColumns* TableColumnsBuffer::getActiveTableColumns()
132 // not more than one table columns descriptor per table
133 SAL_WARN_IF( maTableColumnsVector.size() > 1, "sc.filter",
134 "TableColumnsBuffer::getActiveTableColumns - too many table columns" );
135 // stick to the last imported table columns
136 return maTableColumnsVector.empty() ? nullptr : maTableColumnsVector.back().get();
139 } // namespace xls
140 } // namespace oox
142 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */