Date: prev next · Thread: first prev next last
2011 Archives by date, by thread · List index


Hi,

more duplicate code cleanup.

Class SfxObjectShell has two nearly identical methods: ImportFrom and InsertFrom. The latter has a few lines of code more, so I've removed InsertFrom (which was added to the code base later than ImportFrom), added a boolean parameter to ImportFrom and adjusted the few calls to those methods. And InsertFrom is not virtual like ImportFrom. Please review the attached patches. I'll commit them if I get an "ok".

The changes affect three modules (libs-core/sfx2, writer/sw and impress/sd).

Christina
From 1d3cb5eb3e62600cba485595c5d3ed03809137e3 Mon Sep 17 00:00:00 2001
From: Christina Rossmanith <ChrRossmanith@web.de>
Date: Tue, 31 May 2011 13:56:08 +0200
Subject: [PATCH] Duplicate code: join ImportFrom and InsertFrom

---
 sd/source/ui/docshell/docshel4.cxx |    4 ++--
 sd/source/ui/inc/DrawDocShell.hxx  |    2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/sd/source/ui/docshell/docshel4.cxx b/sd/source/ui/docshell/docshel4.cxx
index ce7e946..9f9d8a5 100644
--- a/sd/source/ui/docshell/docshel4.cxx
+++ b/sd/source/ui/docshell/docshel4.cxx
@@ -406,9 +406,9 @@ sal_Bool DrawDocShell::LoadFrom( SfxMedium& rMedium )
 |*
 \************************************************************************/
 
-sal_Bool DrawDocShell::ImportFrom( SfxMedium &rMedium )
+sal_Bool DrawDocShell::ImportFrom( SfxMedium &rMedium, bool bInsert )
 {
-    const sal_Bool bRet=SfxObjectShell::ImportFrom(rMedium);
+    const sal_Bool bRet=SfxObjectShell::ImportFrom(rMedium, bInsert);
 
     SfxItemSet* pSet = rMedium.GetItemSet();
     if( pSet )
diff --git a/sd/source/ui/inc/DrawDocShell.hxx b/sd/source/ui/inc/DrawDocShell.hxx
index 7ed7f13..e74aeaf 100644
--- a/sd/source/ui/inc/DrawDocShell.hxx
+++ b/sd/source/ui/inc/DrawDocShell.hxx
@@ -90,7 +90,7 @@ public:
     virtual void               Activate( sal_Bool bMDI );
     virtual void               Deactivate( sal_Bool bMDI );
     virtual sal_Bool            InitNew( const ::com::sun::star::uno::Reference< 
::com::sun::star::embed::XStorage >& xStorage );
-    virtual sal_Bool        ImportFrom( SfxMedium &rMedium );
+    virtual sal_Bool        ImportFrom( SfxMedium &rMedium, bool bInsert=false );
     virtual sal_Bool            ConvertFrom( SfxMedium &rMedium );
     virtual sal_Bool           Save();
     virtual sal_Bool            SaveAsOwnFormat( SfxMedium& rMedium );
-- 
1.7.4.1

From 62f072f27797b36d93fae3fe4a95207c3c1d034a Mon Sep 17 00:00:00 2001
From: Christina Rossmanith <ChrRossmanith@web.de>
Date: Tue, 31 May 2011 13:52:53 +0200
Subject: [PATCH] Duplicate code: join ImportFrom and InsertFrom

---
 sfx2/inc/sfx2/objsh.hxx     |    3 +-
 sfx2/source/doc/objstor.cxx |  101 +++----------------------------------------
 2 files changed, 7 insertions(+), 97 deletions(-)

diff --git a/sfx2/inc/sfx2/objsh.hxx b/sfx2/inc/sfx2/objsh.hxx
index 30c4361..ceba796 100644
--- a/sfx2/inc/sfx2/objsh.hxx
+++ b/sfx2/inc/sfx2/objsh.hxx
@@ -344,8 +344,7 @@ public:
                                     sal_Bool bForceNonModified = sal_False );
     sal_Bool                    SaveCompletedChildren( sal_Bool bSuccess );
 
