summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2015-06-24 16:19:36 +0200
committerEike Rathke <erack@redhat.com>2015-06-24 16:54:27 +0200
commit9a4881a15ca463a3fbbaee55ace2123bfdf1b132 (patch)
tree82a5110ee40c8e41b0d957881715d040d301d922
parent6055eb2ca4c3c58f2e510b92bcf57c669bd56e3f (diff)
TableRef: read <table><tableColumns><tableColumn> from OOXML
Change-Id: I46c57a14fd94738e51e65c482c903c2debe868b8
-rw-r--r--sc/Library_scfilt.mk2
-rw-r--r--sc/source/filter/inc/tablebuffer.hxx7
-rw-r--r--sc/source/filter/inc/tablecolumnsbuffer.hxx96
-rw-r--r--sc/source/filter/inc/tablecolumnscontext.hxx68
-rw-r--r--sc/source/filter/oox/tablebuffer.cxx1
-rw-r--r--sc/source/filter/oox/tablecolumnsbuffer.cxx133
-rw-r--r--sc/source/filter/oox/tablecolumnscontext.cxx94
-rw-r--r--sc/source/filter/oox/tablefragment.cxx11
8 files changed, 410 insertions, 2 deletions
diff --git a/sc/Library_scfilt.mk b/sc/Library_scfilt.mk
index fab1700b01e4..64cf36b155f0 100644
--- a/sc/Library_scfilt.mk
+++ b/sc/Library_scfilt.mk
@@ -207,6 +207,8 @@ $(eval $(call gb_Library_add_exception_objects,scfilt,\
sc/source/filter/oox/stylesbuffer \
sc/source/filter/oox/stylesfragment \
sc/source/filter/oox/tablebuffer \
+ sc/source/filter/oox/tablecolumnsbuffer \
+ sc/source/filter/oox/tablecolumnscontext \
sc/source/filter/oox/tablefragment \
sc/source/filter/oox/themebuffer \
sc/source/filter/oox/unitconverter \
diff --git a/sc/source/filter/inc/tablebuffer.hxx b/sc/source/filter/inc/tablebuffer.hxx
index abc0a49bbec0..2bc2cfe1cff6 100644
--- a/sc/source/filter/inc/tablebuffer.hxx
+++ b/sc/source/filter/inc/tablebuffer.hxx
@@ -22,6 +22,7 @@
#include <com/sun/star/table/CellRangeAddress.hpp>
#include "autofilterbuffer.hxx"
+#include "tablecolumnsbuffer.hxx"
#include "workbookhelper.hxx"
namespace oox {
@@ -52,10 +53,13 @@ public:
void importTable( SequenceInputStream& rStrm, sal_Int16 nSheet );
/** Creates a new auto filter and stores it internally. */
inline AutoFilter& createAutoFilter() { return maAutoFilters.createAutoFilter(); }
+ /** Creates a new tableColumns handler and stores it internally. */
+ inline TableColumns& createTableColumns() { return maTableColumns.createTableColumns(); }
/** Creates a database range from this tables. */
void finalizeImport();
void applyAutoFilters();
+ void applyTableColumns();
/** Returns the unique table identifier. */
inline sal_Int32 getTableId() const { return maModel.mnId; }
@@ -80,6 +84,7 @@ public:
private:
TableModel maModel;
AutoFilterBuffer maAutoFilters; /// Filter settings for this table.
+ TableColumnsBuffer maTableColumns; /// Column names of this table.
OUString maDBRangeName; /// Name of the databae range in the Calc document.
::com::sun::star::table::CellRangeAddress
maDestRange; /// Validated range of the table in the worksheet.
@@ -100,6 +105,8 @@ public:
void finalizeImport();
/** Applies autofilters from created database range ( requires finalizeImport to have run before being called */
void applyAutoFilters();
+ /** Applies columns names from created database range ( requires finalizeImport to have run before being called */
+ void applyTableColumns();
/** Returns a table by its identifier. */
TableRef getTable( sal_Int32 nTableId ) const;
/** Returns a table by its display name. */
diff --git a/sc/source/filter/inc/tablecolumnsbuffer.hxx b/sc/source/filter/inc/tablecolumnsbuffer.hxx
new file mode 100644
index 000000000000..dc8e427fe201
--- /dev/null
+++ b/sc/source/filter/inc/tablecolumnsbuffer.hxx
@@ -0,0 +1,96 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef INCLUDED_SC_SOURCE_FILTER_INC_TABLECOLUMNSBUFFER_HXX
+#define INCLUDED_SC_SOURCE_FILTER_INC_TABLECOLUMNSBUFFER_HXX
+
+#include <oox/helper/refvector.hxx>
+#include "workbookhelper.hxx"
+
+namespace oox {
+namespace xls {
+
+/** A column in a table (database range).
+ */
+class TableColumn : public WorkbookHelper
+{
+public:
+ explicit TableColumn( const WorkbookHelper& rHelper );
+
+ /** Imports table column settings from the tableColumn element. */
+ void importTableColumn( const AttributeList& rAttribs );
+ /** Imports table column settings from the TABLECOLUMN (?) record. */
+ void importTableColumn( SequenceInputStream& rStrm );
+
+private:
+ OUString maName;
+ sal_Int32 mnId;
+ sal_Int32 mnDataDxfId;
+};
+
+class TableColumns : public WorkbookHelper
+{
+public:
+ explicit TableColumns( const WorkbookHelper& rHelper );
+
+ /** Imports settings from the tableColumns element. */
+ void importTableColumns( const AttributeList& rAttribs );
+ /** Imports settings from the TABLECOLUMNS (?) record. */
+ void importTableColumns( SequenceInputStream& rStrm );
+
+ /** Creates a new table column and stores it internally. */
+ TableColumn& createTableColumn();
+
+ /** Applies the columns to the passed database range descriptor. */
+ bool finalizeImport( const ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XDatabaseRange >& rxDatabaseRange );
+
+private:
+ typedef RefVector< TableColumn > TableColumnVector;
+
+ TableColumnVector maTableColumnVector;
+ sal_Int32 mnCount;
+};
+
+class TableColumnsBuffer : public WorkbookHelper
+{
+public:
+ explicit TableColumnsBuffer( const WorkbookHelper& rHelper );
+
+ /** Creates a new table columns object and stores it internally. */
+ TableColumns& createTableColumns();
+
+ /** Applies the table columns to the passed database range object.
+ @return True = this buffer contains valid table column settings. */
+ bool finalizeImport( const ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XDatabaseRange >& rxDatabaseRange );
+
+private:
+ /** Returns the table columns object used. */
+ TableColumns* getActiveTableColumns();
+
+private:
+ typedef RefVector< TableColumns > TableColumnsVector;
+ TableColumnsVector maTableColumnsVector;
+};
+
+} // namespace xls
+} // namespace oox
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/filter/inc/tablecolumnscontext.hxx b/sc/source/filter/inc/tablecolumnscontext.hxx
new file mode 100644
index 000000000000..513af5eea461
--- /dev/null
+++ b/sc/source/filter/inc/tablecolumnscontext.hxx
@@ -0,0 +1,68 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef INCLUDED_SC_SOURCE_FILTER_INC_TABLECOLUMNSCONTEXT_HXX
+#define INCLUDED_SC_SOURCE_FILTER_INC_TABLECOLUMNSCONTEXT_HXX
+
+#include "excelhandlers.hxx"
+
+namespace oox {
+namespace xls {
+
+class TableColumn;
+class TableColumns;
+
+class TableColumnContext : public WorksheetContextBase
+{
+public:
+ explicit TableColumnContext( WorksheetContextBase& rParent, TableColumn& rTableColumn );
+
+protected:
+ virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) SAL_OVERRIDE;
+ virtual void onStartElement( const AttributeList& rAttribs ) SAL_OVERRIDE;
+
+ virtual ::oox::core::ContextHandlerRef onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm ) SAL_OVERRIDE;
+ virtual void onStartRecord( SequenceInputStream& rStrm ) SAL_OVERRIDE;
+
+private:
+ TableColumn& mrTableColumn;
+};
+
+class TableColumnsContext : public WorksheetContextBase
+{
+public:
+ explicit TableColumnsContext( WorksheetFragmentBase& rFragment, TableColumns& rTableColumns );
+
+protected:
+ virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) SAL_OVERRIDE;
+ virtual void onStartElement( const AttributeList& rAttribs ) SAL_OVERRIDE;
+
+ virtual ::oox::core::ContextHandlerRef onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm ) SAL_OVERRIDE;
+ virtual void onStartRecord( SequenceInputStream& rStrm ) SAL_OVERRIDE;
+
+private:
+ TableColumns& mrTableColumns;
+};
+
+} // namespace xls
+} // namespace oox
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/filter/oox/tablebuffer.cxx b/sc/source/filter/oox/tablebuffer.cxx
index 65aaf64ee6f9..b1fddccdca3c 100644
--- a/sc/source/filter/oox/tablebuffer.cxx
+++ b/sc/source/filter/oox/tablebuffer.cxx
@@ -46,6 +46,7 @@ TableModel::TableModel() :
Table::Table( const WorkbookHelper& rHelper ) :
WorkbookHelper( rHelper ),
maAutoFilters( rHelper ),
+ maTableColumns( rHelper ),
mnTokenIndex( -1 )
{
}
diff --git a/sc/source/filter/oox/tablecolumnsbuffer.cxx b/sc/source/filter/oox/tablecolumnsbuffer.cxx
new file mode 100644
index 000000000000..5879fc322dd6
--- /dev/null
+++ b/sc/source/filter/oox/tablecolumnsbuffer.cxx
@@ -0,0 +1,133 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include "tablecolumnsbuffer.hxx"
+
+#include <com/sun/star/sheet/XDatabaseRange.hpp>
+#include <rtl/ustrbuf.hxx>
+#include <osl/diagnose.h>
+#include <oox/helper/attributelist.hxx>
+#include <oox/helper/containerhelper.hxx>
+#include <oox/helper/propertyset.hxx>
+#include <oox/token/properties.hxx>
+#include "addressconverter.hxx"
+#include "biffinputstream.hxx"
+#include "defnamesbuffer.hxx"
+
+namespace oox {
+namespace xls {
+
+using namespace ::com::sun::star::sheet;
+using namespace ::com::sun::star::table;
+using namespace ::com::sun::star::uno;
+
+TableColumn::TableColumn( const WorkbookHelper& rHelper ) :
+ WorkbookHelper( rHelper ),
+ mnId( -1 ),
+ mnDataDxfId( -1 )
+{
+}
+
+void TableColumn::importTableColumn( const AttributeList& rAttribs )
+{
+ mnId = rAttribs.getInteger( XML_id, -1 );
+ maName = rAttribs.getString( XML_name, OUString() );
+ mnDataDxfId = rAttribs.getInteger( XML_dataDxfId, -1 );
+}
+
+void TableColumn::importTableColumn( SequenceInputStream& /*rStrm*/ )
+{
+ /* XXX not implemented */
+}
+
+TableColumns::TableColumns( const WorkbookHelper& rHelper ) :
+ WorkbookHelper( rHelper ),
+ mnCount(0)
+{
+}
+
+void TableColumns::importTableColumns( const AttributeList& rAttribs )
+{
+ mnCount = rAttribs.getInteger( XML_count, 0 );
+}
+
+void TableColumns::importTableColumns( SequenceInputStream& /*rStrm*/ )
+{
+ /* XXX not implemented */
+}
+
+TableColumn& TableColumns::createTableColumn()
+{
+ TableColumnVector::value_type xTableColumn( new TableColumn( *this ) );
+ maTableColumnVector.push_back( xTableColumn );
+ return *xTableColumn;
+}
+
+bool TableColumns::finalizeImport( const Reference< XDatabaseRange >& rxDatabaseRange )
+{
+ SAL_WARN_IF( static_cast<size_t>(mnCount) != maTableColumnVector.size(), "sc.filter",
+ "TableColumns::finalizeImport - count attribute doesn't match number of tableColumn elements");
+ if( rxDatabaseRange.is() )
+ {
+ /* TODO: implementation */
+ return true;
+ }
+ return false;
+}
+
+TableColumnsBuffer::TableColumnsBuffer( const WorkbookHelper& rHelper ) :
+ WorkbookHelper( rHelper )
+{
+}
+
+TableColumns& TableColumnsBuffer::createTableColumns()
+{
+ TableColumnsVector::value_type xTableColumns( new TableColumns( *this ) );
+ maTableColumnsVector.push_back( xTableColumns );
+ return *xTableColumns;
+}
+
+bool TableColumnsBuffer::finalizeImport( const Reference< XDatabaseRange >& rxDatabaseRange )
+{
+ TableColumns* pTableColumns = getActiveTableColumns();
+ if( pTableColumns && rxDatabaseRange.is() ) try
+ {
+ pTableColumns->finalizeImport( rxDatabaseRange );
+ // return true to indicate available table columns
+ return true;
+ }
+ catch( Exception& )
+ {
+ }
+ return false;
+}
+
+TableColumns* TableColumnsBuffer::getActiveTableColumns()
+{
+ // not more than one table columns descriptor per table
+ SAL_WARN_IF( maTableColumnsVector.size() > 1, "sc.filter",
+ "TableColumnsBuffer::getActiveTableColumns - too many table columns" );
+ // stick to the last imported table columns
+ return maTableColumnsVector.empty() ? 0 : maTableColumnsVector.back().get();
+}
+
+} // namespace xls
+} // namespace oox
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/filter/oox/tablecolumnscontext.cxx b/sc/source/filter/oox/tablecolumnscontext.cxx
new file mode 100644
index 000000000000..8ad4ea21caad
--- /dev/null
+++ b/sc/source/filter/oox/tablecolumnscontext.cxx
@@ -0,0 +1,94 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include "tablecolumnscontext.hxx"
+
+#include "tablecolumnsbuffer.hxx"
+#include "biffinputstream.hxx"
+
+namespace oox {
+namespace xls {
+
+using ::oox::core::ContextHandlerRef;
+
+TableColumnContext::TableColumnContext( WorksheetContextBase& rParent, TableColumn& rTableColumn ) :
+ WorksheetContextBase( rParent ),
+ mrTableColumn( rTableColumn )
+{
+}
+
+ContextHandlerRef TableColumnContext::onCreateContext( sal_Int32 /*nElement*/, const AttributeList& /*rAttribs*/ )
+{
+ /* no known child elements */
+ return 0;
+}
+
+void TableColumnContext::onStartElement( const AttributeList& rAttribs )
+{
+ mrTableColumn.importTableColumn( rAttribs );
+}
+
+ContextHandlerRef TableColumnContext::onCreateRecordContext( sal_Int32 /*nRecId*/, SequenceInputStream& /*rStrm*/ )
+{
+ /* no known child elements */
+ return 0;
+}
+
+void TableColumnContext::onStartRecord( SequenceInputStream& rStrm )
+{
+ mrTableColumn.importTableColumn( rStrm );
+}
+
+TableColumnsContext::TableColumnsContext( WorksheetFragmentBase& rFragment, TableColumns& rTableColumns ) :
+ WorksheetContextBase( rFragment ),
+ mrTableColumns( rTableColumns )
+{
+}
+
+ContextHandlerRef TableColumnsContext::onCreateContext( sal_Int32 nElement, const AttributeList& /*rAttribs*/ )
+{
+ if( (getCurrentElement() == XLS_TOKEN( tableColumns )) && (nElement == XLS_TOKEN( tableColumn )) )
+ return new TableColumnContext( *this, mrTableColumns.createTableColumn() );
+ return 0;
+}
+
+void TableColumnsContext::onStartElement( const AttributeList& rAttribs )
+{
+ mrTableColumns.importTableColumns( rAttribs );
+}
+
+ContextHandlerRef TableColumnsContext::onCreateRecordContext( sal_Int32 /*nRecId*/, SequenceInputStream& /*rStrm*/ )
+{
+ /* XXX not implemented */
+#if 0
+ if( (getCurrentElement() == BIFF12_ID_TABLECOLUMNS) && (nRecId == BIFF12_ID_TABLECOLUMN) )
+ return new TableColumnContext( *this, mrTableColumns.createTableColumn() );
+#endif
+ return 0;
+}
+
+void TableColumnsContext::onStartRecord( SequenceInputStream& rStrm )
+{
+ mrTableColumns.importTableColumns( rStrm );
+}
+
+} // namespace xls
+} // namespace oox
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/filter/oox/tablefragment.cxx b/sc/source/filter/oox/tablefragment.cxx
index 52039c716a74..b8f5d7d8d746 100644
--- a/sc/source/filter/oox/tablefragment.cxx
+++ b/sc/source/filter/oox/tablefragment.cxx
@@ -21,6 +21,8 @@
#include "autofilterbuffer.hxx"
#include "autofiltercontext.hxx"
+#include "tablecolumnsbuffer.hxx"
+#include "tablecolumnscontext.hxx"
#include "tablebuffer.hxx"
namespace oox {
@@ -46,8 +48,13 @@ ContextHandlerRef TableFragment::onCreateContext( sal_Int32 nElement, const Attr
}
break;
case XLS_TOKEN( table ):
- if( nElement == XLS_TOKEN( autoFilter ) )
- return new AutoFilterContext( *this, mrTable.createAutoFilter() );
+ switch (nElement)
+ {
+ case XLS_TOKEN( autoFilter ):
+ return new AutoFilterContext( *this, mrTable.createAutoFilter() );
+ case XLS_TOKEN( tableColumns ):
+ return new TableColumnsContext( *this, mrTable.createTableColumns() );
+ }
break;
}
return 0;