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. Change-Id: Ie0a075bbfe6eaa1f66726c456105dcdef9001d30
This commit is contained in:
13
sw/qa/extras/rtfimport/data/fdo64637.rtf
Normal file
13
sw/qa/extras/rtfimport/data/fdo64637.rtf
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
{\rtf1
|
||||||
|
{\info
|
||||||
|
{\upr
|
||||||
|
{\company aaa}
|
||||||
|
{\*\ud
|
||||||
|
{\company
|
||||||
|
bbb
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foo
|
||||||
|
}
|
@@ -155,6 +155,7 @@ public:
|
|||||||
void testGroupshape();
|
void testGroupshape();
|
||||||
void testFdo66565();
|
void testFdo66565();
|
||||||
void testFdo54900();
|
void testFdo54900();
|
||||||
|
void testFdo64637();
|
||||||
|
|
||||||
CPPUNIT_TEST_SUITE(Test);
|
CPPUNIT_TEST_SUITE(Test);
|
||||||
#if !defined(MACOSX) && !defined(WNT)
|
#if !defined(MACOSX) && !defined(WNT)
|
||||||
@@ -294,6 +295,7 @@ void Test::run()
|
|||||||
{"groupshape.rtf", &Test::testGroupshape},
|
{"groupshape.rtf", &Test::testGroupshape},
|
||||||
{"fdo66565.rtf", &Test::testFdo66565},
|
{"fdo66565.rtf", &Test::testFdo66565},
|
||||||
{"fdo54900.rtf", &Test::testFdo54900},
|
{"fdo54900.rtf", &Test::testFdo54900},
|
||||||
|
{"fdo64637.rtf", &Test::testFdo64637},
|
||||||
};
|
};
|
||||||
header();
|
header();
|
||||||
for (unsigned int i = 0; i < SAL_N_ELEMENTS(aMethods); ++i)
|
for (unsigned int i = 0; i < SAL_N_ELEMENTS(aMethods); ++i)
|
||||||
@@ -1432,6 +1434,14 @@ void Test::testFdo54900()
|
|||||||
CPPUNIT_ASSERT_EQUAL(style::ParagraphAdjust_CENTER, static_cast<style::ParagraphAdjust>(getProperty<sal_Int16>(getParagraphOfText(1, xCell->getText()), "ParaAdjust")));
|
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_TEST_SUITE_REGISTRATION(Test);
|
||||||
|
|
||||||
CPPUNIT_PLUGIN_IMPLEMENT();
|
CPPUNIT_PLUGIN_IMPLEMENT();
|
||||||
|
@@ -4045,11 +4045,16 @@ int RTFDocumentImpl::popState()
|
|||||||
case DESTINATION_COMPANY:
|
case DESTINATION_COMPANY:
|
||||||
{
|
{
|
||||||
OUString aName = aState.nDestinationState == DESTINATION_OPERATOR ? OUString("Operator") : OUString("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())
|
if (m_xDocumentProperties.is())
|
||||||
{
|
{
|
||||||
uno::Reference<beans::XPropertyContainer> xUserDefinedProperties = m_xDocumentProperties->getUserDefinedProperties();
|
uno::Reference<beans::XPropertyContainer> xUserDefinedProperties = m_xDocumentProperties->getUserDefinedProperties();
|
||||||
xUserDefinedProperties->addProperty(aName, beans::PropertyAttribute::REMOVABLE,
|
uno::Reference<beans::XPropertySet> xPropertySet(xUserDefinedProperties, uno::UNO_QUERY);
|
||||||
uno::makeAny(m_aStates.top().aDestinationText.makeStringAndClear()));
|
uno::Reference<beans::XPropertySetInfo> xPropertySetInfo = xPropertySet->getPropertySetInfo();
|
||||||
|
if (xPropertySetInfo->hasPropertyByName(aName))
|
||||||
|
xPropertySet->setPropertyValue(aName, aValue);
|
||||||
|
else
|
||||||
|
xUserDefinedProperties->addProperty(aName, beans::PropertyAttribute::REMOVABLE, aValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
Reference in New Issue
Block a user