-    sal_Bool                    InsertFrom( SfxMedium &rMedium );
-    virtual sal_Bool            ImportFrom( SfxMedium &rMedium );
+    virtual sal_Bool            ImportFrom( SfxMedium &rMedium, bool bInsert );
     sal_Bool                    ExportTo( SfxMedium &rMedium );
 
     // xmlsec05, check with SFX team
diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx
index 0e2860e..1936ae2 100644
--- a/sfx2/source/doc/objstor.cxx
+++ b/sfx2/source/doc/objstor.cxx
@@ -703,7 +703,7 @@ sal_Bool SfxObjectShell::DoLoad( SfxMedium *pMed )
                 {
                     bSetProperty = false;
                 }
-                bOk = ImportFrom(*pMedium);
+                bOk = ImportFrom( *pMedium, false );
                 if(bSetProperty)
                 {
                     try
@@ -2114,7 +2114,7 @@ sal_Bool SfxObjectShell::ConvertFrom
     return sal_False;
 }
 
-sal_Bool SfxObjectShell::InsertFrom( SfxMedium& rMedium )
+sal_Bool SfxObjectShell::ImportFrom( SfxMedium& rMedium, bool bInsert )
 {
     ::rtl::OUString aTypeName( rMedium.GetFilter()->GetTypeName() );
     ::rtl::OUString aFilterName( rMedium.GetFilter()->GetFilterName() );
@@ -2197,99 +2197,10 @@ sal_Bool SfxObjectShell::InsertFrom( SfxMedium& rMedium )
             aArgs[nEnd-1].Value <<= rMedium.GetBaseURL();
         }
 
