summaryrefslogtreecommitdiff
path: root/xmloff/source/text/XMLTextMarkImportContext.cxx
diff options
context:
space:
mode:
authorMichael Stahl <mstahl@redhat.com>2016-01-08 16:02:43 +0100
committerMichael Stahl <mstahl@redhat.com>2016-01-08 20:31:47 +0100
commit774fb6d2e7cf36b677e66c54278225b1256bd40f (patch)
treea5bad6d37736b5f37656f87874e975e88cdc2ea2 /xmloff/source/text/XMLTextMarkImportContext.cxx
parent79bbc5b910259c2c0efc71329501767e97513584 (diff)
tdf#96480: ODF import: eliminate duplicate cross reference heading bookmarks
7c3c3006deaaaf1bb3f2f4eeeaf11da3bcebe53c is apparently worse than it appeared at first glance since there are numerous assumptions about bookmarks, such as that if they were inserted successfully they may be copied successfully, which isn't the case for duplicate cross reference bookmarks. So fix this differently, by eliminating the duplicates and mapping all reference fields to refer to the surviving bookmark. It was not possible to do this in SwXBookmark by checking the makeMark() return as that would raise interesting problems such as it's currently guaranteed to have 1:1 SwXBoomarks to core Marks so we can't just connect 2 SwXBookmarks to the same core Mark, and we also can't leave the SwXBookmark unconnected after attach. Another alternative would be to temporarily allow inserting the duplicate bookmarks and then eliminate them after the import, but what is implemented now is to check from xmloff for duplicates, which is reasonably simple. Change-Id: I7ee4854d1c9d8bf74201089cbb7287b1bd8ee3b9
Diffstat (limited to 'xmloff/source/text/XMLTextMarkImportContext.cxx')
-rw-r--r--xmloff/source/text/XMLTextMarkImportContext.cxx46
1 files changed, 44 insertions, 2 deletions
diff --git a/xmloff/source/text/XMLTextMarkImportContext.cxx b/xmloff/source/text/XMLTextMarkImportContext.cxx
index 2ebef98d77d6..a670fdc81390 100644
--- a/xmloff/source/text/XMLTextMarkImportContext.cxx
+++ b/xmloff/source/text/XMLTextMarkImportContext.cxx
@@ -99,10 +99,12 @@ void XMLFieldParamImportContext::StartElement(const css::uno::Reference< css::xm
XMLTextMarkImportContext::XMLTextMarkImportContext(
SvXMLImport& rImport,
XMLTextImportHelper& rHlp,
+ uno::Reference<uno::XInterface> & io_rxCrossRefHeadingBookmark,
sal_uInt16 nPrefix,
const OUString& rLocalName )
: SvXMLImportContext(rImport, nPrefix, rLocalName)
, m_rHelper(rHlp)
+ , m_rxCrossRefHeadingBookmark(io_rxCrossRefHeadingBookmark)
, m_bHaveAbout(false)
{
}
@@ -202,9 +204,23 @@ void XMLTextMarkImportContext::EndElement()
OUString());
break;
- case TypeFieldmark:
case TypeBookmark:
{
+ // tdf#94804: detect duplicate heading cross reference bookmarks
+ if (m_sBookmarkName.startsWith("__RefHeading__"))
+ {
+ if (m_rxCrossRefHeadingBookmark.is())
+ {
+ uno::Reference<container::XNamed> const xNamed(
+ m_rxCrossRefHeadingBookmark, uno::UNO_QUERY);
+ m_rHelper.AddCrossRefHeadingMapping(
+ m_sBookmarkName, xNamed->getName());
+ break; // don't insert
+ }
+ }
+ } // fall through
+ case TypeFieldmark:
+ {
const char *formFieldmarkName=lcl_getFormFieldmarkName(m_sFieldName);
bool bImportAsField=((lcl_MarkType)nTmp==TypeFieldmark && formFieldmarkName!=nullptr); //@TODO handle abbreviation cases..
// export point bookmark
@@ -225,6 +241,12 @@ void XMLTextMarkImportContext::EndElement()
}
m_rHelper.popFieldCtx();
}
+ if (TypeBookmark == nTmp
+ && m_sBookmarkName.startsWith("__RefHeading__"))
+ {
+ assert(xContent.is());
+ m_rxCrossRefHeadingBookmark = xContent;
+ }
}
break;
@@ -249,8 +271,22 @@ void XMLTextMarkImportContext::EndElement()
}
break;
- case TypeFieldmarkEnd:
case TypeBookmarkEnd:
+ {
+ // tdf#94804: detect duplicate heading cross reference bookmarks
+ if (m_sBookmarkName.startsWith("__RefHeading__"))
+ {
+ if (m_rxCrossRefHeadingBookmark.is())
+ {
+ uno::Reference<container::XNamed> const xNamed(
+ m_rxCrossRefHeadingBookmark, uno::UNO_QUERY);
+ m_rHelper.AddCrossRefHeadingMapping(
+ m_sBookmarkName, xNamed->getName());
+ break; // don't insert
+ }
+ }
+ } // fall through
+ case TypeFieldmarkEnd:
{
// get old range, and construct
Reference<XTextRange> xStartRange;
@@ -333,6 +369,12 @@ void XMLTextMarkImportContext::EndElement()
}
m_rHelper.popFieldCtx();
}
+ if (TypeBookmarkEnd == nTmp
+ && m_sBookmarkName.startsWith("__RefHeading__"))
+ {
+ assert(xContent.is());
+ m_rxCrossRefHeadingBookmark = xContent;
+ }
}
// else: beginning/end in different XText -> ignore!
}