diff options
author | Michael Stahl <mstahl@redhat.com> | 2012-09-13 11:15:13 +0200 |
---|---|---|
committer | Michael Stahl <mstahl@redhat.com> | 2012-09-14 15:04:15 +0200 |
commit | 22b615a7a54e6424bf3a492d2a07573ad9090949 (patch) | |
tree | cda368df108d59d2afa60a6700482d3fbee4a2cd /xmloff | |
parent | c45c64e3de51d9f56c9d9789729b6f7952547a61 (diff) |
fdo#30711: ODF export: "text:name" is mandatory on bookmarks:
XMLTextParagraphExport: Add a mapping that generates names for those
field marks that don't have a name so validators don't complain.
(regression from 7a1c5e54afe4e4ef7e17c2e9c969cd41221edc28)
There is still the problem that we cannot easily guarantee that the
names (generated or from some field param) do not clash with the names
of actual bookmarks...
Change-Id: I9ed65b94b3e8f725db4354222f2565176b32be52
Diffstat (limited to 'xmloff')
-rw-r--r-- | xmloff/inc/xmloff/txtparae.hxx | 3 | ||||
-rw-r--r-- | xmloff/source/text/txtparae.cxx | 69 |
2 files changed, 56 insertions, 16 deletions
diff --git a/xmloff/inc/xmloff/txtparae.hxx b/xmloff/inc/xmloff/txtparae.hxx index c5d3e75ce4f2..284e88fa550f 100644 --- a/xmloff/inc/xmloff/txtparae.hxx +++ b/xmloff/inc/xmloff/txtparae.hxx @@ -44,6 +44,7 @@ #include <xmloff/SinglePropertySetInfoCache.hxx> #include <xmloff/XMLStringVector.hxx> #include <vector> +#include <boost/scoped_ptr.hpp> class XMLTextListsHelper; class SvXMLExport; @@ -76,6 +77,8 @@ namespace xmloff class XMLOFF_DLLPUBLIC XMLTextParagraphExport : public XMLStyleExport { + struct Impl; + ::boost::scoped_ptr<Impl> m_pImpl; // SvXMLExport& rExport; SvXMLAutoStylePoolP& rAutoStylePool; diff --git a/xmloff/source/text/txtparae.cxx b/xmloff/source/text/txtparae.cxx index 6eba38b1c332..83ba6b3d3209 100644 --- a/xmloff/source/text/txtparae.cxx +++ b/xmloff/source/text/txtparae.cxx @@ -1152,11 +1152,36 @@ void XMLTextParagraphExport::exportListChange( } } +struct XMLTextParagraphExport::Impl +{ + typedef ::std::map<Reference<XFormField>, sal_Int32> FieldMarkMap_t; + FieldMarkMap_t m_FieldMarkMap; + + explicit Impl() {} + sal_Int32 AddFieldMarkStart(Reference<XFormField> const& i_xFieldMark) + { + assert(m_FieldMarkMap.find(i_xFieldMark) == m_FieldMarkMap.end()); + sal_Int32 const ret(m_FieldMarkMap.size()); + m_FieldMarkMap.insert(::std::make_pair(i_xFieldMark, ret)); + return ret; + } + sal_Int32 GetFieldMarkIndex(Reference<XFormField> const& i_xFieldMark) + { + FieldMarkMap_t::const_iterator const it( + m_FieldMarkMap.find(i_xFieldMark)); + // rely on SwXFieldmark::CreateXFieldmark returning the same instance + // because the Reference in m_FieldMarkMap will keep it alive + assert(it != m_FieldMarkMap.end()); + return it->second; + } +}; + XMLTextParagraphExport::XMLTextParagraphExport( SvXMLExport& rExp, SvXMLAutoStylePoolP & rASP ) : XMLStyleExport( rExp, OUString(), &rASP ), + m_pImpl(new Impl), rAutoStylePool( rASP ), pBoundFrameSets(new BoundFrameSets(GetExport().GetModel())), pFieldExport( 0 ), @@ -2178,7 +2203,8 @@ void XMLTextParagraphExport::exportTextRangeEnumeration( sal_Bool bAutoStyles, sal_Bool bIsProgress, sal_Bool bPrvChrIsSpc ) { - static OUString sMeta("InContentMetadata"); + static const OUString sMeta("InContentMetadata"); + static const OUString sFieldMarkName("__FieldMark_"); bool bPrevCharIsSpace = bPrvChrIsSpc; bool bAnnotationStarted = false; @@ -2304,16 +2330,22 @@ void XMLTextParagraphExport::exportTextRangeEnumeration( { if (xFormField.is()) { + OUString sName; Reference< ::com::sun::star::container::XNameAccess > xParameters(xFormField->getParameters(), UNO_QUERY); if (xParameters.is() && xParameters->hasByName("Name")) { const Any aValue = xParameters->getByName("Name"); OUString sValue; - if (aValue >>= sValue) - { - GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_NAME, sValue); - } + aValue >>= sName; + } + if (sName.isEmpty()) + { // name attribute is mandatory, so have to pull a + // rabbit out of the hat here + sName = sFieldMarkName + OUString::valueOf( + m_pImpl->AddFieldMarkStart(xFormField)); } + GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_NAME, + sName); SvXMLElementExport aElem( GetExport(), !bAutoStyles, XML_NAMESPACE_TEXT, XML_BOOKMARK_START, sal_False, sal_False ); @@ -2358,20 +2390,25 @@ void XMLTextParagraphExport::exportTextRangeEnumeration( Reference< ::com::sun::star::text::XFormField > xFormField(xPropSet->getPropertyValue(sBookmark), UNO_QUERY); if (xFormField.is()) { + OUString sName; Reference< ::com::sun::star::container::XNameAccess > xParameters(xFormField->getParameters(), UNO_QUERY); if (xParameters.is() && xParameters->hasByName("Name")) { const Any aValue = xParameters->getByName("Name"); - OUString sValue; - if (aValue >>= sValue) - { - GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_NAME, sValue); - } + aValue >>= sName; } + if (sName.isEmpty()) + { // name attribute is mandatory, so have to pull a + // rabbit out of the hat here + sName = sFieldMarkName + OUString::valueOf( + m_pImpl->GetFieldMarkIndex(xFormField)); + } + GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_NAME, + sName); + SvXMLElementExport aElem( GetExport(), !bAutoStyles, + XML_NAMESPACE_TEXT, XML_BOOKMARK_END, + sal_False, sal_False ); } - SvXMLElementExport aElem( GetExport(), !bAutoStyles, - XML_NAMESPACE_TEXT, XML_BOOKMARK_END, - sal_False, sal_False ); } } else if (sType.equals(sTextFieldStartEnd)) @@ -2401,10 +2438,10 @@ void XMLTextParagraphExport::exportTextRangeEnumeration( if (xBookmark.is()) { GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_NAME, xBookmark->getName()); + SvXMLElementExport aElem( GetExport(), !bAutoStyles, + XML_NAMESPACE_TEXT, XML_BOOKMARK, + sal_False, sal_False ); } - SvXMLElementExport aElem( GetExport(), !bAutoStyles, - XML_NAMESPACE_TEXT, XML_BOOKMARK, - sal_False, sal_False ); } } else if (sType.equals(sSoftPageBreak)) |