-        aArgs.realloc( ++nEnd );
-        aArgs[nEnd-1].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "InsertMode" ) );
-        aArgs[nEnd-1].Value <<= (sal_Bool) sal_True;
-
-        return xLoader->filter( aArgs );
-        }catch(const uno::Exception&)
-        {}
-    }
-
-    return sal_False;
-}
-
-sal_Bool SfxObjectShell::ImportFrom( SfxMedium& rMedium )
-{
-    ::rtl::OUString aTypeName( rMedium.GetFilter()->GetTypeName() );
-    ::rtl::OUString aFilterName( rMedium.GetFilter()->GetFilterName() );
-
-    uno::Reference< lang::XMultiServiceFactory >  xMan = ::comphelper::getProcessServiceFactory();
-    uno::Reference < lang::XMultiServiceFactory > xFilterFact (
-                xMan->createInstance( DEFINE_CONST_UNICODE( "com.sun.star.document.FilterFactory" 
) ), uno::UNO_QUERY );
-
-    uno::Sequence < beans::PropertyValue > aProps;
-    uno::Reference < container::XNameAccess > xFilters ( xFilterFact, uno::UNO_QUERY );
-    if ( xFilters->hasByName( aFilterName ) )
-    {
-        xFilters->getByName( aFilterName ) >>= aProps;
-        rMedium.GetItemSet()->Put( SfxStringItem( SID_FILTER_NAME, aFilterName ) );
-    }
-
-    ::rtl::OUString aFilterImplName;
-    sal_Int32 nFilterProps = aProps.getLength();
-    for ( sal_Int32 nFilterProp = 0; nFilterProp<nFilterProps; nFilterProp++ )
-    {
-        const beans::PropertyValue& rFilterProp = aProps[nFilterProp];
-        if ( rFilterProp.Name.compareToAscii("FilterService") == COMPARE_EQUAL )
-        {
-            rFilterProp.Value >>= aFilterImplName;
-            break;
-        }
-    }
-
-    uno::Reference< document::XFilter > xLoader;
-    if ( aFilterImplName.getLength() )
-    {
-        try{
-        xLoader = uno::Reference< document::XFilter >
-            ( xFilterFact->createInstanceWithArguments( aFilterName, uno::Sequence < uno::Any >() 
), uno::UNO_QUERY );
-        }catch(const uno::Exception&)
-            { xLoader.clear(); }
-    }
-    if ( xLoader.is() )
-    {
-        // it happens that xLoader does not support xImporter!
-        try{
-        uno::Reference< lang::XComponent >  xComp( GetModel(), uno::UNO_QUERY_THROW );
-        uno::Reference< document::XImporter > xImporter( xLoader, uno::UNO_QUERY_THROW );
-        xImporter->setTargetDocument( xComp );
-
-        uno::Sequence < beans::PropertyValue > lDescriptor;
-        rMedium.GetItemSet()->Put( SfxStringItem( SID_FILE_NAME, rMedium.GetName() ) );
-        TransformItems( SID_OPENDOC, *rMedium.GetItemSet(), lDescriptor );
-
-        com::sun::star::uno::Sequence < com::sun::star::beans::PropertyValue > aArgs ( 
lDescriptor.getLength() );
-        com::sun::star::beans::PropertyValue * pNewValue = aArgs.getArray();
-        const com::sun::star::beans::PropertyValue * pOldValue = lDescriptor.getConstArray();
-        const OUString sInputStream ( RTL_CONSTASCII_USTRINGPARAM ( "InputStream" ) );
-
-        sal_Bool bHasInputStream = sal_False;
-        sal_Bool bHasBaseURL = sal_False;
-        sal_Int32 i;
-        sal_Int32 nEnd = lDescriptor.getLength();
-
-        for ( i = 0; i < nEnd; i++ )
-        {
-            pNewValue[i] = pOldValue[i];
-            if ( pOldValue [i].Name == sInputStream )
-                bHasInputStream = sal_True;
-            else if ( pOldValue[i].Name.equalsAsciiL ( RTL_CONSTASCII_STRINGPARAM ( 
"DocumentBaseURL" ) ) )
-                bHasBaseURL = sal_True;
-        }
-
-        if ( !bHasInputStream )
-        {
-            aArgs.realloc ( ++nEnd );
-            aArgs[nEnd-1].Name = sInputStream;
-            aArgs[nEnd-1].Value <<= com::sun::star::uno::Reference < 
com::sun::star::io::XInputStream > ( new utl::OSeekableInputStreamWrapper ( *rMedium.GetInStream() 
) );
-        }
-
-        if ( !bHasBaseURL )
-        {
-            aArgs.realloc ( ++nEnd );
-            aArgs[nEnd-1].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "DocumentBaseURL" 
) );
-            aArgs[nEnd-1].Value <<= rMedium.GetBaseURL();
+        if ( bInsert ) {
+            aArgs.realloc( ++nEnd );
+            aArgs[nEnd-1].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "InsertMode" ) );
+            aArgs[nEnd-1].Value <<= (sal_Bool) sal_True;
         }
 
         return xLoader->filter( aArgs );
-- 
1.7.4.1

From a7306fc17dff28e18da64e721c06c0b231baf4c3 Mon Sep 17 00:00:00 2001
From: Christina Rossmanith <ChrRossmanith@web.de>
Date: Tue, 31 May 2011 13:55:41 +0200
Subject: [PATCH] Duplicate code: join ImportFrom and InsertFrom

---
 sw/source/ui/uiview/view2.cxx |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/sw/source/ui/uiview/view2.cxx b/sw/source/ui/uiview/view2.cxx
index 5483aa6..6498ddc 100644
--- a/sw/source/ui/uiview/view2.cxx
+++ b/sw/source/ui/uiview/view2.cxx
@@ -2035,7 +2035,7 @@ long SwView::InsertMedium( sal_uInt16 nSlotId, SfxMedium* pMedium, sal_Int16 
nVe
                     else
                     {
                         ::sw::UndoGuard const ug(pDoc->GetIDocumentUndoRedo());
-                        nErrno = pDocSh->InsertFrom( *pMedium ) ? 0 : ERR_SWG_READ_ERROR;
+                        nErrno = pDocSh->ImportFrom( *pMedium, true ) ? 0 : ERR_SWG_READ_ERROR;
                     }
 
                 }
-- 
1.7.4.1


Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.