[Libreoffice-commits] .: Branch 'libreoffice-3-6' - xmloff/inc xmloff/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Mon Sep 17 00:52:33 PDT 2012


 xmloff/inc/xmloff/txtparae.hxx  |    3 +
 xmloff/source/text/txtparae.cxx |   69 ++++++++++++++++++++++++++++++----------
 2 files changed, 56 insertions(+), 16 deletions(-)

New commits:
commit ec272a7608ba006573540b4bb8812c01a930d09e
Author: Michael Stahl <mstahl at redhat.com>
Date:   Thu Sep 13 11:15:13 2012 +0200

    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
    (cherry picked from commit 22b615a7a54e6424bf3a492d2a07573ad9090949)
    Reviewed-on: https://gerrit.libreoffice.org/612
    Reviewed-by: Miklos Vajna <vmiklos at suse.cz>
    Tested-by: Miklos Vajna <vmiklos at suse.cz>

diff --git a/xmloff/inc/xmloff/txtparae.hxx b/xmloff/inc/xmloff/txtparae.hxx
index c5d3e75..284e88f 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 04b008c..01ad5dc 100644
--- a/xmloff/source/text/txtparae.cxx
+++ b/xmloff/source/text/txtparae.cxx
@@ -1153,11 +1153,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 ),
@@ -2179,7 +2204,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;
 
     /* This is  used for exporting to strict OpenDocument 1.2, in which case traditional
@@ -2291,16 +2317,22 @@ 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->AddFieldMarkStart(xFormField));
                         }
+                        GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_NAME,
+                                sName);
                         SvXMLElementExport aElem( GetExport(), !bAutoStyles,
                             XML_NAMESPACE_TEXT, XML_BOOKMARK_START,
                             sal_False, sal_False );
@@ -2333,20 +2365,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))
@@ -2376,10 +2413,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))


More information about the Libreoffice-commits mailing list