[Libreoffice-commits] core.git: Branch 'libreoffice-4-1' - sw/qa writerfilter/source

Miklos Vajna vmiklos at suse.cz
Tue Jul 23 12:38:18 PDT 2013


 sw/qa/extras/rtfimport/data/fdo64637.rtf       |   13 +++++++++++++
 sw/qa/extras/rtfimport/rtfimport.cxx           |   10 ++++++++++
 writerfilter/source/rtftok/rtfdocumentimpl.cxx |    9 +++++++--
 3 files changed, 30 insertions(+), 2 deletions(-)

New commits:
commit 58a285d8d504c5ae952d314238dbbaa873b51db7
Author: Miklos Vajna <vmiklos at suse.cz>
Date:   Tue Jul 23 12:01:47 2013 +0200

    fdo#64637 RTF import: handle multiple RTF_COMPANY
    
    Instead of unconditionally calling addProperty(), first check the
    existence with hasPropertyByName() and call setPropertyValue() instead,
    if necessary.
    
    (cherry picked from commit bb67e709b70919efb41ec41e93dd92953dc6a003)
    
    Change-Id: Ie0a075bbfe6eaa1f66726c456105dcdef9001d30
    Reviewed-on: https://gerrit.libreoffice.org/5049
    Reviewed-by: Fridrich Strba <fridrich at documentfoundation.org>
    Tested-by: Fridrich Strba <fridrich at documentfoundation.org>

diff --git a/sw/qa/extras/rtfimport/data/fdo64637.rtf b/sw/qa/extras/rtfimport/data/fdo64637.rtf
new file mode 100644
index 0000000..9bec690
--- /dev/null
+++ b/sw/qa/extras/rtfimport/data/fdo64637.rtf
@@ -0,0 +1,13 @@
+{\rtf1
+{\info
+{\upr
+{\company aaa}
+{\*\ud
+{\company
+bbb
+}
+}
+}
+}
+foo
+}
diff --git a/sw/qa/extras/rtfimport/rtfimport.cxx b/sw/qa/extras/rtfimport/rtfimport.cxx
index 58353bf..9a6974f 100644
--- a/sw/qa/extras/rtfimport/rtfimport.cxx
+++ b/sw/qa/extras/rtfimport/rtfimport.cxx
@@ -146,6 +146,7 @@ public:
     void testFdo39001();
     void testFdo66565();
     void testFdo54900();
+    void testFdo64637();
 
     CPPUNIT_TEST_SUITE(Test);
 #if !defined(MACOSX) && !defined(WNT)
@@ -279,6 +280,7 @@ void Test::run()
         {"fdo39001.rtf", &Test::testFdo39001},
         {"fdo66565.rtf", &Test::testFdo66565},
         {"fdo54900.rtf", &Test::testFdo54900},
+        {"fdo64637.rtf", &Test::testFdo64637},
     };
     header();
     for (unsigned int i = 0; i < SAL_N_ELEMENTS(aMethods); ++i)
@@ -1343,6 +1345,14 @@ void Test::testFdo54900()
     CPPUNIT_ASSERT_EQUAL(style::ParagraphAdjust_CENTER, static_cast<style::ParagraphAdjust>(getProperty<sal_Int16>(getParagraphOfText(1, xCell->getText()), "ParaAdjust")));
 }
 
+void Test::testFdo64637()
+{
+    // The problem was that the custom "Company" property was added twice, the second invocation resulted in an exception.
+    uno::Reference<document::XDocumentPropertiesSupplier> xDocumentPropertiesSupplier(mxComponent, uno::UNO_QUERY);
+    uno::Reference<beans::XPropertySet> xPropertySet(xDocumentPropertiesSupplier->getDocumentProperties()->getUserDefinedProperties(), uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(OUString("bbb"), getProperty<OUString>(xPropertySet, "Company"));
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(Test);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index 5e93fc2..769191b 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -4006,11 +4006,16 @@ int RTFDocumentImpl::popState()
         case DESTINATION_COMPANY:
             {
                 OUString aName = aState.nDestinationState == DESTINATION_OPERATOR ? OUString("Operator") : OUString("Company");
+                uno::Any aValue = uno::makeAny(m_aStates.top().aDestinationText.makeStringAndClear());
                 if (m_xDocumentProperties.is())
                 {
                     uno::Reference<beans::XPropertyContainer> xUserDefinedProperties = m_xDocumentProperties->getUserDefinedProperties();
-                    xUserDefinedProperties->addProperty(aName, beans::PropertyAttribute::REMOVABLE,
-                            uno::makeAny(m_aStates.top().aDestinationText.makeStringAndClear()));
+                    uno::Reference<beans::XPropertySet> xPropertySet(xUserDefinedProperties, uno::UNO_QUERY);
+                    uno::Reference<beans::XPropertySetInfo> xPropertySetInfo = xPropertySet->getPropertySetInfo();
+                    if (xPropertySetInfo->hasPropertyByName(aName))
+                        xPropertySet->setPropertyValue(aName, aValue);
+                    else
+                        xUserDefinedProperties->addProperty(aName, beans::PropertyAttribute::REMOVABLE, aValue);
                 }
             }
             break;


More information about the Libreoffice-commits mailing list