writerfilter/source/filter/ImportFilter.cxx |  186 ++++++++--------------------
 writerfilter/source/filter/WriterFilter.hxx |    3 
 2 files changed, 60 insertions(+), 129 deletions(-)

New commits:
commit 629706f24dcc9b4654f1d717a31d584769137a53
Author: Jacobo Aragunde Pérez <jaragu...@igalia.com>
Date:   Thu Dec 12 18:50:18 2013 +0100

    writerfilter: refactor code to fill document grab bag
    
    There were several chunks of identical code to add attributes to the
    document grab bag. I have refactored the common code to a method.
    
    Change-Id: Ia1de75280a7725ab9703b08b1b08e7a7d1e0a8f2

diff --git a/writerfilter/source/filter/ImportFilter.cxx 
b/writerfilter/source/filter/ImportFilter.cxx
index 708b9f7..2854088 100644
--- a/writerfilter/source/filter/ImportFilter.cxx
+++ b/writerfilter/source/filter/ImportFilter.cxx
@@ -119,140 +119,30 @@ sal_Bool WriterFilter::filter( const uno::Sequence< 
beans::PropertyValue >& aDes
 
         pDocument->resolve(*pStream);
 
-        // Adding the saved Theme DOM to the document's grab bag
-        try
-        {
-            uno::Reference<beans::XPropertySet> xDocProps(m_xDstDoc, 
uno::UNO_QUERY);
-            if (xDocProps.is())
-            {
-                uno::Reference<beans::XPropertySetInfo> xPropsInfo = 
xDocProps->getPropertySetInfo();
+        // Adding some properties to the document's grab bag for 
interoperability purposes:
+        uno::Sequence<beans::PropertyValue> aGrabBagProperties(6);
 
-                const OUString aGrabBagPropName = "InteropGrabBag";
-                if( xPropsInfo.is() && xPropsInfo->hasPropertyByName( 
aGrabBagPropName ) )
-                {
-                    uno::Sequence<beans::PropertyValue> aGrabBag;
-
-                    // We want to keep the previous items
-                    xDocProps->getPropertyValue( aGrabBagPropName ) >>= 
aGrabBag;
-                    sal_Int32 length = aGrabBag.getLength();
-                    aGrabBag.realloc(length+1);
+        // Adding the saved Theme DOM
+        aGrabBagProperties[0].Name = "OOXTheme";
+        aGrabBagProperties[0].Value = uno::makeAny( pDocument->getThemeDom() );
 
-                    uno::Reference<xml::dom::XDocument> aThemeDom = 
pDocument->getThemeDom();
+        // Adding the saved custom xml DOM
+        aGrabBagProperties[1].Name = "OOXCustomXml";
+        aGrabBagProperties[1].Value = uno::makeAny( 
pDocument->getCustomXmlDomList() );
+        aGrabBagProperties[2].Name = "OOXCustomXmlProps";
+        aGrabBagProperties[2].Value = uno::makeAny( 
pDocument->getCustomXmlDomPropsList() );
 
-                    beans::PropertyValue* pValue = aGrabBag.getArray();
-                    pValue[length].Name = "OOXTheme";
-                    pValue[length].Value = uno::makeAny( aThemeDom );
+        // Adding the saved ActiveX DOM
+        aGrabBagProperties[3].Name = "OOXActiveX";
+        aGrabBagProperties[3].Value = uno::makeAny( 
pDocument->getActiveXDomList() );
+        aGrabBagProperties[4].Name = "OOXActiveXBin";
+        aGrabBagProperties[4].Value = uno::makeAny( 
pDocument->getActiveXBinList() );
 
-                    xDocProps->setPropertyValue( aGrabBagPropName, uno::Any( 
aGrabBag ) );
-                }
-            }
-        }
-        catch(const uno::Exception&)
-        {
-            SAL_WARN("writerfilter","Failed to save theme dom to documents 
grab bag");
-        }
+        // Adding the saved w:themeFontLang setting
+        aGrabBagProperties[5].Name = "ThemeFontLangProps";
+        aGrabBagProperties[5].Value = uno::makeAny( 
aDomainMapper->GetThemeFontLangProperties() );
 
-        // Adding the saved custom xml DOM to the document's grab bag
-        try
-        {
-              uno::Reference<beans::XPropertySet> xDocProps(m_xDstDoc, 
uno::UNO_QUERY);
-              if (xDocProps.is())
-              {
-                  uno::Reference<beans::XPropertySetInfo> xPropsInfo = 
xDocProps->getPropertySetInfo();
-
-                  const OUString aGrabBagPropName = "InteropGrabBag";
-                  if( xPropsInfo.is() && xPropsInfo->hasPropertyByName( 
aGrabBagPropName ) )
-                  {
-                      uno::Sequence<beans::PropertyValue> aGrabBag;
-
-                      // We want to keep the previous items
-                      xDocProps->getPropertyValue( aGrabBagPropName ) >>= 
aGrabBag;
-                      sal_Int32 length = aGrabBag.getLength();
-                      aGrabBag.realloc(length+2);
-
-                      beans::PropertyValue* pValue = aGrabBag.getArray();
-                      pValue[length].Name = "OOXCustomXml";
-                      pValue[length].Value = uno::makeAny( 
pDocument->getCustomXmlDomList() );
-
-                      pValue[length+1].Name = "OOXCustomXmlProps";
-                      pValue[length+1].Value = uno::makeAny( 
pDocument->getCustomXmlDomPropsList() );
-
-                      xDocProps->setPropertyValue( aGrabBagPropName, uno::Any( 
aGrabBag ) );
-
-
-                  }
-              }
-        }
-        catch(const uno::Exception&)
-        {
-            SAL_WARN("writerfilter","Failed to save custom xml dom to 
documents grab bag");
-        }
-
-        // Adding the saved ActiveX DOM to the document's grab bag
-        try
-        {
-            uno::Reference<beans::XPropertySet> xDocProps(m_xDstDoc, 
uno::UNO_QUERY);
-            if (xDocProps.is())
-            {
-                uno::Reference<beans::XPropertySetInfo> xPropsInfo = 
xDocProps->getPropertySetInfo();
-
-                const OUString aGrabBagPropName = "InteropGrabBag";
-                if( xPropsInfo.is() && xPropsInfo->hasPropertyByName( 
aGrabBagPropName ) )
-                {
-                    uno::Sequence<beans::PropertyValue> aGrabBag;
-
-                    // We want to keep the previous items
-                    xDocProps->getPropertyValue( aGrabBagPropName ) >>= 
aGrabBag;
-                    sal_Int32 length = aGrabBag.getLength();
-                    aGrabBag.realloc(length+2);
-
-                    beans::PropertyValue* pValue = aGrabBag.getArray();
-                    pValue[length].Name = "OOXActiveX";
-                    pValue[length].Value = uno::makeAny( 
pDocument->getActiveXDomList() );
-
-                    pValue[length+1].Name = "OOXActiveXBin";
-                    pValue[length+1].Value = uno::makeAny( 
pDocument->getActiveXBinList() );
-
-                    xDocProps->setPropertyValue( aGrabBagPropName, uno::Any( 
aGrabBag ) );
-                 }
-             }
-         }
-         catch(const uno::Exception&)
-         {
-             SAL_WARN("writerfilter","Failed to save ActiveX dom to documents 
grab bag");
-         }
-
-         // Adding the saved w:themeFontLang setting to the document's grab bag
-         if ( aDomainMapper->GetThemeFontLangProperties().hasElements() )
-             try
-             {
-                 uno::Reference<beans::XPropertySet> xDocProps( m_xDstDoc, 
uno::UNO_QUERY );
-                 if (xDocProps.is())
-                 {
-                     uno::Reference< beans::XPropertySetInfo > xPropsInfo = 
xDocProps->getPropertySetInfo();
-
-                     const OUString aGrabBagPropName = "InteropGrabBag";
-                     if( xPropsInfo.is() && xPropsInfo->hasPropertyByName( 
aGrabBagPropName ) )
-                     {
-                         uno::Sequence< beans::PropertyValue > aGrabBag;
-
-                         // We want to keep the previous items
-                         xDocProps->getPropertyValue( aGrabBagPropName ) >>= 
aGrabBag;
-                         sal_Int32 length = aGrabBag.getLength();
-                         aGrabBag.realloc( length+1 );
-
-                         beans::PropertyValue* pValue = aGrabBag.getArray();
-                         pValue[length].Name = "ThemeFontLangProps";
-                         pValue[length].Value = uno::makeAny( 
aDomainMapper->GetThemeFontLangProperties() );
-
-                         xDocProps->setPropertyValue( aGrabBagPropName, 
uno::Any( aGrabBag ) );
-                     }
-                 }
-             }
-             catch(const uno::Exception&)
-             {
-                 SAL_WARN("writerfilter","Failed to save themeFontLang 
properties to documents grab bag");
-             }
+        putPropertiesToDocumentGrabBag( aGrabBagProperties );
 
         writerfilter::ooxml::OOXMLStream::Pointer_t  
pVBAProjectStream(writerfilter::ooxml::OOXMLDocumentFactory::createStream( 
pDocStream, writerfilter::ooxml::OOXMLStream::VBAPROJECT ));
         oox::StorageRef xVbaPrjStrg( new ::oox::ole::OleStorage( m_xContext, 
pVBAProjectStream->getDocumentStream(), false ) );
@@ -393,4 +283,42 @@ uno::Sequence< OUString > 
WriterFilter::getSupportedServiceNames(  ) throw (uno:
     return WriterFilter_getSupportedServiceNames();
 }
 
+void WriterFilter::putPropertiesToDocumentGrabBag( const uno::Sequence< 
beans::PropertyValue >& aProperties )
+{
+    try
+    {
+        uno::Reference<beans::XPropertySet> xDocProps(m_xDstDoc, 
uno::UNO_QUERY);
+        if( xDocProps.is() )
+        {
+            uno::Reference<beans::XPropertySetInfo> xPropsInfo = 
xDocProps->getPropertySetInfo();
+
+            const OUString aGrabBagPropName = "InteropGrabBag";
+            if( xPropsInfo.is() && xPropsInfo->hasPropertyByName( 
aGrabBagPropName ) )
+            {
+                // get existing grab bag
+                uno::Sequence<beans::PropertyValue> aGrabBag;
+                xDocProps->getPropertyValue( aGrabBagPropName ) >>= aGrabBag;
+                sal_Int32 length = aGrabBag.getLength();
+
+                // update grab bag size to contain the new items
+                aGrabBag.realloc( length + aProperties.getLength() );
+
+                // put the new items
+                for( sal_Int32 i=0; i < aProperties.getLength(); ++i )
+                {
+                    aGrabBag[length + i].Name = aProperties[i].Name;
+                    aGrabBag[length + i].Value = aProperties[i].Value;
+                }
+
+                // put it back to the document
+                xDocProps->setPropertyValue( aGrabBagPropName, uno::Any( 
aGrabBag ) );
+            }
+        }
+    }
+    catch(const uno::Exception&)
+    {
+        SAL_WARN("writerfilter","Failed to save documents grab bag");
+    }
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerfilter/source/filter/WriterFilter.hxx 
b/writerfilter/source/filter/WriterFilter.hxx
index d34de2c..6b8738f 100644
--- a/writerfilter/source/filter/WriterFilter.hxx
+++ b/writerfilter/source/filter/WriterFilter.hxx
@@ -77,6 +77,9 @@ public:
     virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL 
getSupportedServiceNames()
         throw (::com::sun::star::uno::RuntimeException);
 
+private:
+    void putPropertiesToDocumentGrabBag( const 
::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& 
aProperties );
+
 };
 
 
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to