This is an automated email from the ASF dual-hosted git repository.
ardovm pushed a commit to branch AOO42X
in repository https://gitbox.apache.org/repos/asf/openoffice.git
The following commit(s) were added to refs/heads/AOO42X by this push:
new 9f951c0d55 Merge pull request #122 from ardovm/bug128356
9f951c0d55 is described below
commit 9f951c0d55f17771f1f6011ea938b721eee333ff
Author: Jim Jagielski <[email protected]>
AuthorDate: Fri Oct 1 07:38:30 2021 -0400
Merge pull request #122 from ardovm/bug128356
Address bug 128356 and similar ones (duplicated XML attributes)
(cherry picked from commit 59d6557e284ffa3dc5c77d3b9525211aac79a543,
with minor adaptations)
---
main/xmloff/inc/xmloff/attrlist.hxx | 114 +++++++++++++++++++++++++++++++++--
main/xmloff/inc/xmloff/xmlexp.hxx | 20 ++++--
main/xmloff/source/core/attrlist.cxx | 18 ++++--
main/xmloff/source/core/xmlexp.cxx | 10 +--
main/xmloff/source/text/txtparae.cxx | 16 ++---
5 files changed, 152 insertions(+), 26 deletions(-)
diff --git a/main/xmloff/inc/xmloff/attrlist.hxx
b/main/xmloff/inc/xmloff/attrlist.hxx
index 9953b6ba32..6bbeed112f 100644
--- a/main/xmloff/inc/xmloff/attrlist.hxx
+++ b/main/xmloff/inc/xmloff/attrlist.hxx
@@ -37,8 +37,13 @@
#include <cppuhelper/implbase3.hxx>
+/** Implementation of the XML attribute list.
+ *
+ * It is based on std::vector.
+ */
struct SvXMLAttributeList_Impl;
+/** Container for XML tag attributes. */
class XMLOFF_DLLPUBLIC SvXMLAttributeList : public ::cppu::WeakImplHelper3<
::com::sun::star::xml::sax::XAttributeList,
::com::sun::star::util::XCloneable,
@@ -59,30 +64,129 @@ public:
// XUnoTunnel
virtual sal_Int64 SAL_CALL getSomething( const
::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier )
throw(::com::sun::star::uno::RuntimeException);
- // ::com::sun::star::xml::sax::XAttributeList
+ /** Return the number of attributes.
+ *
+ * Required by ::com::sun::star::xml::sax::XAttributeList
+ */
virtual sal_Int16 SAL_CALL getLength(void) throw(
::com::sun::star::uno::RuntimeException );
+ /** Return the name of the i-th attribute.
+ *
+ * @param i index starting from zero.
+ *
+ * @return the name of the i-th attribute, or empty string if i is
+ * not a valid index.
+ */
virtual ::rtl::OUString SAL_CALL getNameByIndex(sal_Int16 i) throw(
::com::sun::star::uno::RuntimeException );
+ /** Returns the type of the i-th attribute.
+ *
+ * @param i index starting from zero.
+ *
+ * @return CDATA for any value of i.
+ */
virtual ::rtl::OUString SAL_CALL getTypeByIndex(sal_Int16 i) throw(
::com::sun::star::uno::RuntimeException );
+ /** Returns the type of an attribute.
+ *
+ * @param aName name of the attribute to look for.
+ *
+ * @return CDATA for any value of aName.
+ */
virtual ::rtl::OUString SAL_CALL getTypeByName(const ::rtl::OUString&
aName) throw( ::com::sun::star::uno::RuntimeException );
+ /** Return the value of the i-th attribute.
+ *
+ * @param i index starting from zero.
+ *
+ * @return the value of the i-th attribute, or empty string if i is
+ * not a valid index.
+ */
virtual ::rtl::OUString SAL_CALL getValueByIndex(sal_Int16 i) throw(
::com::sun::star::uno::RuntimeException );
+ /** Return the value of an attribute.
+ *
+ * @param aName name of the attribute to look for.
+ *
+ * @return the value of the attribute named aName, or empty string
+ * if no attributes are named aName.
+ */
virtual ::rtl::OUString SAL_CALL getValueByName(const ::rtl::OUString&
aName) throw( ::com::sun::star::uno::RuntimeException );
- // ::com::sun::star::util::XCloneable
+ /** Make a clone of this object.
+ *
+ * Required by ::com::sun::star::util::XCloneable
+ *
+ * @return a clone of the current object.
+ */
virtual ::com::sun::star::uno::Reference<
::com::sun::star::util::XCloneable > SAL_CALL createClone() throw(
::com::sun::star::uno::RuntimeException );
// methods that are not contained in any interface
+
+ /** Add an attribute.
+ *
+ * @param sName name of the attribute.
+ * @param sValue value of the attribute.
+ *
+ * @exception com::sun::star::uno::RuntimeException thrown if the
+ * attribute already exists.
+ */
void AddAttribute( const ::rtl::OUString &sName , const ::rtl::OUString
&sValue );
+ /** Clear the attributes list. */
void Clear();
+ /** Remove an attribute from the list.
+ *
+ * @param sName name of the attribute to remove.
+ *
+ * If no attribute named sName is found, this method does not do anything.
+ */
void RemoveAttribute( const ::rtl::OUString sName );
- void SetAttributeList( const ::com::sun::star::uno::Reference<
::com::sun::star::xml::sax::XAttributeList > & );
- void AppendAttributeList( const ::com::sun::star::uno::Reference<
::com::sun::star::xml::sax::XAttributeList > & );
+ /** Reset the attributes list.
+ *
+ * @param r list to read the attributes from.
+ *
+ * The internal list is cleared and reset from r.
+ */
+ void SetAttributeList( const ::com::sun::star::uno::Reference<
::com::sun::star::xml::sax::XAttributeList > &r );
+ /** Add attributes.
+ *
+ * @param r attributes to add.
+ *
+ * @exception com::sun::star::uno::RuntimeException thrown if any
+ * of the attributes in r already exists. Previous attributes may
+ * have been added.
+ */
+ void AppendAttributeList( const ::com::sun::star::uno::Reference<
::com::sun::star::xml::sax::XAttributeList > &r );
+ /** Set the value of the i-th attribute.
+ *
+ * @param i index starting from zero.
+ * @param rValue value to set.
+ *
+ * If i is out of range, this method does nothing.
+ */
void SetValueByIndex( sal_Int16 i, const ::rtl::OUString& rValue );
+ /** Remove the i-th attribute.
+ *
+ * @param i index starting from zero.
+ *
+ * If i is out of range, this method does nothing.
+ */
void RemoveAttributeByIndex( sal_Int16 i );
+ /** Rename the i-th attribute.
+ *
+ * @param i index starting from zero.
+ * @param rNewName new name to set.
+ *
+ * If i is out of range, this method does nothing.
+ */
void RenameAttributeByIndex( sal_Int16 i, const ::rtl::OUString&
rNewName );
+ /** Find an attribute from its name.
+ *
+ * @param rName attribute name to look for.
+ *
+ * @return the index of attribute named rName (starting from
+ * zero), or -1 if no attributes were found.
+ */
sal_Int16 GetIndexByName( const ::rtl::OUString& rName ) const;
private:
- const ::rtl::OUString sType; // "CDATA"
+ /** "CDATA" string */
+ const ::rtl::OUString sType;
};
diff --git a/main/xmloff/inc/xmloff/xmlexp.hxx
b/main/xmloff/inc/xmloff/xmlexp.hxx
index 68e78828df..ac907b1e56 100644
--- a/main/xmloff/inc/xmloff/xmlexp.hxx
+++ b/main/xmloff/inc/xmloff/xmlexp.hxx
@@ -681,14 +681,27 @@ inline void SvXMLExport::SetGraphicResolver(
mxGraphicResolver = _xGraphicResolver;
}
-// Helper class to export an element.
+/** Helper class to export an element.
+ *
+ * The constructor prints a start tag that has the common attributes
+ * of the XMLExport instance attached. The destructor prints an end
+ * tag.
+ *
+ * Object of this class can be turned into a no-op by a parameter to
+ * the constructor.
+ */
class XMLOFF_DLLPUBLIC SvXMLElementExport
{
+ /** Object on which the element is emitted. */
SvXMLExport& mrExport;
+ /** Name of this element */
::rtl::OUString maElementName;
+ /** Parameter passed to the export object */
const sal_Bool mbIgnoreWhitespaceInside :1;
+ /** When false, this object is a no-op */
const sal_Bool mbDoSomething :1;
+ /** Start the XML element */
SAL_DLLPRIVATE
void StartElement(
const sal_uInt16 nPrefix,
@@ -696,9 +709,6 @@ class XMLOFF_DLLPUBLIC SvXMLElementExport
const sal_Bool bIgnoreWhitespaceOutside );
public:
-
- // The constructor prints a start tag that has the common attributes
- // of the XMLExport instance attached.
SvXMLElementExport( SvXMLExport& rExp, sal_uInt16 nPrefix,
const sal_Char *pName,
sal_Bool bIgnWSOutside, sal_Bool
bIgnWSInside );
@@ -723,7 +733,7 @@ public:
enum ::xmloff::token::XMLTokenEnum eName,
sal_Bool bIgnWSOutside, sal_Bool
bIgnWSInside );
- // The destructor prints an end tag.
+ /** Prints an end tag. */
~SvXMLElementExport();
};
diff --git a/main/xmloff/source/core/attrlist.cxx
b/main/xmloff/source/core/attrlist.cxx
index 7dacb98bb8..c4c4f58a77 100644
--- a/main/xmloff/source/core/attrlist.cxx
+++ b/main/xmloff/source/core/attrlist.cxx
@@ -162,7 +162,11 @@ SvXMLAttributeList::~SvXMLAttributeList()
void SvXMLAttributeList::AddAttribute( const OUString &sName ,
const OUString &sValue )
{
- m_pImpl->vecAttribute.push_back( SvXMLTagAttribute_Impl( sName , sValue
) );
+ if (GetIndexByName(sName) == -1) {
+ m_pImpl->vecAttribute.push_back( SvXMLTagAttribute_Impl( sName
, sValue ) );
+ } else {
+ throw
com::sun::star::uno::RuntimeException(OUString(RTL_CONSTASCII_USTRINGPARAM("attempt
to insert duplicate XML tag attribute: ")) + sName, NULL);
+ }
}
void SvXMLAttributeList::Clear()
@@ -200,10 +204,16 @@ void SvXMLAttributeList::AppendAttributeList( const
uno::Reference< ::com::sun::
m_pImpl->vecAttribute.size() + nMax;
m_pImpl->vecAttribute.reserve( nTotalSize );
+ OUString sName;
for( sal_Int16 i = 0 ; i < nMax ; ++i ) {
- m_pImpl->vecAttribute.push_back( SvXMLTagAttribute_Impl(
- r->getNameByIndex( i ) ,
- r->getValueByIndex( i )));
+ sName = r->getNameByIndex(i);
+ if (GetIndexByName(sName) == -1) {
+ m_pImpl->vecAttribute.push_back( SvXMLTagAttribute_Impl(
+ sName,
+ r->getValueByIndex( i ) ) );
+ } else {
+ throw
com::sun::star::uno::RuntimeException(OUString(RTL_CONSTASCII_USTRINGPARAM("attempt
to insert duplicate XML tag attribute: ")) + sName, NULL);
+ }
}
OSL_ASSERT( nTotalSize ==
(SvXMLAttributeList_Impl::size_type)getLength());
diff --git a/main/xmloff/source/core/xmlexp.cxx
b/main/xmloff/source/core/xmlexp.cxx
index 35f11ec0f3..ae1df0b09c 100644
--- a/main/xmloff/source/core/xmlexp.cxx
+++ b/main/xmloff/source/core/xmlexp.cxx
@@ -1193,7 +1193,7 @@ void SvXMLExport::ImplExportStyles( sal_Bool )
// AddAttribute( XML_NAMESPACE_NONE, XML_ID, XML_STYLES_ID );
{
- // <style:styles>
+ // <office:styles>
SvXMLElementExport aElem( *this, XML_NAMESPACE_OFFICE,
XML_STYLES,
sal_True,
sal_True );
@@ -1237,7 +1237,7 @@ void SvXMLExport::ImplExportAutoStyles( sal_Bool )
// AddAttributeASCII( XML_NAMESPACE_NONE, XML_ID, XML_AUTO_STYLES_ID );
{
- // <style:automatic-styles>
+ // <office:automatic-styles>
SvXMLElementExport aElem( *this, XML_NAMESPACE_OFFICE,
XML_AUTOMATIC_STYLES, sal_True, sal_True );
@@ -1249,7 +1249,7 @@ void SvXMLExport::ImplExportAutoStyles( sal_Bool )
pNamespaceMap->GetQNameByKey(
XML_NAMESPACE_OFFICE,
GetXMLToken(XML_STYLESHEET)) );
{
- // <style:use-styles>
+ // <office:use-styles>
SvXMLElementExport aElem( *this, XML_NAMESPACE_OFFICE,
XML_USE_STYLES, sal_True, sal_True );
}
@@ -1261,7 +1261,7 @@ void SvXMLExport::ImplExportAutoStyles( sal_Bool )
void SvXMLExport::ImplExportMasterStyles( sal_Bool )
{
{
- // <style:master-styles>
+ // <office:master-styles>
SvXMLElementExport aElem( *this, XML_NAMESPACE_OFFICE,
XML_MASTER_STYLES,
sal_True,
sal_True );
@@ -1276,7 +1276,7 @@ void SvXMLExport::ImplExportMasterStyles( sal_Bool )
pNamespaceMap->GetQNameByKey(
XML_NAMESPACE_OFFICE,
GetXMLToken(XML_STYLESHEET) )
);
{
- // <style:use-styles>
+ // <office:use-styles>
SvXMLElementExport aElem( *this, XML_NAMESPACE_OFFICE,
XML_USE_STYLES, sal_True, sal_True );
}
diff --git a/main/xmloff/source/text/txtparae.cxx
b/main/xmloff/source/text/txtparae.cxx
index 46668e577e..3c591a78d5 100644
--- a/main/xmloff/source/text/txtparae.cxx
+++ b/main/xmloff/source/text/txtparae.cxx
@@ -2255,13 +2255,15 @@ void XMLTextParagraphExport::exportTextRangeEnumeration(
}
else if ( sType.equals( sAnnotationEnd ) )
{
- Reference<XNamed>
xBookmark(xPropSet->getPropertyValue(sBookmark), UNO_QUERY);
- const OUString& rName = xBookmark->getName();
- if ( rName.getLength() > 0 )
- {
- GetExport().AddAttribute(XML_NAMESPACE_OFFICE, XML_NAME,
rName);
- }
- SvXMLElementExport aElem( GetExport(), !bAutoStyles,
XML_NAMESPACE_OFFICE, XML_ANNOTATION_END, sal_False, sal_False );
+ if (!bAutoStyles) {
+ Reference<XNamed>
xBookmark(xPropSet->getPropertyValue(sBookmark), UNO_QUERY);
+ const OUString& rName = xBookmark->getName();
+ if ( rName.getLength() > 0 )
+ {
+ GetExport().AddAttribute(XML_NAMESPACE_OFFICE,
XML_NAME, rName);
+ }
+ SvXMLElementExport aElem( GetExport(), true,
XML_NAMESPACE_OFFICE, XML_ANNOTATION_END, sal_False, sal_False );
+ } // else: there is nothing to do for automatic styles here
}
else if( sType.equals( sFrame ) )
{