framework/source/loadenv/loadenv.cxx | 8 ++- sc/inc/orcusfilters.hxx | 4 + sc/source/filter/inc/orcusfiltersimpl.hxx | 2 sc/source/filter/orcus/orcusfiltersimpl.cxx | 42 ++++++++++++++++ sc/source/ui/docshell/docsh.cxx | 31 ++++++++++-- sc/source/ui/inc/docsh.hxx | 2 sfx2/inc/sfx2/docfilt.hxx | 19 +++++-- sfx2/inc/sfx2/objsh.hxx | 4 - sfx2/source/bastyp/fltfnc.cxx | 2 sfx2/source/doc/docfile.cxx | 71 +++++++++++++--------------- sfx2/source/doc/docfilt.cxx | 15 +++++ sfx2/source/doc/objstor.cxx | 6 +- sfx2/source/doc/sfxbasemodel.cxx | 5 + 13 files changed, 154 insertions(+), 57 deletions(-)
New commits: commit 2733c20610d5b508c929e74e830764b8e1591336 Author: Kohei Yoshida <kohei.yosh...@gmail.com> Date: Tue Apr 9 15:36:03 2013 -0400 Manage to use orcus to import ods, xlsx, and csv. But this occasionally crashes. Change-Id: I0a18d0e210639b43b89b966a54de541b9a43e329 diff --git a/framework/source/loadenv/loadenv.cxx b/framework/source/loadenv/loadenv.cxx index 86646d5..c824222 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 ef88795..ab09d8c 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 de5f988..e07cd19 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 e74a5e4..7ef1310 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 1694255..0cc10bd 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 a26a234..d761f7f 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 8400e5a..cc6f6b8 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 5f1018e..4c366a5 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 78b3607..43e0f10 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 3d57ae8..79e32c3 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 ce95b9b..d642f02 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 223ae5e..350785e 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 ) @@ -3586,7 +3586,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 3cfec8c..a333a98 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; commit 76677cf2e1d5e87672d5ecf5303df58f98eb88e4 Author: Kohei Yoshida <kohei.yosh...@gmail.com> Date: Tue Apr 9 14:50:18 2013 -0400 Make the impl class explicitly non-copyable. Change-Id: I58971205bcb0c9f397c64556c84114c0390e8e96 diff --git a/sfx2/source/doc/docfile.cxx b/sfx2/source/doc/docfile.cxx index a339ee4..3d57ae8 100644 --- a/sfx2/source/doc/docfile.cxx +++ b/sfx2/source/doc/docfile.cxx @@ -88,12 +88,6 @@ #include <rtl/logfile.hxx> #include <osl/file.hxx> -using namespace ::com::sun::star; -using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::ucb; -using namespace ::com::sun::star::beans; -using namespace ::com::sun::star::io; - #include <comphelper/storagehelper.hxx> #include <comphelper/mediadescriptor.hxx> #include <comphelper/configurationhelper.hxx> @@ -130,7 +124,14 @@ using namespace ::com::sun::star::io; #include "sfxacldetect.hxx" #include "officecfg/Office/Common.hxx" -//========================================================== +#include <boost/noncopyable.hpp> + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::ucb; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::io; + namespace { static const sal_Int8 LOCK_UI_NOLOCK = 0; @@ -243,8 +244,7 @@ void SAL_CALL SfxMediumHandler_Impl::handle( const com::sun::star::uno::Referenc m_xInter->handle( xRequest ); } -//---------------------------------------------------------------- -class SfxMedium_Impl +class SfxMedium_Impl : boost::noncopyable { public: StreamMode m_nStorOpenMode; commit f7eabb366dd8b404827614a47b9b3f54e45fd3e6 Author: Kohei Yoshida <kohei.yosh...@gmail.com> Date: Tue Apr 9 14:37:44 2013 -0400 Re-organize UNO interface members & use clear() to clear their refs. Change-Id: I815e77640c7c3816e5b9c83b567a8e2051cdb81f diff --git a/sfx2/source/doc/docfile.cxx b/sfx2/source/doc/docfile.cxx index 44f8d9d..a339ee4 100644 --- a/sfx2/source/doc/docfile.cxx +++ b/sfx2/source/doc/docfile.cxx @@ -274,9 +274,6 @@ public: OUString m_aLogicName; OUString m_aLongName; - uno::Reference < embed::XStorage > xStorage; - uno::Reference<io::XInputStream> m_xInputStreamToLoadFrom; - mutable SfxItemSet* m_pSet; mutable INetURLObject* m_pURLObj; @@ -297,27 +294,26 @@ public: ::utl::TempFile* pTempFile; - uno::Reference < embed::XStorage > m_xZipStorage; - Reference < XInputStream > xInputStream; - Reference < XStream > xStream; - - uno::Reference< io::XStream > m_xLockingStream; + uno::Reference<embed::XStorage> xStorage; + uno::Reference<embed::XStorage> m_xZipStorage; + uno::Reference<io::XInputStream> m_xInputStreamToLoadFrom; + uno::Reference<io::XInputStream> xInputStream; + uno::Reference<io::XStream> xStream; + uno::Reference<io::XStream> m_xLockingStream; + uno::Reference<task::XInteractionHandler> xInteraction; + uno::Reference<logging::XSimpleLogRing> m_xLogRing; sal_uInt32 nLastStorageError; - ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler > xInteraction; - OUString m_aBackupURL; - // the following member is changed and makes sence only during saving + // the following member is changed and makes sense only during saving // TODO/LATER: in future the signature state should be controlled by the medium not by the document // in this case the member will hold this information sal_uInt16 m_nSignatureState; util::DateTime m_aDateTime; - uno::Reference< logging::XSimpleLogRing > m_xLogRing; - SfxMedium_Impl( SfxMedium* pAntiImplP ); ~SfxMedium_Impl(); @@ -619,13 +615,13 @@ void SfxMedium::CloseInStream_Impl() pImp->m_pSet->ClearItem( SID_INPUTSTREAM ); CloseZipStorage_Impl(); - pImp->xInputStream = uno::Reference< io::XInputStream >(); + pImp->xInputStream.clear(); if ( !pImp->m_pOutStream ) { // output part of the stream is not used so the whole stream can be closed // TODO/LATER: is it correct? - pImp->xStream = uno::Reference< io::XStream >(); + pImp->xStream.clear(); if ( pImp->m_pSet ) pImp->m_pSet->ClearItem( SID_STREAM ); } @@ -685,7 +681,7 @@ sal_Bool SfxMedium::CloseOutStream_Impl() { // input part of the stream is not used so the whole stream can be closed // TODO/LATER: is it correct? - pImp->xStream = uno::Reference< io::XStream >(); + pImp->xStream.clear(); if ( pImp->m_pSet ) pImp->m_pSet->ClearItem( SID_STREAM ); } @@ -1403,7 +1399,7 @@ uno::Reference < embed::XStorage > SfxMedium::GetStorage( sal_Bool bCreateTempIf if ( bResetStorage ) { - pImp->xStorage = 0; + pImp->xStorage.clear(); if ( pImp->m_pInStream ) pImp->m_pInStream->Seek( 0L ); } @@ -1454,7 +1450,7 @@ void SfxMedium::CloseZipStorage_Impl() } catch( const uno::Exception& ) {} - pImp->m_xZipStorage = uno::Reference< embed::XStorage >(); + pImp->m_xZipStorage.clear(); } } @@ -1474,7 +1470,7 @@ void SfxMedium::CloseStorage() } } - pImp->xStorage = 0; + pImp->xStorage.clear(); pImp->bStorageBasedOnInStream = false; } @@ -2675,7 +2671,7 @@ void SfxMedium::UnlockFile( sal_Bool bReleaseLockStream ) {} } - pImp->m_xLockingStream = uno::Reference< io::XStream >(); + pImp->m_xLockingStream.clear(); } if ( pImp->m_bLocked ) @@ -2705,7 +2701,7 @@ void SfxMedium::CloseAndReleaseStreams_Impl() // if the locking stream is closed here the related member should be cleaned if ( pImp->xStream == pImp->m_xLockingStream ) - pImp->m_xLockingStream = uno::Reference< io::XStream >(); + pImp->m_xLockingStream.clear(); } // The probably exsisting SvStream wrappers should be closed first _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits