diff options
-rw-r--r-- | framework/source/loadenv/loadenv.cxx | 8 | ||||
-rw-r--r-- | sc/inc/orcusfilters.hxx | 4 | ||||
-rw-r--r-- | sc/source/filter/inc/orcusfiltersimpl.hxx | 2 | ||||
-rw-r--r-- | sc/source/filter/orcus/orcusfiltersimpl.cxx | 42 | ||||
-rw-r--r-- | sc/source/ui/docshell/docsh.cxx | 31 | ||||
-rw-r--r-- | sc/source/ui/inc/docsh.hxx | 2 | ||||
-rw-r--r-- | sfx2/inc/sfx2/docfilt.hxx | 19 | ||||
-rw-r--r-- | sfx2/inc/sfx2/objsh.hxx | 4 | ||||
-rw-r--r-- | sfx2/source/bastyp/fltfnc.cxx | 2 | ||||
-rw-r--r-- | sfx2/source/doc/docfile.cxx | 15 | ||||
-rw-r--r-- | sfx2/source/doc/docfilt.cxx | 15 | ||||
-rw-r--r-- | sfx2/source/doc/objstor.cxx | 6 | ||||
-rw-r--r-- | sfx2/source/doc/sfxbasemodel.cxx | 5 |
13 files changed, 128 insertions, 27 deletions
diff --git a/framework/source/loadenv/loadenv.cxx b/framework/source/loadenv/loadenv.cxx index 86646d58ec4e..c82422218c59 100644 --- a/framework/source/loadenv/loadenv.cxx +++ b/framework/source/loadenv/loadenv.cxx @@ -744,7 +744,6 @@ bool queryOrcusTypeAndFilter(const uno::Sequence<beans::PropertyValue>& rDescrip rFilter = "gnumeric"; return true; } -#if 0 else if (aURL.endsWith(".xlsx")) { rType = "generic_Text"; @@ -757,7 +756,12 @@ bool queryOrcusTypeAndFilter(const uno::Sequence<beans::PropertyValue>& rDescrip rFilter = "ods"; return true; } -#endif + else if (aURL.endsWith(".csv")) + { + rType = "generic_Text"; + rFilter = "csv"; + return true; + } return false; } diff --git a/sc/inc/orcusfilters.hxx b/sc/inc/orcusfilters.hxx index ef88795432f3..ab09d8cdb680 100644 --- a/sc/inc/orcusfilters.hxx +++ b/sc/inc/orcusfilters.hxx @@ -30,6 +30,10 @@ public: virtual bool importGnumeric(ScDocument& rDoc, const OUString& rPath) const = 0; + virtual bool importXLSX(ScDocument& rDoc, const OUString& rPath) const = 0; + + virtual bool importODS(ScDocument& rDoc, const OUString& rPath) const = 0; + /** * Create a context for XML file. The context object stores session * information for each unique XML file. You must create a new context diff --git a/sc/source/filter/inc/orcusfiltersimpl.hxx b/sc/source/filter/inc/orcusfiltersimpl.hxx index de5f988f03dc..e07cd19d39e1 100644 --- a/sc/source/filter/inc/orcusfiltersimpl.hxx +++ b/sc/source/filter/inc/orcusfiltersimpl.hxx @@ -22,6 +22,8 @@ public: virtual bool importCSV(ScDocument& rDoc, const OUString& rPath) const; virtual bool importGnumeric(ScDocument& rDoc, const OUString& rPath) const; + virtual bool importXLSX(ScDocument& rDoc, const OUString& rPath) const; + virtual bool importODS(ScDocument& rDoc, const OUString& rPath) const; virtual ScOrcusXMLContext* createXMLContext(ScDocument& rDoc, const OUString& rPath) const; }; diff --git a/sc/source/filter/orcus/orcusfiltersimpl.cxx b/sc/source/filter/orcus/orcusfiltersimpl.cxx index e74a5e421891..7ef1310c4793 100644 --- a/sc/source/filter/orcus/orcusfiltersimpl.cxx +++ b/sc/source/filter/orcus/orcusfiltersimpl.cxx @@ -17,6 +17,8 @@ #include <orcus/spreadsheet/import_interface.hpp> #include <orcus/orcus_csv.hpp> #include <orcus/orcus_gnumeric.hpp> +#include <orcus/orcus_xlsx.hpp> +#include <orcus/orcus_ods.hpp> #include <orcus/global.hpp> #ifdef WNT @@ -71,6 +73,46 @@ bool ScOrcusFiltersImpl::importGnumeric(ScDocument& rDoc, const OUString& rPath) return true; } +bool ScOrcusFiltersImpl::importXLSX(ScDocument& rDoc, const OUString& rPath) const +{ + ScOrcusFactory aFactory(rDoc); + OString aSysPath = toSystemPath(rPath); + const char* path = aSysPath.getStr(); + + try + { + orcus::orcus_xlsx filter(&aFactory); + filter.read_file(path); + } + catch (const std::exception& e) + { + SAL_WARN("sc", "Unable to load xlsx file! " << e.what()); + return false; + } + + return true; +} + +bool ScOrcusFiltersImpl::importODS(ScDocument& rDoc, const OUString& rPath) const +{ + ScOrcusFactory aFactory(rDoc); + OString aSysPath = toSystemPath(rPath); + const char* path = aSysPath.getStr(); + + try + { + orcus::orcus_ods filter(&aFactory); + filter.read_file(path); + } + catch (const std::exception& e) + { + SAL_WARN("sc", "Unable to load ods file! " << e.what()); + return false; + } + + return true; +} + ScOrcusXMLContext* ScOrcusFiltersImpl::createXMLContext(ScDocument& rDoc, const OUString& rPath) const { return new ScOrcusXMLContextImpl(rDoc, rPath); diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx index 16942554d809..0cc10bdd9db6 100644 --- a/sc/source/ui/docshell/docsh.cxx +++ b/sc/source/ui/docshell/docsh.cxx @@ -1493,16 +1493,39 @@ sal_Bool ScDocShell::ConvertFrom( SfxMedium& rMedium ) return bRet; } -bool ScDocShell::LoadExternal(SfxMedium& rMed, const OUString& rProvider) +bool ScDocShell::LoadExternal( SfxMedium& rMed ) { - if (rProvider == "orcus") + const SfxFilter* pFilter = rMed.GetFilter(); + if (!pFilter) + return false; + + if (pFilter->GetProviderName() == "orcus") { ScOrcusFilters* pOrcus = ScFormatFilter::Get().GetOrcusFilters(); if (!pOrcus) return false; - if (!pOrcus->importGnumeric(aDocument, rMed.GetName())) - return false; + const OUString& rFilterName = pFilter->GetName(); + if (rFilterName == "gnumeric") + { + if (!pOrcus->importGnumeric(aDocument, rMed.GetName())) + return false; + } + else if (rFilterName == "csv") + { + if (!pOrcus->importCSV(aDocument, rMed.GetName())) + return false; + } + else if (rFilterName == "xlsx") + { + if (!pOrcus->importXLSX(aDocument, rMed.GetName())) + return false; + } + else if (rFilterName == "ods") + { + if (!pOrcus->importODS(aDocument, rMed.GetName())) + return false; + } FinishedLoading(SFX_LOADED_MAINDOCUMENT | SFX_LOADED_IMAGES); return true; diff --git a/sc/source/ui/inc/docsh.hxx b/sc/source/ui/inc/docsh.hxx index a26a234f3a83..d761f7f46fba 100644 --- a/sc/source/ui/inc/docsh.hxx +++ b/sc/source/ui/inc/docsh.hxx @@ -201,7 +201,7 @@ public: virtual sal_Bool Load( SfxMedium& rMedium ); virtual sal_Bool LoadFrom( SfxMedium& rMedium ); virtual sal_Bool ConvertFrom( SfxMedium &rMedium ); - virtual bool LoadExternal(SfxMedium& rMedium, const OUString& rProvider); + virtual bool LoadExternal( SfxMedium& rMedium ); virtual sal_Bool Save(); virtual sal_Bool SaveAs( SfxMedium& rMedium ); virtual sal_Bool ConvertTo( SfxMedium &rMedium ); diff --git a/sfx2/inc/sfx2/docfilt.hxx b/sfx2/inc/sfx2/docfilt.hxx index 8400e5a6b16e..cc6f6b8c1971 100644 --- a/sfx2/inc/sfx2/docfilt.hxx +++ b/sfx2/inc/sfx2/docfilt.hxx @@ -34,12 +34,12 @@ #include <sfx2/sfxdefs.hxx> -//======================================================================== class SfxFilterContainer; class SotStorage; + class SFX2_DLLPUBLIC SfxFilter { -friend class SfxFilterContainer; + friend class SfxFilterContainer; WildCard aWildCard; @@ -47,17 +47,25 @@ friend class SfxFilterContainer; OUString aUserData; OUString aServiceName; OUString aMimeType; - OUString aFilterName; + OUString maFilterName; OUString aPattern; OUString aUIName; OUString aDefaultTemplate; + /** + * Custom provider name in case the filter is provided via external + * libraries. Empty for conventional filter types. + */ + OUString maProvider; + SfxFilterFlags nFormatType; sal_uIntPtr nVersion; sal_uIntPtr lFormat; sal_uInt16 nDocIcon; public: + SfxFilter( const OUString& rProvider, const OUString& rFilterName ); + SfxFilter( const OUString &rName, const OUString &rWildCard, SfxFilterFlags nFormatType, @@ -77,9 +85,9 @@ public: bool CanExport() const { return nFormatType & SFX_FILTER_EXPORT; } bool IsInternal() const { return nFormatType & SFX_FILTER_INTERNAL; } SfxFilterFlags GetFilterFlags() const { return nFormatType; } - const OUString& GetFilterName() const { return aFilterName; } + const OUString& GetFilterName() const { return maFilterName; } const OUString& GetMimeType() const { return aMimeType; } - const OUString& GetName() const { return aFilterName; } + const OUString& GetName() const { return maFilterName; } const WildCard& GetWildcard() const { return aWildCard; } const OUString& GetRealTypeName() const { return aTypeName; } sal_uIntPtr GetFormat() const { return lFormat; } @@ -98,6 +106,7 @@ public: OUString GetSuffixes() const; OUString GetDefaultExtension() const; const OUString& GetServiceName() const { return aServiceName; } + const OUString& GetProviderName() const; static const SfxFilter* GetDefaultFilter( const String& rName ); static const SfxFilter* GetFilterByName( const String& rName ); diff --git a/sfx2/inc/sfx2/objsh.hxx b/sfx2/inc/sfx2/objsh.hxx index 5f1018e6ad6e..4c366a56710f 100644 --- a/sfx2/inc/sfx2/objsh.hxx +++ b/sfx2/inc/sfx2/objsh.hxx @@ -308,7 +308,7 @@ public: bool DoInitUnitTest(); sal_Bool DoInitNew( SfxMedium* pMedium=0 ); sal_Bool DoLoad( SfxMedium* pMedium ); - bool DoLoadExternal(SfxMedium* pMed, const OUString& rProvider); + bool DoLoadExternal( SfxMedium* pMed ); sal_Bool DoSave(); sal_Bool DoSaveAs( SfxMedium &rNewStor ); sal_Bool DoSaveObjectAs( SfxMedium &rNewStor, sal_Bool bCommit ); @@ -329,7 +329,7 @@ public: virtual sal_Bool SwitchPersistance( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage ); virtual void UpdateLinks(); - virtual bool LoadExternal(SfxMedium& rMedium, const OUString& rProvider); + virtual bool LoadExternal( SfxMedium& rMedium ); /** * Called when the Options dialog is dismissed with the OK button, to * handle potentially conflicting option settings. diff --git a/sfx2/source/bastyp/fltfnc.cxx b/sfx2/source/bastyp/fltfnc.cxx index 78b3607dadba..43e0f1009880 100644 --- a/sfx2/source/bastyp/fltfnc.cxx +++ b/sfx2/source/bastyp/fltfnc.cxx @@ -1087,7 +1087,7 @@ void SfxFilterContainer::ReadSingleFilter_Impl( } else { - pFilter->aFilterName = sFilterName; + pFilter->maFilterName = sFilterName; pFilter->aWildCard = WildCard(sExtension, ';'); pFilter->nFormatType = nFlags; pFilter->lFormat = nClipboardId; diff --git a/sfx2/source/doc/docfile.cxx b/sfx2/source/doc/docfile.cxx index 3d57ae8b1499..79e32c374e08 100644 --- a/sfx2/source/doc/docfile.cxx +++ b/sfx2/source/doc/docfile.cxx @@ -125,6 +125,7 @@ #include "officecfg/Office/Common.hxx" #include <boost/noncopyable.hpp> +#include <boost/scoped_ptr.hpp> using namespace ::com::sun::star; using namespace ::com::sun::star::uno; @@ -278,6 +279,8 @@ public: mutable INetURLObject* m_pURLObj; const SfxFilter* m_pFilter; + boost::scoped_ptr<SfxFilter> m_pCustomFilter; + SfxMedium* pAntiImpl; SvStream* m_pInStream; SvStream* m_pOutStream; @@ -2869,26 +2872,26 @@ SfxMedium::SfxMedium( const uno::Sequence<beans::PropertyValue>& aArgs ) : pImp->m_pSet = pParams; TransformParameters( SID_OPENDOC, aArgs, *pParams ); - OUString aFilterProvider; + OUString aFilterProvider, aFilterName; { const SfxPoolItem* pItem = NULL; if (pImp->m_pSet->HasItem(SID_FILTER_PROVIDER, &pItem)) aFilterProvider = static_cast<const SfxStringItem*>(pItem)->GetValue(); + + if (pImp->m_pSet->HasItem(SID_FILTER_NAME, &pItem)) + aFilterName = static_cast<const SfxStringItem*>(pItem)->GetValue(); } if (aFilterProvider.isEmpty()) { // This is a conventional filter type. - OUString aFilterName; - SFX_ITEMSET_ARG( pImp->m_pSet, pFilterNameItem, SfxStringItem, SID_FILTER_NAME, false ); - if( pFilterNameItem ) - aFilterName = pFilterNameItem->GetValue(); pImp->m_pFilter = SFX_APP()->GetFilterMatcher().GetFilter4FilterName( aFilterName ); } else { // This filter is from an external provider such as orcus. - + pImp->m_pCustomFilter.reset(new SfxFilter(aFilterProvider, aFilterName)); + pImp->m_pFilter = pImp->m_pCustomFilter.get(); } SFX_ITEMSET_ARG( pImp->m_pSet, pSalvageItem, SfxStringItem, SID_DOC_SALVAGE, false ); diff --git a/sfx2/source/doc/docfilt.cxx b/sfx2/source/doc/docfilt.cxx index ce95b9b46300..d642f02ace72 100644 --- a/sfx2/source/doc/docfilt.cxx +++ b/sfx2/source/doc/docfilt.cxx @@ -40,6 +40,12 @@ using namespace ::com::sun::star; DBG_NAME(SfxFilter) +SfxFilter::SfxFilter( const OUString& rProvider, const OUString &rFilterName ) : + maFilterName(rFilterName), + maProvider(rProvider) +{ +} + SfxFilter::SfxFilter( const OUString &rName, const OUString &rWildCard, SfxFilterFlags nType, @@ -54,8 +60,8 @@ SfxFilter::SfxFilter( const OUString &rName, aUserData(rUsrDat), aServiceName(rServiceName), aMimeType(rMimeType), - aFilterName(rName), - aUIName(aFilterName), + maFilterName(rName), + aUIName(maFilterName), nFormatType(nType), nVersion(SOFFICE_FILEFORMAT_50), lFormat(lFmt), @@ -101,6 +107,11 @@ OUString SfxFilter::GetDefaultExtension() const return comphelper::string::getToken(GetWildcard().getGlob(), 0, ';'); } +const OUString& SfxFilter::GetProviderName() const +{ + return maProvider; +} + void SfxFilter::SetURLPattern( const OUString& rStr ) { aPattern = rStr.toAsciiLowerCase(); diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx index 0008014b87e8..a6fef7693f60 100644 --- a/sfx2/source/doc/objstor.cxx +++ b/sfx2/source/doc/objstor.cxx @@ -858,10 +858,10 @@ sal_Bool SfxObjectShell::DoLoad( SfxMedium *pMed ) return bOk; } -bool SfxObjectShell::DoLoadExternal(SfxMedium *pMed, const OUString& rProvider) +bool SfxObjectShell::DoLoadExternal( SfxMedium *pMed ) { pMedium = pMed; - return LoadExternal(*pMedium, rProvider); + return LoadExternal(*pMedium); } sal_uInt32 SfxObjectShell::HandleFilter( SfxMedium* pMedium, SfxObjectShell* pDoc ) @@ -3606,7 +3606,7 @@ void SfxObjectShell::UpdateLinks() { } -bool SfxObjectShell::LoadExternal(SfxMedium&, const OUString&) +bool SfxObjectShell::LoadExternal( SfxMedium& ) { // Not implemented. It's an error if the code path ever comes here. return false; diff --git a/sfx2/source/doc/sfxbasemodel.cxx b/sfx2/source/doc/sfxbasemodel.cxx index 3cfec8c97554..a333a984af56 100644 --- a/sfx2/source/doc/sfxbasemodel.cxx +++ b/sfx2/source/doc/sfxbasemodel.cxx @@ -1854,8 +1854,11 @@ void SAL_CALL SfxBaseModel::load( const Sequence< beans::PropertyValue >& seqA OUString aFilterProvider = getFilterProvider(seqArguments); if (!aFilterProvider.isEmpty()) { - if (!m_pData->m_pObjectShell->DoLoadExternal(pMedium, aFilterProvider)) + if (!m_pData->m_pObjectShell->DoLoadExternal(pMedium)) + { delete pMedium; + return; + } pMedium->SetUpdatePickList(false); return; |