diff options
author | Kohei Yoshida <kohei.yoshida@collabora.com> | 2013-12-19 15:17:49 -0500 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@collabora.com> | 2013-12-19 15:33:09 -0500 |
commit | 23f09302199c903b63064760d9d4a3fd34ff0fe5 (patch) | |
tree | f1aa9410c5927ccef569c5fbd28ecc6bb10941a2 /sc | |
parent | a6b2103b8b35aa7c25eabc3d38adca167a9f9f4e (diff) |
Properly import data stream data from ods.
Change-Id: Iedae2226ba08c614f1b700a5444715a990899d38
Diffstat (limited to 'sc')
-rw-r--r-- | sc/Library_sc.mk | 2 | ||||
-rw-r--r-- | sc/inc/importfilterdata.hxx | 49 | ||||
-rw-r--r-- | sc/inc/xmlwrap.hxx | 6 | ||||
-rw-r--r-- | sc/source/filter/importfilterdata.cxx | 19 | ||||
-rw-r--r-- | sc/source/filter/xml/xmlbodyi.cxx | 4 | ||||
-rw-r--r-- | sc/source/filter/xml/xmlimprt.cxx | 31 | ||||
-rw-r--r-- | sc/source/filter/xml/xmlimprt.hxx | 27 | ||||
-rw-r--r-- | sc/source/filter/xml/xmlwrap.cxx | 9 | ||||
-rw-r--r-- | sc/source/ui/docshell/datastream.cxx | 2 | ||||
-rw-r--r-- | sc/source/ui/docshell/docsh.cxx | 34 | ||||
-rw-r--r-- | sc/source/ui/miscdlgs/datastreamdlg.cxx | 2 |
11 files changed, 183 insertions, 2 deletions
diff --git a/sc/Library_sc.mk b/sc/Library_sc.mk index 8eeab594157f..11f4d06ebc40 100644 --- a/sc/Library_sc.mk +++ b/sc/Library_sc.mk @@ -269,6 +269,7 @@ $(eval $(call gb_Library_add_exception_objects,sc,\ sc/source/core/tool/userlist \ sc/source/core/tool/viewopti \ sc/source/core/tool/zforauto \ + sc/source/filter/xml/datastreamimport \ sc/source/filter/xml/XMLCalculationSettingsContext \ sc/source/filter/xml/XMLCellRangeSourceContext \ sc/source/filter/xml/XMLChangeTrackingExportHelper \ @@ -324,6 +325,7 @@ $(eval $(call gb_Library_add_exception_objects,sc,\ sc/source/filter/xml/xmltabi \ sc/source/filter/xml/xmlwrap \ sc/source/filter/chart/chart_imp \ + sc/source/filter/importfilterdata \ sc/source/ui/Accessibility/AccessibilityHints \ sc/source/ui/Accessibility/AccessibleCell \ sc/source/ui/Accessibility/AccessibleCellBase \ diff --git a/sc/inc/importfilterdata.hxx b/sc/inc/importfilterdata.hxx new file mode 100644 index 000000000000..23cef833d202 --- /dev/null +++ b/sc/inc/importfilterdata.hxx @@ -0,0 +1,49 @@ +/* -*- 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/. + */ + +#ifndef SC_IMPORTFILTERDATA_HXX +#define SC_IMPORTFILTERDATA_HXX + +#include <address.hxx> + +#include <boost/noncopyable.hpp> +#include <boost/scoped_ptr.hpp> + +namespace sc { + +/** + * Stores data imported from the file that need to be processed at the end + * of the import process. + */ +struct ImportPostProcessData : boost::noncopyable +{ + /** + * Data stream data needs to be post-processed because it requires + * ScDocShell instance which is not available in the filter code. + */ + struct DataStream + { + enum InsertPos { InsertTop, InsertBottom }; + + OUString maURL; + ScRange maRange; + bool mbRefreshOnEmpty; + InsertPos meInsertPos; + + DataStream(); + }; + + boost::scoped_ptr<DataStream> mpDataStream; +}; + +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/inc/xmlwrap.hxx b/sc/inc/xmlwrap.hxx index fb7b15681137..107ceb4cfdae 100644 --- a/sc/inc/xmlwrap.hxx +++ b/sc/inc/xmlwrap.hxx @@ -25,6 +25,8 @@ #include <com/sun/star/uno/Sequence.hxx> #include <com/sun/star/frame/XModel.hpp> +#include <importfilterdata.hxx> + class ScDocument; class SfxMedium; class ScMySharedData; @@ -44,6 +46,8 @@ namespace com { namespace sun { namespace star { class ScXMLImportWrapper { + sc::ImportPostProcessData maPostProcessData; + ScDocument& rDoc; SfxMedium* pMedium; ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > xStorage; @@ -70,6 +74,8 @@ public: ScXMLImportWrapper(ScDocument& rD, SfxMedium* pM, const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >&); sal_Bool Import(sal_Bool bStylesOnly, ErrCode& ); sal_Bool Export(sal_Bool bStylesOnly); + + const sc::ImportPostProcessData& GetImportPostProcessData() const; }; class ScXMLChartExportWrapper diff --git a/sc/source/filter/importfilterdata.cxx b/sc/source/filter/importfilterdata.cxx new file mode 100644 index 000000000000..100188928a0c --- /dev/null +++ b/sc/source/filter/importfilterdata.cxx @@ -0,0 +1,19 @@ +/* -*- 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/. + */ + +#include <importfilterdata.hxx> + +namespace sc { + +ImportPostProcessData::DataStream::DataStream() : + mbRefreshOnEmpty(false), meInsertPos(InsertBottom) {} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/filter/xml/xmlbodyi.cxx b/sc/source/filter/xml/xmlbodyi.cxx index 10a0a946cc38..2496a94cecfc 100644 --- a/sc/source/filter/xml/xmlbodyi.cxx +++ b/sc/source/filter/xml/xmlbodyi.cxx @@ -39,6 +39,7 @@ #include "XMLEmptyContext.hxx" #include "scerrors.hxx" #include "tabprotection.hxx" +#include "datastreamimport.hxx" #include <xmloff/xmltkmap.hxx> #include <xmloff/xmltoken.hxx> @@ -192,6 +193,9 @@ SvXMLImportContext *ScXMLBodyContext::CreateChildContext( sal_uInt16 nPrefix, pContext = new ScXMLDDELinksContext ( GetScImport(), nPrefix, rLocalName, xAttrList ); break; + case XML_TOK_BODY_DATA_STREAM_SOURCE: + pContext = new ScXMLDataStreamContext(GetScImport(), nPrefix, rLocalName, xAttrList); + break; } if( !pContext ) diff --git a/sc/source/filter/xml/xmlimprt.cxx b/sc/source/filter/xml/xmlimprt.cxx index 0320be55d459..96be8112c40c 100644 --- a/sc/source/filter/xml/xmlimprt.cxx +++ b/sc/source/filter/xml/xmlimprt.cxx @@ -457,6 +457,7 @@ const SvXMLTokenMap& ScXMLImport::GetBodyElemTokenMap() { XML_NAMESPACE_TABLE, XML_DATA_PILOT_TABLES, XML_TOK_BODY_DATA_PILOT_TABLES }, { XML_NAMESPACE_TABLE, XML_CONSOLIDATION, XML_TOK_BODY_CONSOLIDATION }, { XML_NAMESPACE_TABLE, XML_DDE_LINKS, XML_TOK_BODY_DDE_LINKS }, + { XML_NAMESPACE_CALC_EXT, XML_DATA_STREAM_SOURCE, XML_TOK_BODY_DATA_STREAM_SOURCE }, XML_TOKEN_MAP_END }; @@ -1930,6 +1931,33 @@ const SvXMLTokenMap& ScXMLImport::GetCellTextSAttrTokenMap() return *pCellTextSAttrTokenMap; } +const SvXMLTokenMap& ScXMLImport::GetDataStreamAttrTokenMap() +{ + if (!pDataStreamAttrTokenMap) + { + static const SvXMLTokenMapEntry aMap[] = + { + { XML_NAMESPACE_XLINK, XML_HREF, XML_TOK_DATA_STREAM_ATTR_URL }, + { XML_NAMESPACE_TABLE, XML_TARGET_RANGE_ADDRESS, XML_TOK_DATA_STREAM_ATTR_RANGE }, + { XML_NAMESPACE_CALC_EXT, XML_EMPTY_LINE_REFRESH, XML_TOK_DATA_STREAM_ATTR_EMPTY_LINE_REFRESH }, + { XML_NAMESPACE_CALC_EXT, XML_INSERTION_POSITION, XML_TOK_DATA_STREAM_ATTR_INSERTION_POSITION }, + XML_TOKEN_MAP_END + }; + pDataStreamAttrTokenMap = new SvXMLTokenMap(aMap); + } + return *pDataStreamAttrTokenMap; +} + +void ScXMLImport::SetPostProcessData( sc::ImportPostProcessData* p ) +{ + mpPostProcessData = p; +} + +sc::ImportPostProcessData* ScXMLImport::GetPostProcessData() +{ + return mpPostProcessData; +} + SvXMLImportContext *ScXMLImport::CreateContext( sal_uInt16 nPrefix, const OUString& rLocalName, const uno::Reference<xml::sax::XAttributeList>& xAttrList ) @@ -2056,6 +2084,8 @@ ScXMLImport::ScXMLImport( pCellTextSpanAttrTokenMap(NULL), pCellTextURLAttrTokenMap(NULL), pCellTextSAttrTokenMap(NULL), + pDataStreamAttrTokenMap(NULL), + mpPostProcessData(NULL), aTables(*this), pMyNamedExpressions(NULL), pMyLabelRanges(NULL), @@ -2197,6 +2227,7 @@ ScXMLImport::~ScXMLImport() throw() delete pCellTextSpanAttrTokenMap; delete pCellTextURLAttrTokenMap; delete pCellTextSAttrTokenMap; + delete pDataStreamAttrTokenMap; delete pChangeTrackingImportHelper; delete pNumberFormatAttributesExportHelper; diff --git a/sc/source/filter/xml/xmlimprt.hxx b/sc/source/filter/xml/xmlimprt.hxx index d4d45a79db1a..f3dba757686d 100644 --- a/sc/source/filter/xml/xmlimprt.hxx +++ b/sc/source/filter/xml/xmlimprt.hxx @@ -55,6 +55,12 @@ class XMLNumberFormatAttributesExportHelper; class ScEditEngineDefaulter; class ScDocumentImport; +namespace sc { + +struct ImportPostProcessData; + +} + enum ScXMLDocTokens { XML_TOK_DOC_FONTDECLS, @@ -97,7 +103,8 @@ enum ScXMLBodyTokens XML_TOK_BODY_DATABASE_RANGE, XML_TOK_BODY_DATA_PILOT_TABLES, XML_TOK_BODY_CONSOLIDATION, - XML_TOK_BODY_DDE_LINKS + XML_TOK_BODY_DDE_LINKS, + XML_TOK_BODY_DATA_STREAM_SOURCE }; enum ScXMLContentValidationsElemTokens @@ -733,6 +740,17 @@ enum ScXMLCellTextSAttrTokens XML_TOK_CELL_TEXT_S_ATTR_C }; +/** + * Attribute tokens for <calcext:data-stream-source>. + */ +enum ScXMLDataStreamAttrTokens +{ + XML_TOK_DATA_STREAM_ATTR_URL, + XML_TOK_DATA_STREAM_ATTR_RANGE, + XML_TOK_DATA_STREAM_ATTR_EMPTY_LINE_REFRESH, + XML_TOK_DATA_STREAM_ATTR_INSERTION_POSITION +}; + class SvXMLTokenMap; class XMLShapeImportHelper; class ScXMLChangeTrackingImportHelper; @@ -907,6 +925,9 @@ class ScXMLImport: public SvXMLImport, boost::noncopyable SvXMLTokenMap *pCellTextSpanAttrTokenMap; SvXMLTokenMap *pCellTextURLAttrTokenMap; SvXMLTokenMap *pCellTextSAttrTokenMap; + SvXMLTokenMap *pDataStreamAttrTokenMap; + + sc::ImportPostProcessData* mpPostProcessData; /// Lift cycle managed elsewhere, no need to delete. ScMyTables aTables; @@ -1076,6 +1097,10 @@ public: const SvXMLTokenMap& GetCellTextSpanAttrTokenMap(); const SvXMLTokenMap& GetCellTextURLAttrTokenMap(); const SvXMLTokenMap& GetCellTextSAttrTokenMap(); + const SvXMLTokenMap& GetDataStreamAttrTokenMap(); + + void SetPostProcessData( sc::ImportPostProcessData* p ); + sc::ImportPostProcessData* GetPostProcessData(); void AddNamedExpression(ScMyNamedExpression* pMyNamedExpression) { diff --git a/sc/source/filter/xml/xmlwrap.cxx b/sc/source/filter/xml/xmlwrap.cxx index ef38f08c7c63..4e2ef7d1f5ea 100644 --- a/sc/source/filter/xml/xmlwrap.cxx +++ b/sc/source/filter/xml/xmlwrap.cxx @@ -174,6 +174,10 @@ sal_uInt32 ScXMLImportWrapper::ImportFromComponent(const uno::Reference<uno::XCo if (xImporter.is()) xImporter->setTargetDocument( xComponent ); + ScXMLImport* pImporterImpl = dynamic_cast<ScXMLImport*>(xImporter.get()); + if (pImporterImpl) + pImporterImpl->SetPostProcessData(&maPostProcessData); + // connect parser and filter xParser->setDocumentHandler( xDocHandler ); @@ -992,5 +996,10 @@ sal_Bool ScXMLImportWrapper::Export(sal_Bool bStylesOnly) return false; } +const sc::ImportPostProcessData& ScXMLImportWrapper::GetImportPostProcessData() const +{ + return maPostProcessData; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/docshell/datastream.cxx b/sc/source/ui/docshell/datastream.cxx index edd0e2a87db3..493b9224bbfb 100644 --- a/sc/source/ui/docshell/datastream.cxx +++ b/sc/source/ui/docshell/datastream.cxx @@ -288,7 +288,7 @@ void DataStream::Decode(const OUString& rURL, const ScRange& rRange, meOrigMove = eMove; mnSettings = nSettings; - mbValuesInLine = mnSettings & VALUES_IN_LINE; + mbValuesInLine = true; // always true. mnCurRow = rRange.aStart.Row(); diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx index ca39e78c6118..3e182701fce8 100644 --- a/sc/source/ui/docshell/docsh.cxx +++ b/sc/source/ui/docshell/docsh.cxx @@ -119,6 +119,8 @@ #include "dpobject.hxx" #include "markdata.hxx" #include "orcusfilters.hxx" +#include <datastream.hxx> +#include <documentlinkmgr.hxx> #include <config_telepathy.h> @@ -400,6 +402,36 @@ private: ScDocument* mpDoc; }; +void processDataStream( ScDocShell& rShell, const sc::ImportPostProcessData& rData ) +{ + if (!rData.mpDataStream) + return; + + const sc::ImportPostProcessData::DataStream& r = *rData.mpDataStream; + if (!r.maRange.IsValid()) + return; + + // Break the streamed range into the top range and the height limit. A + // height limit of 0 means unlimited i.e. the streamed data will go all + // the way to the last row. + + ScRange aTopRange = r.maRange; + aTopRange.aEnd.SetRow(aTopRange.aStart.Row()); + sal_Int32 nLimit = r.maRange.aEnd.Row() - r.maRange.aStart.Row() + 1; + if (r.maRange.aEnd.Row() == MAXROW) + // Unlimited range. + nLimit = 0; + + sc::DataStream::MoveType eMove = + r.meInsertPos == sc::ImportPostProcessData::DataStream::InsertTop ? + sc::DataStream::MOVE_DOWN : sc::DataStream::RANGE_DOWN; + + sc::DataStream* pStrm = new sc::DataStream(&rShell, r.maURL, aTopRange, nLimit, eMove, 0); + pStrm->SetRefreshOnEmptyLine(r.mbRefreshOnEmpty); + sc::DocumentLinkManager& rMgr = rShell.GetDocument()->GetDocLinkManager(); + rMgr.setDataStream(pStrm); +} + } sal_Bool ScDocShell::LoadXML( SfxMedium* pLoadMedium, const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStor ) @@ -430,6 +462,8 @@ sal_Bool ScDocShell::LoadXML( SfxMedium* pLoadMedium, const ::com::sun::star::un if ( nError ) pLoadMedium->SetError( nError, OUString( OSL_LOG_PREFIX ) ); + processDataStream(*this, aImport.GetImportPostProcessData()); + //if the document was not generated by LibreOffice, do hard recalc in case some other document //generator saved cached formula results that differ from LibreOffice's calculated results or //did not use cached formula results. diff --git a/sc/source/ui/miscdlgs/datastreamdlg.cxx b/sc/source/ui/miscdlgs/datastreamdlg.cxx index cc5819535d38..8a3bee5a813a 100644 --- a/sc/source/ui/miscdlgs/datastreamdlg.cxx +++ b/sc/source/ui/miscdlgs/datastreamdlg.cxx @@ -150,6 +150,8 @@ void DataStreamDlg::Init( const DataStream& rStrm ) ; } + m_pCBRefreshOnEmpty->Check(rStrm.IsRefreshOnEmptyLine()); + UpdateEnable(); } |