summaryrefslogtreecommitdiff
path: root/writerfilter
diff options
context:
space:
mode:
authorJacobo Aragunde Pérez <jaragunde@igalia.com>2014-03-22 19:52:12 +0100
committerJacobo Aragunde Pérez <jaragunde@igalia.com>2014-03-22 23:58:15 +0100
commite55a4222e694d4354d3c46e6d6aa8d4e7e1ff898 (patch)
tree05b7b25bfbfae23c705dd544c90d91b601f3f092 /writerfilter
parentc6ff03f37a6898f50a5ca07152168fb4fe911e05 (diff)
ooxml: Make SdtHelper grab bag more generic
Flexibilize the way the grab bag in SdtHelper works, enabling it to store several children of SdtPr. For every tag inside SdtPr, we enable the DomainMapper grab bag, store the children properties there, and insert the full grab bag inside the SdtHelper grab bag. In this way, the SdtHelper grab bag becomes a Sequence of pairs "SdtPr token name" -> "Bag with children tokens and values". The first advantage of this implementation is that we can preserve dataBinding sdt property plus another one of those supported; until now the second property overwrote the first one in SdtHelper bag. In further patches we will add support for other tags. Some lines are incorrectly indented to make the purpose of this patch more evident, and will be corrected in the next patch. Change-Id: I0ec7be7b96dca455bbbeb03fc2fed230df04c52a
Diffstat (limited to 'writerfilter')
-rw-r--r--writerfilter/source/dmapper/DomainMapper.cxx22
-rw-r--r--writerfilter/source/dmapper/SdtHelper.cxx44
-rw-r--r--writerfilter/source/dmapper/SdtHelper.hxx9
3 files changed, 37 insertions, 38 deletions
diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx
index f57c142bcd7b..d8d14e6f62db 100644
--- a/writerfilter/source/dmapper/DomainMapper.cxx
+++ b/writerfilter/source/dmapper/DomainMapper.cxx
@@ -903,7 +903,7 @@ void DomainMapper::lcl_attribute(Id nName, Value & val)
case NS_ooxml::LN_CT_DataBinding_storeItemID:
{
OUString sName = OUString::createFromAscii((*QNameToString::Instance())(nName).c_str());
- m_pImpl->m_pSdtHelper->appendToInteropGrabBag(sName, uno::Any(sStringValue));
+ m_pImpl->appendGrabBag(m_pImpl->m_aInteropGrabBag, sName, sStringValue);
}
break;
default:
@@ -2253,12 +2253,15 @@ void DomainMapper::sprmWithProps( Sprm& rSprm, PropertyMapPtr rContext )
{
// this is an unsupported SDT property, create a grab bag for it
OUString sName = OUString::createFromAscii((*QNameToString::Instance())(nSprmId).c_str());
- m_pImpl->m_pSdtHelper->enableInteropGrabBag(sName);
+ enableInteropGrabBag(sName);
// process subitems
writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
if (pProperties.get() != NULL)
pProperties->resolve(*this);
+
+ m_pImpl->m_pSdtHelper->appendToInteropGrabBag(getInteropGrabBag());
+ m_pImpl->disableInteropGrabBag();
}
break;
case NS_ooxml::LN_CT_SdtCheckbox_checked:
@@ -2270,7 +2273,7 @@ void DomainMapper::sprmWithProps( Sprm& rSprm, PropertyMapPtr rContext )
{
// this is a child of an unsupported SDT property, store in the grab bag
OUString sName = OUString::createFromAscii((*QNameToString::Instance())(nSprmId).c_str());
- m_pImpl->m_pSdtHelper->appendToInteropGrabBag(sName, uno::Any(sStringValue));
+ m_pImpl->appendGrabBag(m_pImpl->m_aInteropGrabBag, sName, sStringValue);
}
break;
case NS_ooxml::LN_EG_SectPrContents_pgNumType:
@@ -2659,16 +2662,17 @@ void DomainMapper::lcl_utext(const sal_uInt8 * data_, size_t len)
m_pImpl->m_pSdtHelper->createDateControl(sText);
return;
}
- else if (m_pImpl->m_pSdtHelper->isInteropGrabBagEnabled())
+ else if (!m_pImpl->m_pSdtHelper->isInteropGrabBagEmpty())
{
// there are unsupported SDT properties in the document
// save them in the paragraph interop grab bag
- OUString sName = m_pImpl->m_pSdtHelper->getInteropGrabBagName();
- uno::Any aPropValue = uno::makeAny(m_pImpl->m_pSdtHelper->getInteropGrabBagAndClear());
- if(sName == "ooxml:CT_SdtPr_checkbox" || sName == "ooxml:CT_SdtPr_dataBinding")
- m_pImpl->GetTopContextOfType(CONTEXT_CHARACTER)->Insert(PROP_SDTPR, aPropValue, true, CHAR_GRAB_BAG);
+ if(m_pImpl->m_pSdtHelper->containedInInteropGrabBag("ooxml:CT_SdtPr_checkbox") ||
+ m_pImpl->m_pSdtHelper->containedInInteropGrabBag("ooxml:CT_SdtPr_dataBinding"))
+ m_pImpl->GetTopContextOfType(CONTEXT_CHARACTER)->Insert(PROP_SDTPR,
+ uno::makeAny(m_pImpl->m_pSdtHelper->getInteropGrabBagAndClear()), true, CHAR_GRAB_BAG);
else
- m_pImpl->GetTopContextOfType(CONTEXT_PARAGRAPH)->Insert(PROP_SDTPR, aPropValue, true, PARA_GRAB_BAG);
+ m_pImpl->GetTopContextOfType(CONTEXT_PARAGRAPH)->Insert(PROP_SDTPR,
+ uno::makeAny(m_pImpl->m_pSdtHelper->getInteropGrabBagAndClear()), true, PARA_GRAB_BAG);
}
else if (len == 1 && sText[0] == 0x03)
{
diff --git a/writerfilter/source/dmapper/SdtHelper.cxx b/writerfilter/source/dmapper/SdtHelper.cxx
index 2ff928bd89cf..daf9b81455da 100644
--- a/writerfilter/source/dmapper/SdtHelper.cxx
+++ b/writerfilter/source/dmapper/SdtHelper.cxx
@@ -190,42 +190,38 @@ bool SdtHelper::hasElements()
void SdtHelper::appendToInteropGrabBag(const OUString& rName, const css::uno::Any& rValue)
{
- if (isInteropGrabBagEnabled())
- {
- sal_Int32 nLength = m_aGrabBag.getLength();
- m_aGrabBag.realloc(nLength + 1);
- m_aGrabBag[nLength].Name = rName;
- m_aGrabBag[nLength].Value = rValue;
- }
+ sal_Int32 nLength = m_aGrabBag.getLength();
+ m_aGrabBag.realloc(nLength + 1);
+ m_aGrabBag[nLength].Name = rName;
+ m_aGrabBag[nLength].Value = rValue;
}
-beans::PropertyValue SdtHelper::getInteropGrabBagAndClear()
+void SdtHelper::appendToInteropGrabBag(com::sun::star::beans::PropertyValue rValue)
{
- beans::PropertyValue aProp;
- if (isInteropGrabBagEnabled())
- {
- aProp.Name = m_sGrabBagName;
- aProp.Value = uno::Any(m_aGrabBag);
-
- m_aGrabBag.realloc(0);
- m_sGrabBagName = "";
- }
- return aProp;
+ sal_Int32 nLength = m_aGrabBag.getLength();
+ m_aGrabBag.realloc(nLength + 1);
+ m_aGrabBag[nLength] = rValue;
}
-void SdtHelper::enableInteropGrabBag(const OUString& rName)
+com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue> SdtHelper::getInteropGrabBagAndClear()
{
- m_sGrabBagName = rName;
+ com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue> aRet = m_aGrabBag;
+ m_aGrabBag.realloc(0);
+ return aRet;
}
-bool SdtHelper::isInteropGrabBagEnabled()
+bool SdtHelper::isInteropGrabBagEmpty()
{
- return !m_sGrabBagName.isEmpty();
+ return m_aGrabBag.getLength() == 0;
}
-OUString SdtHelper::getInteropGrabBagName()
+bool SdtHelper::containedInInteropGrabBag(OUString rValueName)
{
- return m_sGrabBagName;
+ for (sal_Int32 i=0; i < m_aGrabBag.getLength(); ++i)
+ if (m_aGrabBag[i].Name == rValueName)
+ return true;
+
+ return false;
}
} // namespace dmapper
diff --git a/writerfilter/source/dmapper/SdtHelper.hxx b/writerfilter/source/dmapper/SdtHelper.hxx
index 8f70de9fba10..a69628729ad2 100644
--- a/writerfilter/source/dmapper/SdtHelper.hxx
+++ b/writerfilter/source/dmapper/SdtHelper.hxx
@@ -59,7 +59,6 @@ class SdtHelper
OUStringBuffer m_sLocale;
/// Grab bag to store unsupported SDTs, aiming to save them back on export.
com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue> m_aGrabBag;
- OUString m_sGrabBagName;
bool m_bHasElements;
@@ -85,10 +84,10 @@ public:
void createDateControl(OUString& rContentText);
void appendToInteropGrabBag(const OUString& rName, const css::uno::Any& rValue);
- com::sun::star::beans::PropertyValue getInteropGrabBagAndClear();
- void enableInteropGrabBag(const OUString& rName);
- bool isInteropGrabBagEnabled();
- OUString getInteropGrabBagName();
+ void appendToInteropGrabBag(com::sun::star::beans::PropertyValue rValue);
+ com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue> getInteropGrabBagAndClear();
+ bool isInteropGrabBagEmpty();
+ bool containedInInteropGrabBag(OUString rValueName);
};
} // namespace dmapper